-
Notifications
You must be signed in to change notification settings - Fork 315
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
base: master
Are you sure you want to change the base?
Changes from all commits
4e2e2ec
b51b72d
9fc3233
2184de4
49336d5
721fa8f
43655c8
b4536f8
df2991d
a1870c5
53540de
04fbceb
984c478
a8484df
07d2c1d
ab6899c
4dc875d
4334f8a
600d10b
7323aa0
2ed6e46
f660c74
d5dddea
0f07c8c
86abf42
ed725e5
33db941
1708dda
d0a464b
b096afc
2ec2db9
788bbc3
d60693c
aee6323
d195771
4e14f22
6c668e5
d4918d0
2f998c4
75e5e35
3fd928c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -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; | ||
|
@@ -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( | ||
|
@@ -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); | ||
|
@@ -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( | ||
|
@@ -184,6 +212,8 @@ public void onFacingChange() { | |
|
||
@Override | ||
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { | ||
this.lastClickedPlayer = aPlayer; | ||
|
||
GTUIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); | ||
return true; | ||
} | ||
|
@@ -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(); | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'll look at what i can do, thx There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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; | ||
|
@@ -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() | ||
|
@@ -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; | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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