mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
crate dupe fix(?)
This commit is contained in:
parent
e518ef48c9
commit
4fd4aa819b
@ -5,4 +5,5 @@
|
||||
## Fixed
|
||||
* Fixed a potential crash caused by cargo dropships landing on cargo docks with no satellite chip installed
|
||||
* Fixed potential crash related to hazard handling for dropped items
|
||||
* Fixed errors thrown when loading in old system bullet entities
|
||||
* Fixed errors thrown when loading in old system bullet entities
|
||||
* Fixed dupe regarding breaking transport drones
|
||||
@ -214,18 +214,10 @@ public class BlockStorageCrate extends BlockContainer implements IBlockMulti, IT
|
||||
|
||||
int i = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
|
||||
|
||||
if(i == 0) {
|
||||
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
|
||||
}
|
||||
if(i == 1) {
|
||||
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
|
||||
}
|
||||
if(i == 2) {
|
||||
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
|
||||
}
|
||||
if(i == 3) {
|
||||
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
|
||||
}
|
||||
if(i == 0) world.setBlockMetadataWithNotify(x, y, z, 2, 2);
|
||||
if(i == 1) world.setBlockMetadataWithNotify(x, y, z, 5, 2);
|
||||
if(i == 2) world.setBlockMetadataWithNotify(x, y, z, 3, 2);
|
||||
if(i == 3) world.setBlockMetadataWithNotify(x, y, z, 4, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -35,6 +35,8 @@ public class EntityDeliveryDrone extends EntityDroneBase implements IInventory,
|
||||
@Override
|
||||
public boolean hitByEntity(Entity attacker) {
|
||||
|
||||
if(this.isDead) return false;
|
||||
|
||||
if(attacker instanceof EntityPlayer && !worldObj.isRemote) {
|
||||
this.setDead();
|
||||
for (ItemStack stack : slots) {
|
||||
|
||||
@ -43,6 +43,8 @@ public class EntityRequestDrone extends EntityDroneBase {
|
||||
@Override
|
||||
public boolean hitByEntity(Entity attacker) {
|
||||
|
||||
if(this.isDead) return false;
|
||||
|
||||
if(attacker instanceof EntityPlayer && !worldObj.isRemote) {
|
||||
this.setDead();
|
||||
if(heldItem != null)
|
||||
|
||||
@ -23,14 +23,9 @@ public abstract class ItemInventory implements IInventory {
|
||||
public ItemStack[] slots;
|
||||
public ItemStack target;
|
||||
|
||||
public boolean toMarkDirty = false;
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
|
||||
if(!toMarkDirty || player.getEntityWorld().isRemote)
|
||||
return;
|
||||
|
||||
for(int i = 0; i < getSizeInventory(); ++i) {
|
||||
if(getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) {
|
||||
slots[i] = null;
|
||||
@ -38,7 +33,6 @@ public abstract class ItemInventory implements IInventory {
|
||||
}
|
||||
|
||||
ItemStackUtil.addStacksToNBT(target, slots); // Maintain compatibility with the containment boxes.
|
||||
|
||||
target.setTagCompound(checkNBT(target.getTagCompound()));
|
||||
|
||||
}
|
||||
@ -93,9 +87,10 @@ public abstract class ItemInventory implements IInventory {
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
ItemStack stack = getStackInSlot(slot);
|
||||
if (stack != null) {
|
||||
if(stack != null) {
|
||||
if (stack.stackSize > amount) {
|
||||
stack = stack.splitStack(amount);
|
||||
markDirty();
|
||||
} else {
|
||||
setInventorySlotContents(slot, null);
|
||||
}
|
||||
@ -110,6 +105,7 @@ public abstract class ItemInventory implements IInventory {
|
||||
}
|
||||
|
||||
slots[slot] = stack;
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -119,36 +115,12 @@ public abstract class ItemInventory implements IInventory {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return slots[slot];
|
||||
}
|
||||
@Override public ItemStack getStackInSlot(int slot) { return slots[slot]; }
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
@Override public boolean isUseableByPlayer(EntityPlayer player) { return true; }
|
||||
@Override public boolean isItemValidForSlot(int slot, ItemStack stack) { return true; }
|
||||
@Override public int getInventoryStackLimit() { return 64; }
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
player.worldObj.playSoundEffect(player.posX, player.posY, player.posZ, "hbm:block.crateOpen", 1.0F, 0.8F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
toMarkDirty = true;
|
||||
markDirty();
|
||||
toMarkDirty = false;
|
||||
player.worldObj.playSoundEffect(player.posX, player.posY, player.posZ, "hbm:block.crateClose", 1.0F, 0.8F);
|
||||
}
|
||||
@Override public void openInventory() { player.worldObj.playSoundEffect(player.posX, player.posY, player.posZ, "hbm:block.crateOpen", 1.0F, 0.8F); }
|
||||
@Override public void closeInventory() { player.worldObj.playSoundEffect(player.posX, player.posY, player.posZ, "hbm:block.crateClose", 1.0F, 0.8F); }
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import com.hbm.items.tool.ItemKey;
|
||||
import com.hbm.main.MainRegistry;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.machine.storage.*;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
@ -34,12 +35,10 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
|
||||
if(!world.isRemote && stack.stackSize == 1) {
|
||||
if (stack.stackTagCompound != null && stack.stackTagCompound.hasKey("lock")) {
|
||||
for (ItemStack item : player.inventory.mainInventory) {
|
||||
if(item == null) // Skip if no item.
|
||||
continue;
|
||||
if(!(item.getItem() instanceof ItemKey)) // Skip if item isn't a key.
|
||||
continue;
|
||||
if(item.stackTagCompound == null) // Skip if there is no NBT (wouldn't open it anyway).
|
||||
continue;
|
||||
|
||||
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)
|
||||
TileEntityCrateBase.spawnSpiders(player, world, stack);
|
||||
player.openGui(MainRegistry.instance, 0, world, 0, 0, 0);
|
||||
@ -81,22 +80,19 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
|
||||
}
|
||||
|
||||
public static class InventoryCrate extends ItemInventory {
|
||||
|
||||
|
||||
public InventoryCrate(EntityPlayer player, ItemStack crate) {
|
||||
|
||||
this.player = player;
|
||||
this.target = crate;
|
||||
|
||||
slots = new ItemStack[this.getSizeInventory()];
|
||||
if(crate.stackTagCompound == null)
|
||||
crate.stackTagCompound = new NBTTagCompound();
|
||||
else if(!player.worldObj.isRemote) {
|
||||
for (int i = 0; i < this.getSizeInventory(); i++)
|
||||
this.setInventorySlotContents(i, ItemStack.loadItemStackFromNBT(crate.stackTagCompound.getCompoundTag("slot" + i)));
|
||||
|
||||
this.slots = new ItemStack[this.getSizeInventory()];
|
||||
if(target.stackTagCompound == null) {
|
||||
target.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
toMarkDirty = true;
|
||||
this.markDirty();
|
||||
toMarkDirty = false;
|
||||
|
||||
for(int i = 0; i < slots.length; i++)
|
||||
this.slots[i] = ItemStack.loadItemStackFromNBT(target.stackTagCompound.getCompoundTag("slot" + i));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@ -128,38 +124,36 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
|
||||
|
||||
@Override
|
||||
public void markDirty() { // I HATE THIS SO MUCH
|
||||
|
||||
if(player.getEntityWorld().isRemote || !toMarkDirty) { // go the fuck away
|
||||
return;
|
||||
}
|
||||
|
||||
NBTTagCompound nbt = 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) 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!!
|
||||
/*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!!
|
||||
}*/
|
||||
|
||||
/*
|
||||
* target and held item stacks constantly desync, not being the same reference, while still holding the same value.
|
||||
* code was tested with a copy of the containment box code using the CB's GUI and container to no avail.
|
||||
* hypothesis: minecraft's keybind handling has some special bullshit case for ItemBlocks, since that is the only difference in the test.
|
||||
* solution (?): check equality, then just access the held stack directly. if not, pray the target reference is still accurate and use that.
|
||||
*/
|
||||
if(player.getHeldItem() != null && ItemStack.areItemStacksEqual(player.getHeldItem(), target)) {
|
||||
player.getHeldItem().setTagCompound(checkNBT(nbt));
|
||||
} else {
|
||||
target.setTagCompound(checkNBT(nbt));
|
||||
}
|
||||
|
||||
target.setTagCompound(checkNBT(nbt));
|
||||
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,6 @@ public class ItemLeadBox extends Item implements IGUIProvider {
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
|
||||
|
||||
if(!world.isRemote) player.openGui(MainRegistry.instance, 0, world, 0, 0, 0);
|
||||
return stack;
|
||||
}
|
||||
@ -60,9 +59,6 @@ public class ItemLeadBox extends Item implements IGUIProvider {
|
||||
if(fromNBT != null) {
|
||||
System.arraycopy(fromNBT, 0, slots, 0, slots.length);
|
||||
}
|
||||
toMarkDirty = true;
|
||||
this.markDirty();
|
||||
toMarkDirty = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -266,9 +266,6 @@ public class ItemToolBox extends Item implements IGUIProvider {
|
||||
if(fromNBT != null) {
|
||||
System.arraycopy(fromNBT, 0, slots, 0, slots.length);
|
||||
}
|
||||
toMarkDirty = true;
|
||||
this.markDirty();
|
||||
toMarkDirty = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user