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.BlockStaticLiquid;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@ -37,6 +36,7 @@ import prospector.shootingstar.ShootingStar;
import prospector.shootingstar.model.ModelCompound;
import reborncore.api.tile.IMachineGuiHandler;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.util.WorldUtils;
import techreborn.client.EGui;
import techreborn.client.TechRebornCreativeTab;
import techreborn.lib.ModInfo;
@ -45,7 +45,6 @@ import techreborn.tiles.TileTechStorageBase;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class BlockDigitalChest extends BlockMachineBase {
@ -89,28 +88,7 @@ public class BlockDigitalChest extends BlockMachineBase {
}
items.add(itemStack.copy());
}
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);
}
WorldUtils.dropItems(items, world, pos);
}
@Override

View file

@ -26,7 +26,6 @@ package techreborn.blocks;
import net.minecraft.block.BlockDynamicLiquid;
import net.minecraft.block.BlockStaticLiquid;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@ -37,6 +36,7 @@ import prospector.shootingstar.ShootingStar;
import prospector.shootingstar.model.ModelCompound;
import reborncore.api.tile.IMachineGuiHandler;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.util.WorldUtils;
import techreborn.client.EGui;
import techreborn.client.TechRebornCreativeTab;
import techreborn.lib.ModInfo;
@ -45,7 +45,6 @@ import techreborn.tiles.TileTechStorageBase;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class BlockQuantumChest extends BlockMachineBase {
@ -95,28 +94,7 @@ public class BlockQuantumChest extends BlockMachineBase {
}
items.add(itemStack.copy());
}
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);
}
WorldUtils.dropItems(items, world, pos);
}
@Override

View file

@ -59,8 +59,8 @@ public class TileChargeOMat extends TilePowerAcceptor
}
@Override
public void updateEntity() {
super.updateEntity();
public void update() {
super.update();
for (int i = 0; i < 6; i++) {
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.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntityFurnace;

View file

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

View file

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