From 47583fe3cf215fc8c49a6dc2377ad27ad822e67d Mon Sep 17 00:00:00 2001 From: reobf <2215595288@qq.com> Date: Tue, 7 May 2024 15:39:59 +0800 Subject: [PATCH] drop items in buffers when Buffered Hatch is destroyed --- .../BufferedDualInputHatch.java | 37 ++++++++++++++++++- .../metatileentity/PatternDualInputHatch.java | 10 ++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java index 2bd5432..1e90ea7 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java @@ -1,7 +1,7 @@ package reobf.proghatches.gt.metatileentity; import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; - +import static gregtech.api.objects.XSTR.XSTR_INSTANCE; import java.io.IOException; import java.lang.invoke.MethodHandle; @@ -24,6 +24,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Slot; @@ -93,6 +94,7 @@ import gregtech.api.util.extensions.ArrayExt; import gregtech.common.tileentities.machines.IDualInputInventory; import gregtech.common.tileentities.machines.IRecipeProcessingAwareHatch; +import gregtech.common.tileentities.storage.GT_MetaTileEntity_QuantumChest; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; import reobf.proghatches.item.ItemProgrammingCircuit; @@ -1440,4 +1442,37 @@ public CheckRecipeResult endRecipeProcessing(GT_MetaTileEntity_MultiBlockBase co dirty=true; return super.endRecipeProcessing(controller); } +@Override +public void onBlockDestroyed() { + IGregTechTileEntity te = this.getBaseMetaTileEntity(); + World aWorld=te.getWorld(); + int aX = te.getXCoord(); + short aY = te.getYCoord(); + int aZ = te.getZCoord(); + for (DualInvBuffer inv:this.inv0) + for (int i = 0; i < inv.mStoredItemInternal.length; i++) { + final ItemStack tItem =inv.mStoredItemInternal[i]; + if ((tItem != null) && (tItem.stackSize > 0)) { + final EntityItem tItemEntity = new EntityItem( + aWorld, + aX + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, + aY + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, + aZ + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, + new ItemStack(tItem.getItem(), tItem.stackSize, tItem.getItemDamage())); + if (tItem.hasTagCompound()) { + tItemEntity.getEntityItem() + .setTagCompound( + (NBTTagCompound) tItem.getTagCompound() + .copy()); + } + tItemEntity.motionX = (XSTR_INSTANCE.nextGaussian() * 0.05D); + tItemEntity.motionY = (XSTR_INSTANCE.nextGaussian() * 0.25D); + tItemEntity.motionZ = (XSTR_INSTANCE.nextGaussian() * 0.05D); + aWorld.spawnEntityInWorld(tItemEntity); + tItem.stackSize = 0; + inv.mStoredItemInternal[i]=null; + } + } + super.onBlockDestroyed(); +} } diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java index 6f47633..d2c6d9e 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java @@ -630,5 +630,13 @@ public ItemStack getCrafterIcon() { ItemStack is = this.getMachineCraftingIcon(); return is == null ? new ItemStack(GregTech_API.sBlockMachines, 1, getBaseMetaTileEntity().getMetaTileID()) : is; } - + @Override + public void onBlockDestroyed() { + try { + refundAll(); + } catch (Exception e) { + e.printStackTrace(); + } + super.onBlockDestroyed(); + } }