Fixed check for max storage for chests. Closes #1026

This commit is contained in:
drcrazy 2017-09-22 04:03:20 +03:00
parent 833974d698
commit ae75191c00
6 changed files with 40 additions and 76 deletions

View file

@ -26,7 +26,6 @@ package techreborn.blocks;
import net.minecraft.block.BlockDynamicLiquid; import net.minecraft.block.BlockDynamicLiquid;
import net.minecraft.block.BlockStaticLiquid; import net.minecraft.block.BlockStaticLiquid;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -37,6 +36,7 @@ import prospector.shootingstar.ShootingStar;
import prospector.shootingstar.model.ModelCompound; import prospector.shootingstar.model.ModelCompound;
import reborncore.api.tile.IMachineGuiHandler; import reborncore.api.tile.IMachineGuiHandler;
import reborncore.common.blocks.BlockMachineBase; import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.util.WorldUtils;
import techreborn.client.EGui; import techreborn.client.EGui;
import techreborn.client.TechRebornCreativeTab; import techreborn.client.TechRebornCreativeTab;
import techreborn.lib.ModInfo; import techreborn.lib.ModInfo;
@ -45,7 +45,6 @@ import techreborn.tiles.TileTechStorageBase;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random;
public class BlockDigitalChest extends BlockMachineBase { public class BlockDigitalChest extends BlockMachineBase {
@ -89,28 +88,7 @@ public class BlockDigitalChest extends BlockMachineBase {
} }
items.add(itemStack.copy()); items.add(itemStack.copy());
} }
WorldUtils.dropItems(items, world, pos);
for (final ItemStack itemStack : items) {
final Random rand = new Random();
final float dX = rand.nextFloat() * 0.8F + 0.1F;
final float dY = rand.nextFloat() * 0.8F + 0.1F;
final float dZ = rand.nextFloat() * 0.8F + 0.1F;
final EntityItem entityItem = new EntityItem(world, pos.getX() + dX, pos.getY() + dY, pos.getZ() + dZ,
itemStack.copy());
if (itemStack.hasTagCompound()) {
entityItem.getItem().setTagCompound(itemStack.getTagCompound().copy());
}
final float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntity(entityItem);
itemStack.setCount(0);
}
} }
@Override @Override

View file

@ -26,7 +26,6 @@ package techreborn.blocks;
import net.minecraft.block.BlockDynamicLiquid; import net.minecraft.block.BlockDynamicLiquid;
import net.minecraft.block.BlockStaticLiquid; import net.minecraft.block.BlockStaticLiquid;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -37,6 +36,7 @@ import prospector.shootingstar.ShootingStar;
import prospector.shootingstar.model.ModelCompound; import prospector.shootingstar.model.ModelCompound;
import reborncore.api.tile.IMachineGuiHandler; import reborncore.api.tile.IMachineGuiHandler;
import reborncore.common.blocks.BlockMachineBase; import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.util.WorldUtils;
import techreborn.client.EGui; import techreborn.client.EGui;
import techreborn.client.TechRebornCreativeTab; import techreborn.client.TechRebornCreativeTab;
import techreborn.lib.ModInfo; import techreborn.lib.ModInfo;
@ -45,7 +45,6 @@ import techreborn.tiles.TileTechStorageBase;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random;
public class BlockQuantumChest extends BlockMachineBase { public class BlockQuantumChest extends BlockMachineBase {
@ -95,28 +94,7 @@ public class BlockQuantumChest extends BlockMachineBase {
} }
items.add(itemStack.copy()); items.add(itemStack.copy());
} }
WorldUtils.dropItems(items, world, pos);
for (final ItemStack itemStack : items) {
final Random rand = new Random();
final float dX = rand.nextFloat() * 0.8F + 0.1F;
final float dY = rand.nextFloat() * 0.8F + 0.1F;
final float dZ = rand.nextFloat() * 0.8F + 0.1F;
final EntityItem entityItem = new EntityItem(world, pos.getX() + dX, pos.getY() + dY, pos.getZ() + dZ,
itemStack.copy());
if (itemStack.hasTagCompound()) {
entityItem.getItem().setTagCompound(itemStack.getTagCompound().copy());
}
final float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntity(entityItem);
itemStack.setCount(0);
}
} }
@Override @Override

