Merge pull request #2158 from MellowArpeggiation/master

the five hundredth crate dupe fix
This commit is contained in:
HbmMods 2025-05-20 09:48:25 +02:00 committed by GitHub
commit c7f570706d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 58 additions and 55 deletions

View File

@ -7,6 +7,7 @@ import api.hbm.conveyor.IEnterableBlock;
import com.hbm.blocks.IBlockMultiPass;
import com.hbm.blocks.ITooltipProvider;
import com.hbm.entity.item.EntityMovingItem;
import com.hbm.items.tool.ItemConveyorWand;
import com.hbm.lib.RefStrings;
import com.hbm.main.MainRegistry;
import com.hbm.module.ModulePatternMatcher;
@ -61,7 +62,9 @@ public class CraneRouter extends BlockContainer implements IBlockMultiPass, IEnt
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if(world.isRemote) {
if(player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ItemConveyorWand) {
return false;
} else if(world.isRemote) {
return true;
} else if(!player.isSneaking()) {
FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z);

View File

@ -17,7 +17,7 @@ public class ServerConfig extends RunningConfig {
public static ConfigWrapper<Float> MINE_NUKE_DAMAGE = new ConfigWrapper(100F);
public static ConfigWrapper<Float> MINE_NAVAL_DAMAGE = new ConfigWrapper(60F);
public static ConfigWrapper<Boolean> TAINT_TRAILS = new ConfigWrapper(false);
public static ConfigWrapper<Boolean> CRATE_ALLOW_OPEN_HELD = new ConfigWrapper(false);
public static ConfigWrapper<Boolean> CRATE_ALLOW_OPEN_HELD = new ConfigWrapper(true);
public static ConfigWrapper<Boolean> CRATE_KEEP_CONTENTS = new ConfigWrapper(true);
public static ConfigWrapper<Integer> ITEM_HAZARD_DROP_TICKRATE = new ConfigWrapper(2);

View File

@ -10,14 +10,11 @@ import net.minecraft.tileentity.TileEntity;
public class ContainerCrateBase extends ContainerBase {
//just there so prev stuff doesnt break
protected IInventory crate = tile;
public ContainerCrateBase(InventoryPlayer invPlayer, IInventory tedf) {
super(invPlayer, tedf);
tile.openInventory();
}
@Override
public void playerInv(InventoryPlayer invPlayer, int playerInvX, int playerInvY, int playerHotbarY) {
for(int i = 0; i < 3; i++) {
@ -35,7 +32,7 @@ public class ContainerCrateBase extends ContainerBase {
public ItemStack slotClick(int index, int button, int mode, EntityPlayer player) {
// prevents the player from moving around the currently open box
if(player.inventory.getStackInSlot(player.inventory.currentItem) != null &&
player.inventory.getStackInSlot(player.inventory.currentItem).getItem() instanceof ItemBlockStorageCrate && !(this.crate instanceof TileEntity)) {
player.inventory.getStackInSlot(player.inventory.currentItem).getItem() instanceof ItemBlockStorageCrate && !(this.tile instanceof TileEntity)) {
if (mode == 2 && button == player.inventory.currentItem) {
return null;
}
@ -51,7 +48,7 @@ public class ContainerCrateBase extends ContainerBase {
super.onContainerClosed(p_75134_1_);
tile.closeInventory();
}
public class SlotPlayerCrate extends SlotNonRetarded {
public SlotPlayerCrate(IInventory inventory, int id, int x, int y) {
@ -66,7 +63,7 @@ public class ContainerCrateBase extends ContainerBase {
public boolean canTakeStack(EntityPlayer player) {
if(player.inventory.currentItem == this.getSlotIndex() && // If this slot is the current held slot.
this.getStack() != null && this.getStack().getItem() instanceof ItemBlockStorageCrate && // If the slot contains a storage crate.
player.openContainer instanceof ContainerCrateBase && !(ContainerCrateBase.this.crate instanceof TileEntity)) // If the player is currently inside a crate container.
player.openContainer instanceof ContainerCrateBase && !(ContainerCrateBase.this.tile instanceof TileEntity)) // If the player is currently inside a crate container.
return false;
return super.canTakeStack(player);
}

View File

@ -39,11 +39,11 @@ public class ContainerDroneRequester extends ContainerCrateBase {
if(par2 < 9) return null; //ignore filters
if(par2 <= crate.getSizeInventory() - 1) {
if(!this.mergeItemStack(var5, crate.getSizeInventory(), this.inventorySlots.size(), true)) {
if(par2 <= tile.getSizeInventory() - 1) {
if(!this.mergeItemStack(var5, tile.getSizeInventory(), this.inventorySlots.size(), true)) {
return null;
}
} else if(!this.mergeItemStack(var5, 9, crate.getSizeInventory(), false)) {
} else if(!this.mergeItemStack(var5, 9, tile.getSizeInventory(), false)) {
return null;
}
@ -75,25 +75,25 @@ public class ContainerDroneRequester extends ContainerCrateBase {
ItemStack ret = null;
ItemStack held = player.inventory.getItemStack();
TileEntityDroneRequester requester = (TileEntityDroneRequester) crate;
TileEntityDroneRequester requester = (TileEntityDroneRequester) tile;
if(slot.getHasStack())
ret = slot.getStack().copy();
if(button == 1 && mode == 0 && slot.getHasStack()) {
requester.nextMode(index);
return ret;
} else {
slot.putStack(held != null ? held.copy() : null);
if(slot.getHasStack()) {
slot.getStack().stackSize = 1;
}
slot.onSlotChanged();
requester.matcher.initPatternStandard(requester.getWorldObj(), slot.getStack(), index);
return ret;
}
}

View File

@ -28,21 +28,27 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
super(block);
}
// IF WE PUT ROCKS IN THE SHAPE OF A RUNWAY GOD WILL GIVE US HIGH-FRUCTOSE CORN SYRUP
@Override
public int getMaxItemUseDuration(ItemStack stack) {
return 1;
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if(!ServerConfig.CRATE_ALLOW_OPEN_HELD.get()) return stack;
Block block = Block.getBlockFromItem(player.getHeldItem().getItem());
if(block == ModBlocks.mass_storage) return stack; // Genuinely can't figure out how to make this part work, so I'm just not gonna mess with it.
if(!world.isRemote && stack.stackSize == 1) {
if (stack.stackTagCompound != null && stack.stackTagCompound.hasKey("lock")) {
for (ItemStack item : player.inventory.mainInventory) {
if(stack.stackTagCompound != null && stack.stackTagCompound.hasKey("lock")) {
for(ItemStack item : player.inventory.mainInventory) {
if(item == null) continue; // Skip if no item.
if(!(item.getItem() instanceof ItemKey)) continue; // Skip if item isn't a key.
if(item.stackTagCompound == null) continue; // Skip if there is no NBT (wouldn't open it anyway).
if (item.stackTagCompound.getInteger("pins") == stack.stackTagCompound.getInteger("lock")) { // Check if pins are equal (if it can open it)
if(item.stackTagCompound.getInteger("pins") == stack.stackTagCompound.getInteger("lock")) { // Check if pins are equal (if it can open it)
TileEntityCrateBase.spawnSpiders(player, world, stack);
player.openGui(MainRegistry.instance, 0, world, 0, 0, 0);
break;
@ -83,20 +89,16 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
}
public static class InventoryCrate extends ItemInventory {
public int heldIndex;
public InventoryCrate(EntityPlayer player, ItemStack crate) {
public InventoryCrate(EntityPlayer player, ItemStack crate) {
this.player = player;
this.target = crate;
this.heldIndex = player.inventory.currentItem;
this.slots = new ItemStack[this.getSizeInventory()];
if(target.stackTagCompound == null) {
target.stackTagCompound = new NBTTagCompound();
}
for(int i = 0; i < slots.length; i++)
this.slots[i] = ItemStack.loadItemStackFromNBT(target.stackTagCompound.getCompoundTag("slot" + i));
}
@ -129,42 +131,35 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
}
@Override
public void markDirty() { // I HATE THIS SO MUCH
NBTTagCompound nbt = new NBTTagCompound();
public void markDirty() { // You have been blessed by the unfuck
// Preserve existing NBT so we keep lock data and piders
NBTTagCompound nbt = target.stackTagCompound != null ? target.stackTagCompound : new NBTTagCompound();
int invSize = this.getSizeInventory();
for(int i = 0; i < invSize; i++) {
ItemStack stack = this.getStackInSlot(i);
if(stack == null) continue;
if(stack == null) {
nbt.removeTag("slot" + i);
continue;
}
NBTTagCompound slot = new NBTTagCompound();
stack.writeToNBT(slot);
nbt.setTag("slot" + i, slot);
}
/*if(target.stackTagCompound != null) { // yes it's a bit jank, but it wants to clear otherwise so...
if(target.stackTagCompound.hasKey("lock")) nbt.setInteger("lock", target.stackTagCompound.getInteger("lock"));
if(target.stackTagCompound.hasKey("lockMod")) nbt.setDouble("lockMod", target.stackTagCompound.getDouble("lockMod"));
if(target.stackTagCompound.hasKey("spiders")) nbt.setBoolean("spiders", target.stackTagCompound.getBoolean("spiders")); // fuck you!!
}*/
// i have completely given up
if(player.getHeldItem() != null && player.getHeldItem().getItem() == this.target.getItem() && player.inventory.currentItem == this.heldIndex) {
player.getHeldItem().setTagCompound(nbt);
}
target.setTagCompound(nbt);
}
@Override
public void closeInventory() {
player.worldObj.playSoundEffect(player.posX, player.posY, player.posZ, "hbm:block.crateClose", 1.0F, 0.8F);
/*
* realistically, we only need one NBT size check (and we only *want* one because CompressedStreamTools is expensive) so we do that part only when closing
*/
if(player.getHeldItem() != null && player.getHeldItem().getItem() == this.target.getItem() && player.inventory.currentItem == this.heldIndex) {
player.getHeldItem().setTagCompound(checkNBT(player.getHeldItem().getTagCompound()));
}
super.closeInventory();
// Check for 6kb item vomit
target.setTagCompound(checkNBT(target.getTagCompound()));
player.inventoryContainer.detectAndSendChanges();
}
}
}

View File

@ -10,6 +10,7 @@ import com.hbm.tileentity.IGUIProvider;
import com.hbm.util.ItemStackUtil;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
@ -35,6 +36,11 @@ public class ItemToolBox extends Item implements IGUIProvider {
this.setMaxStackSize(1);
}
@Override
public int getMaxItemUseDuration(ItemStack stack) {
return 1;
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconRegister) {
@ -285,9 +291,11 @@ public class ItemToolBox extends Item implements IGUIProvider {
@Override
public void closeInventory() {
this.target.getTagCompound().removeTag("isOpen");
this.player.inventory.setInventorySlotContents(this.player.inventory.currentItem, this.target);
super.closeInventory();
this.target.getTagCompound().removeTag("isOpen");
this.target.getTagCompound().setInteger("rand", player.worldObj.rand.nextInt()); // a boolean changing isn't sufficient to detect the change
player.inventoryContainer.detectAndSendChanges();
}
@Override