Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to filter outputs to ME Output Bus and Hatch #3828

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4e2e2ec
Added the ability to filter outputs to ME Output Bus and Hatch
Diamantino-Op Jan 19, 2025
b51b72d
Merge branch 'master' into master
Diamantino-Op Jan 19, 2025
9fc3233
Ran spotlessApply
Diamantino-Op Jan 19, 2025
2184de4
Merge remote-tracking branch 'origin/master'
Diamantino-Op Jan 19, 2025
49336d5
Merge branch 'master' into master
Dream-Master Jan 20, 2025
721fa8f
Fix ME Output Bus and translations
Diamantino-Op Jan 20, 2025
43655c8
Merge remote-tracking branch 'origin/master'
Diamantino-Op Jan 20, 2025
b4536f8
Merge branch 'master' into master
Diamantino-Op Jan 21, 2025
df2991d
Merge branch 'master' into master
Dream-Master Jan 21, 2025
a1870c5
Update src/main/java/gregtech/common/tileentities/machines/MTEHatchOu…
Diamantino-Op Jan 21, 2025
53540de
Update src/main/java/gregtech/common/tileentities/machines/MTEHatchOu…
Diamantino-Op Jan 21, 2025
04fbceb
Update src/main/resources/assets/gregtech/lang/en_US.lang
Diamantino-Op Jan 21, 2025
984c478
Merge branch 'master' into master
Diamantino-Op Jan 22, 2025
a8484df
Merge branch 'master' into master
Dream-Master Jan 22, 2025
07d2c1d
Merge branch 'master' into master
Diamantino-Op Jan 22, 2025
ab6899c
Merge branch 'master' into master
Diamantino-Op Jan 23, 2025
4dc875d
Merge branch 'master' into master
Dream-Master Jan 23, 2025
4334f8a
Merge branch 'master' into master
Diamantino-Op Jan 25, 2025
600d10b
Merge branch 'master' into master
Dream-Master Jan 25, 2025
7323aa0
Merge branch 'master' into master
Dream-Master Jan 25, 2025
2ed6e46
Merge branch 'master' into master
Dream-Master Jan 26, 2025
f660c74
Merge branch 'master' into master
Dream-Master Jan 27, 2025
d5dddea
Merge branch 'master' into master
Dream-Master Jan 30, 2025
0f07c8c
Merge branch 'master' into master
Dream-Master Jan 30, 2025
86abf42
Merge branch 'master' into master
Dream-Master Jan 31, 2025
ed725e5
Merge branch 'master' into master
Dream-Master Jan 31, 2025
33db941
Merge branch 'master' into master
Dream-Master Feb 3, 2025
1708dda
Merge branch 'master' into master
Dream-Master Feb 5, 2025
d0a464b
Merge branch 'master' into master
Dream-Master Feb 7, 2025
b096afc
Merge branch 'master' into master
Dream-Master Feb 8, 2025
2ec2db9
Optimize ME Output bus
Diamantino-Op Feb 9, 2025
788bbc3
Merge branch 'master' of https://github.com/Diamantino-Op/GT5-Unofficial
Diamantino-Op Feb 9, 2025
d60693c
Optimize ME Output Hatch
Diamantino-Op Feb 9, 2025
aee6323
Merge branch 'master' into master
Diamantino-Op Feb 9, 2025
d195771
Merge branch 'master' into master
Dream-Master Feb 10, 2025
4e14f22
Merge branch 'master' into master
Dream-Master Feb 11, 2025
6c668e5
Merge branch 'master' into master
Dream-Master Feb 11, 2025
d4918d0
Merge branch 'master' into master
Dream-Master Feb 12, 2025
2f998c4
Merge branch 'master' into master
Dream-Master Feb 13, 2025
75e5e35
Merge branch 'master' into master
Dream-Master Feb 14, 2025
3fd928c
Merge branch 'master' into master
Dream-Master Feb 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2389,7 +2389,7 @@ public void setVoidingMode(VoidingMode mode) {
public List<ItemStack> getItemOutputSlots(ItemStack[] toOutput) {
List<ItemStack> ret = new ArrayList<>();
for (final MTEHatch tBus : validMTEList(mOutputBusses)) {
if (!(tBus instanceof MTEHatchOutputBusME)) {
if (!(tBus instanceof MTEHatchOutputBusME meBus)) {
final IInventory tBusInv = tBus.getBaseMetaTileEntity();
for (int i = 0; i < tBusInv.getSizeInventory(); i++) {
final ItemStack stackInSlot = tBus.getStackInSlot(i);
Expand All @@ -2407,6 +2407,14 @@ public List<ItemStack> getItemOutputSlots(ItemStack[] toOutput) {
ret.add(stackInSlot);
}
}
} else {
if (meBus.isLocked()) {
for (ItemStack stack : meBus.getLockedItems()) {
ItemStack fakeItemStack = stack.copy();
fakeItemStack.stackSize = 0;
ret.add(fakeItemStack);
}
}
}
}
return ret;
Expand Down Expand Up @@ -2444,7 +2452,11 @@ protected <T extends MTEHatchOutput> List<? extends IFluidStore> getFluidOutputS
public boolean canDumpItemToME() {
for (MTEHatch tHatch : validMTEList(mOutputBusses)) {
if (tHatch instanceof MTEHatchOutputBusME) {
if ((((MTEHatchOutputBusME) tHatch).canAcceptItem())) {
if (((MTEHatchOutputBusME) tHatch).isLocked()) {
return false;
}
Comment on lines +2455 to +2457
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will require voiding mode to be extensively tested, as this function greatly changes void protection calculation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tested with multi hatch, but did not test what happens when it overflows or try to craft when the hatch is full


if (((MTEHatchOutputBusME) tHatch).canAcceptItem()) {
return true;
}
}
Expand All @@ -2456,7 +2468,11 @@ public boolean canDumpItemToME() {
public boolean canDumpFluidToME() {
for (IFluidStore tHatch : getFluidOutputSlots(new FluidStack[0])) {
if (tHatch instanceof MTEHatchOutputME) {
if ((((MTEHatchOutputME) tHatch).canAcceptFluid())) {
if (((MTEHatchOutputME) tHatch).isFluidLocked()) {
return false;
}

if (((MTEHatchOutputME) tHatch).canAcceptFluid()) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

import com.gtnewhorizons.modularui.api.forge.ItemHandlerHelper;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;

Expand All @@ -37,6 +39,7 @@
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AECableType;
import appeng.items.contents.CellConfig;
import appeng.items.storage.ItemBasicStorageCell;
import appeng.me.GridAccessException;
import appeng.me.helpers.AENetworkProxy;
Expand Down Expand Up @@ -73,6 +76,10 @@ public class MTEHatchOutputBusME extends MTEHatchOutputBus implements IPowerChan
long lastInputTick = 0;
long tickCounter = 0;
boolean additionalConnection = false;
EntityPlayer lastClickedPlayer = null;
List<ItemStack> lockedItems = new ArrayList<>();

boolean hadCell = false;

public MTEHatchOutputBusME(int aID, String aName, String aNameRegional) {
super(
Expand All @@ -82,14 +89,19 @@ public MTEHatchOutputBusME(int aID, String aName, String aNameRegional) {
3,
new String[] { "Item Output for Multiblocks", "Stores directly into ME", "Can cache 1600 items by default",
"Change cache size by inserting a storage cell",
"Change ME connection behavior by right-clicking with wire cutter" },
"Change ME connection behavior by right-clicking with wire cutter",
"Partition the inserted Storage Cell to filter accepted outputs" },
1);
}

public MTEHatchOutputBusME(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) {
super(aName, aTier, 1, aDescription, aTextures);
}

public List<ItemStack> getLockedItems() {
return lockedItems;
}

@Override
public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
return new MTEHatchOutputBusME(mName, mTier, mDescriptionArray, mTextures);
Expand Down Expand Up @@ -147,6 +159,22 @@ public boolean canAcceptItem() {
* @return amount of items left over
*/
public int store(final ItemStack stack) {
if (!lockedItems.isEmpty()) {
boolean isOk = false;

for (ItemStack lockedItem : lockedItems) {
if (lockedItem.isItemEqual(stack)) {
isOk = true;

break;
}
}

if (!isOk) {
return stack.stackSize;
}
}

// Always allow insertion on the same tick so we can output the entire recipe
if (canAcceptItem() || (lastInputTick == tickCounter)) {
itemCache.add(
Expand Down Expand Up @@ -184,6 +212,8 @@ public void onFacingChange() {

@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
this.lastClickedPlayer = aPlayer;

GTUIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer);
return true;
}
Expand Down Expand Up @@ -269,6 +299,8 @@ public boolean isActive() {

@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
checkItemLock();

if (getBaseMetaTileEntity().isServerSide()) {
tickCounter = aTick;
if (tickCounter > (lastOutputTick + 40)) flushCachedStack();
Expand All @@ -278,8 +310,77 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
}

@Override
public void addAdditionalTooltipInformation(ItemStack stack, List<String> tooltip) {
public boolean isLocked() {
return !this.lockedItems.isEmpty();
}

private void checkItemLock() {
ItemStack upgradeItemStack = mInventory[0];

if ((hadCell && upgradeItemStack != null) || (!hadCell && upgradeItemStack == null)) {
return;
}

if (upgradeItemStack != null && upgradeItemStack.getItem() instanceof ItemBasicStorageCell) {
hadCell = true;

if (this.lockedItems.isEmpty()) {
CellConfig cfg = (CellConfig) ((ItemBasicStorageCell) upgradeItemStack.getItem())
.getConfigInventory(upgradeItemStack);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed that this method is showing up on my server's profiles more than I'd expect. It's nothing major, but if you have time could you optimize this a bit? I doubt it needs to be called constantly. I'm guessing it's because I have a lot of cells with no partition, causing this code to always run for those busses. I only have a few hundred me output busses in my world, so I imagine late game worlds would be hit quite a bit harder.

https://spark.lucko.me/ID2eUmeIF4
image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll look at what i can do, thx

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok @RecursivePineapple i think i optimized it a bit now, can you check pls?


if (!cfg.isEmpty()) {
StringBuilder builder = new StringBuilder();

boolean hadFilters = false;
boolean isFirst = true;

for (int i = 0; i < cfg.getSizeInventory(); i++) {
ItemStack stack = cfg.getStackInSlot(i);

if (stack != null) {
hadFilters = true;

lockedItems.add(ItemHandlerHelper.copyStackWithSize(stack, 1));

if (isFirst) {
builder.append(stack.getDisplayName());

isFirst = false;
} else {
builder.append(", ")
.append(stack.getDisplayName());
}
}
}

if (hadFilters) {
if (lastClickedPlayer != null) {
GTUtility.sendChatToPlayer(
lastClickedPlayer,
StatCollector.translateToLocalFormatted("GT5U.hatch.item.filter.enable", builder));
}

markDirty();
}
}
}
} else {
hadCell = false;

if (!this.lockedItems.isEmpty()) {
this.lockedItems.clear();

markDirty();

GTUtility.sendChatToPlayer(
lastClickedPlayer,
StatCollector.translateToLocal("GT5U.hatch.item.filter.disable"));
}
}
}

@Override
public void addAdditionalTooltipInformation(ItemStack stack, List<String> tooltip) {
if (stack.hasTagCompound() && stack.stackTagCompound.hasKey("baseCapacity")) {
tooltip.add(
"Current cache capacity: " + EnumChatFormatting.YELLOW
Expand All @@ -298,6 +399,16 @@ public void setItemNBT(NBTTagCompound aNBT) {
public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);

NBTTagList lockedItemsTag = new NBTTagList();

for (ItemStack stack : this.lockedItems) {
NBTTagCompound stackTag = new NBTTagCompound();
stack.writeToNBT(stackTag);
lockedItemsTag.appendTag(stackTag);
}

aNBT.setTag("lockedItems", lockedItemsTag);

NBTTagList items = new NBTTagList();
for (IAEItemStack s : itemCache) {
if (s.getStackSize() == 0) continue;
Expand All @@ -309,13 +420,23 @@ public void saveNBTData(NBTTagCompound aNBT) {
aNBT.setBoolean("additionalConnection", additionalConnection);
aNBT.setTag("cachedItems", items);
aNBT.setLong("baseCapacity", baseCapacity);
aNBT.setBoolean("hadCell", hadCell);
getProxy().writeToNBT(aNBT);
}

@Override
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);

NBTBase lockedItemsTag = aNBT.getTag("lockedItems");

if (lockedItemsTag instanceof NBTTagList lockedItemsList) {
for (int i = 0; i < lockedItemsList.tagCount(); i++) {
NBTTagCompound stackTag = lockedItemsList.getCompoundTagAt(i);
this.lockedItems.add(GTUtility.loadItem(stackTag));
}
}

NBTBase t = aNBT.getTag("cachedStack"); // legacy
if (t instanceof NBTTagCompound) itemCache.add(
AEApi.instance()
Expand Down Expand Up @@ -348,6 +469,7 @@ public void loadNBTData(NBTTagCompound aNBT) {
}
additionalConnection = aNBT.getBoolean("additionalConnection");
baseCapacity = aNBT.getLong("baseCapacity");
hadCell = aNBT.getBoolean("hadCell");
// Set the base capacity of existing hatches to be infinite
if (baseCapacity == 0) {
baseCapacity = Long.MAX_VALUE;
Expand Down
Loading