View file

@ -59,8 +59,8 @@ public class TileChargeOMat extends TilePowerAcceptor
} }
@Override @Override
public void updateEntity() { public void update() {
super.updateEntity(); super.update();
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
if (this.inventory.getStackInSlot(i) != ItemStack.EMPTY) { if (this.inventory.getStackInSlot(i) != ItemStack.EMPTY) {

View file

@ -26,9 +26,7 @@ package techreborn.tiles;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.tileentity.TileEntityFurnace;

View file

@ -61,28 +61,37 @@ public class TileTechStorageBase extends TileLegacyMachineBase
@Override @Override
public void updateEntity() { public void updateEntity() {
if (!world.isRemote) { if (!world.isRemote) {
if (this.getStackInSlot(0) != ItemStack.EMPTY) { ItemStack outputStack = ItemStack.EMPTY;
if (!this.getStackInSlot(1).isEmpty()){
outputStack = this.getStackInSlot(1);
}
if (this.getStackInSlot(0) != ItemStack.EMPTY
&& (this.storedItem.getCount() + outputStack.getCount()) < this.maxCapacity) {
ItemStack inputStack = this.getStackInSlot(0);
if (this.getStoredItemType().isEmpty() || (this.storedItem.isEmpty() if (this.getStoredItemType().isEmpty() || (this.storedItem.isEmpty()
&& ItemUtils.isItemEqual(this.getStackInSlot(0), this.getStackInSlot(1), true, true))) { && ItemUtils.isItemEqual(inputStack, outputStack, true, true))) {
this.storedItem = this.getStackInSlot(0); this.storedItem = inputStack;
this.setInventorySlotContents(0, ItemStack.EMPTY); this.setInventorySlotContents(0, ItemStack.EMPTY);
this.syncWithAll(); } else if (ItemUtils.isItemEqual(this.getStoredItemType(), inputStack, true, true)) {
} else if (ItemUtils.isItemEqual(this.getStoredItemType(), this.getStackInSlot(0), true, true)) { int reminder = this.maxCapacity - this.storedItem.getCount() - outputStack.getCount();
if (inputStack.getCount() <= reminder) {
this.setStoredItemCount(this.getStackInSlot(0).getCount()); this.setStoredItemCount(inputStack.getCount());
this.setInventorySlotContents(0, ItemStack.EMPTY); this.setInventorySlotContents(0, ItemStack.EMPTY);
this.syncWithAll(); } else {
this.setStoredItemCount(this.maxCapacity - outputStack.getCount());
this.getStackInSlot(0).shrink(reminder);
}
} }
this.markDirty(); this.markDirty();
this.syncWithAll();
} }
if (!this.storedItem.isEmpty()) { if (!this.storedItem.isEmpty()) {
if (this.getStackInSlot(1) == ItemStack.EMPTY) { if (outputStack == ItemStack.EMPTY) {
ItemStack delivered = this.storedItem.copy(); ItemStack delivered = this.storedItem.copy();
delivered.setCount(Math.min(this.storedItem.getCount(), delivered.getMaxStackSize())); delivered.setCount(Math.min(this.storedItem.getCount(), delivered.getMaxStackSize()));
this.storedItem.shrink(delivered.getCount()); this.storedItem.shrink(delivered.getCount());
if (this.storedItem.isEmpty()) if (this.storedItem.isEmpty())
@ -91,13 +100,13 @@ public class TileTechStorageBase extends TileLegacyMachineBase
this.setInventorySlotContents(1, delivered); this.setInventorySlotContents(1, delivered);
this.markDirty(); this.markDirty();
this.syncWithAll(); this.syncWithAll();
} else if (ItemUtils.isItemEqual(this.storedItem, this.getStackInSlot(1), true, true) } else if (ItemUtils.isItemEqual(this.storedItem, outputStack, true, true)
&& this.getStackInSlot(1).getCount() < this.getStackInSlot(1).getMaxStackSize()) { && outputStack.getCount() < outputStack.getMaxStackSize()) {
int wanted = Math.min(this.storedItem.getCount(), int wanted = Math.min(this.storedItem.getCount(),
this.getStackInSlot(1).getMaxStackSize() - this.getStackInSlot(1).getCount()); outputStack.getMaxStackSize() - outputStack.getCount());
this.getStackInSlot(1).setCount(this.getStackInSlot(1).getCount() + wanted); outputStack.setCount(outputStack.getCount() + wanted);
this.storedItem.shrink(wanted); this.storedItem.shrink(wanted);
if (this.storedItem.isEmpty()) if (this.storedItem.isEmpty())
@ -127,11 +136,11 @@ public class TileTechStorageBase extends TileLegacyMachineBase
storedItem = ItemStack.EMPTY; storedItem = ItemStack.EMPTY;
if (tagCompound.hasKey("storedStack")) { if (tagCompound.hasKey("storedStack")) {
storedItem = new ItemStack((NBTTagCompound) tagCompound.getTag("storedStack")); this.storedItem = new ItemStack((NBTTagCompound) tagCompound.getTag("storedStack"));
} }
if (!storedItem.isEmpty()) { if (!this.storedItem.isEmpty()) {
storedItem.setCount(tagCompound.getInteger("storedQuantity")); this.storedItem.setCount(Math.min(tagCompound.getInteger("storedQuantity"), this.maxCapacity));
} }
} }
@ -143,13 +152,13 @@ public class TileTechStorageBase extends TileLegacyMachineBase
} }
public NBTTagCompound writeToNBTWithoutCoords(NBTTagCompound tagCompound) { public NBTTagCompound writeToNBTWithoutCoords(NBTTagCompound tagCompound) {
if (!storedItem.isEmpty()) { if (!this.storedItem.isEmpty()) {
ItemStack temp = storedItem.copy(); ItemStack temp = this.storedItem.copy();
if (storedItem.getCount() > storedItem.getMaxStackSize()){ if (this.storedItem.getCount() > storedItem.getMaxStackSize()){
temp.setCount(storedItem.getMaxStackSize()); temp.setCount(storedItem.getMaxStackSize());
} }
tagCompound.setTag("storedStack", temp.writeToNBT(new NBTTagCompound())); tagCompound.setTag("storedStack", temp.writeToNBT(new NBTTagCompound()));
tagCompound.setInteger("storedQuantity", storedItem.getCount()); tagCompound.setInteger("storedQuantity", Math.min(this.storedItem.getCount(), this.maxCapacity));
} else { } else {
tagCompound.setInteger("storedQuantity", 0); tagCompound.setInteger("storedQuantity", 0);
} }
@ -170,6 +179,7 @@ public class TileTechStorageBase extends TileLegacyMachineBase
dropStack.getTagCompound().setTag("tileEntity", tileEntity); dropStack.getTagCompound().setTag("tileEntity", tileEntity);
this.storedItem.setCount(0); this.storedItem.setCount(0);
this.syncWithAll(); this.syncWithAll();
return dropStack; return dropStack;
} }

View file

@ -46,8 +46,8 @@ public class TileCreativeSolarPanel extends TilePowerAcceptor implements IToolDr
int powerToAdd; int powerToAdd;
@Override @Override
public void updateEntity() { public void update() {
super.updateEntity(); super.update();
this.setEnergy(getMaxPower()); this.setEnergy(getMaxPower());
} }