Skip to content

Commit

Permalink
Merge remote-tracking branch 'Diamantino-Op/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master committed Jan 20, 2025
2 parents 2cf015b + 43655c8 commit e301e23
Show file tree
Hide file tree
Showing 4 changed files with 271 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2315,7 +2315,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 @@ -2333,6 +2333,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 @@ -2370,7 +2378,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;
}

if (((MTEHatchOutputBusME) tHatch).canAcceptItem()) {
return true;
}
}
Expand All @@ -2382,7 +2394,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,8 @@ public class MTEHatchOutputBusME extends MTEHatchOutputBus implements IPowerChan
long lastInputTick = 0;
long tickCounter = 0;
boolean additionalConnection = false;
EntityPlayer lastClickedPlayer = null;
List<ItemStack> lockedItems = new ArrayList<>();

public MTEHatchOutputBusME(int aID, String aName, String aNameRegional) {
super(
Expand All @@ -82,14 +87,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",
"To set output item filter, place an ME Disk that has the items in its filter settings into the slot" },
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 +157,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 +210,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 +297,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 +308,69 @@ 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 (upgradeItemStack != null && upgradeItemStack.getItem() instanceof ItemBasicStorageCell) {
if (this.lockedItems.isEmpty()) {
CellConfig cfg = (CellConfig) ((ItemBasicStorageCell) upgradeItemStack.getItem())
.getConfigInventory(upgradeItemStack);

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 {
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 +389,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 @@ -316,6 +417,15 @@ public void saveNBTData(NBTTagCompound aNBT) {
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
Loading

0 comments on commit e301e23

Please sign in to comment.