diff --git a/src/main/java/techreborn/tiles/TileAlarm.java b/src/main/java/techreborn/tiles/TileAlarm.java index 160890f10..fecd3d009 100644 --- a/src/main/java/techreborn/tiles/TileAlarm.java +++ b/src/main/java/techreborn/tiles/TileAlarm.java @@ -71,7 +71,7 @@ public class TileAlarm extends TileEntity @Override public void readFromNBT(NBTTagCompound compound) { if (compound != null && compound.hasKey("selectedSound")) { - this.selectedSound = compound.getInteger("selectedSound"); + selectedSound = compound.getInteger("selectedSound"); } super.readFromNBT(compound); } @@ -88,13 +88,13 @@ public class TileAlarm extends TileEntity BlockAlarm.setActive(true, world, pos); switch (selectedSound) { case 1: - world.playSound(null, getPos().getX(), getPos().getY(), getPos().getZ(), ModSounds.ALARM, SoundCategory.BLOCKS, 4F, 1F); + world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.ALARM, SoundCategory.BLOCKS, 4F, 1F); break; case 2: - world.playSound(null, getPos().getX(), getPos().getY(), getPos().getZ(), ModSounds.ALARM_2, SoundCategory.BLOCKS, 4F, 1F); + world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.ALARM_2, SoundCategory.BLOCKS, 4F, 1F); break; case 3: - world.playSound(null, getPos().getX(), getPos().getY(), getPos().getZ(), ModSounds.ALARM_3, SoundCategory.BLOCKS, 4F, 1F); + world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.ALARM_3, SoundCategory.BLOCKS, 4F, 1F); break; } diff --git a/src/main/java/techreborn/tiles/TileChargeOMat.java b/src/main/java/techreborn/tiles/TileChargeOMat.java index 37b2dc025..b0c46a472 100644 --- a/src/main/java/techreborn/tiles/TileChargeOMat.java +++ b/src/main/java/techreborn/tiles/TileChargeOMat.java @@ -33,7 +33,6 @@ import reborncore.api.IToolDrop; import reborncore.api.power.IEnergyItemInfo; import reborncore.api.tile.IInventoryProvider; import reborncore.common.RebornCoreConfig; -import reborncore.common.powerSystem.PoweredItem; import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.impl.ConfigRegistry; @@ -70,26 +69,18 @@ public class TileChargeOMat extends TilePowerAcceptor return; } for (int i = 0; i < 6; i++) { - if (this.inventory.getStackInSlot(i) != ItemStack.EMPTY) { - if (this.getEnergy() > 0) { - final ItemStack stack = this.inventory.getStackInSlot(i); - if (stack.getItem() instanceof IEnergyItemInfo) { - IEnergyItemInfo item = (IEnergyItemInfo) stack.getItem(); - if (PoweredItem.getEnergy(stack) != PoweredItem.getMaxPower(stack)) { - if (canUseEnergy(item.getMaxTransfer(stack))) { - useEnergy(item.getMaxTransfer(stack)); - PoweredItem.setEnergy(PoweredItem.getEnergy(stack) + item.getMaxTransfer(stack), stack); - } - } - } - if(CompatManager.isIC2Loaded){ - IC2ItemCharger.chargeIc2Item(this, stack); - } - if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){ - IEnergyStorage energyStorage = stack.getCapability(CapabilityEnergy.ENERGY, null); - int max = Math.min(maxInput, (int) getEnergy()) * RebornCoreConfig.euPerFU; - useEnergy(energyStorage.receiveEnergy(max, false) / RebornCoreConfig.euPerFU); + if (!inventory.getStackInSlot(i).isEmpty()) { + final ItemStack stack = inventory.getStackInSlot(i); + if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) { + IEnergyStorage powerItem = stack.getCapability(CapabilityEnergy.ENERGY, null); + int maxReceive = Math.min((powerItem.getMaxEnergyStored() - powerItem.getEnergyStored()), + (int) ((IEnergyItemInfo) stack.getItem()).getMaxTransfer(stack)); + double maxUse = Math.min((double) (maxReceive / RebornCoreConfig.euPerFU), getMaxInput()); + if (getEnergy() >= 0.0 && maxReceive > 0) { + powerItem.receiveEnergy((int) useEnergy(maxUse) * RebornCoreConfig.euPerFU, false); } + } else if (CompatManager.isIC2Loaded) { + IC2ItemCharger.chargeIc2Item(this, stack); } } } @@ -135,7 +126,7 @@ public class TileChargeOMat extends TilePowerAcceptor // IInventoryProvider @Override public Inventory getInventory() { - return this.inventory; + return inventory; } // IContainerProvider diff --git a/src/main/java/techreborn/tiles/TileChunkLoader.java b/src/main/java/techreborn/tiles/TileChunkLoader.java index 6be03a0b8..ab71e3d38 100644 --- a/src/main/java/techreborn/tiles/TileChunkLoader.java +++ b/src/main/java/techreborn/tiles/TileChunkLoader.java @@ -45,7 +45,7 @@ public class TileChunkLoader extends TilePowerAcceptor implements IToolDrop, IIn @ConfigRegistry(config = "machines", category = "chunk_loader", key = "ChunkLoaderMaxInput", comment = "Chunk Loader Max Input (Value in EU)") public static int maxInput = 32; @ConfigRegistry(config = "machines", category = "chunk_loader", key = "ChunkLoaderMaxEnergy", comment = "Chunk Loader Max Energy (Value in EU)") - public static int maxEnergy = 10000; + public static int maxEnergy = 10_000; // @ConfigRegistry(config = "machines", category = "chunk_loader", key = "ChunkLoaderWrenchDropRate", comment = "Chunk Loader Wrench Drop Rate") public static float wrenchDropRate = 1.0F; diff --git a/src/main/java/techreborn/tiles/TileDigitalChest.java b/src/main/java/techreborn/tiles/TileDigitalChest.java index 18c9e6585..dadfe64e0 100644 --- a/src/main/java/techreborn/tiles/TileDigitalChest.java +++ b/src/main/java/techreborn/tiles/TileDigitalChest.java @@ -47,9 +47,4 @@ public class TileDigitalChest extends TileTechStorageBase implements IContainerP return new ContainerBuilder("digitalchest").player(player.inventory).inventory().hotbar().addInventory() .tile(this).slot(0, 80, 24).outputSlot(1, 80, 64).addInventory().create(this); } - - @Override - public boolean canBeUpgraded() { - return false; - } } diff --git a/src/main/java/techreborn/tiles/TileGenericMachine.java b/src/main/java/techreborn/tiles/TileGenericMachine.java index 7e103a477..ae634523c 100644 --- a/src/main/java/techreborn/tiles/TileGenericMachine.java +++ b/src/main/java/techreborn/tiles/TileGenericMachine.java @@ -77,8 +77,8 @@ public abstract class TileGenericMachine extends TilePowerAcceptor @Override public void update() { super.update(); - if (!this.world.isRemote) { - this.charge(energySlot); + if (!world.isRemote) { + charge(energySlot); } } diff --git a/src/main/java/techreborn/tiles/TileMatterFabricator.java b/src/main/java/techreborn/tiles/TileMatterFabricator.java index dfa020292..879a1807a 100644 --- a/src/main/java/techreborn/tiles/TileMatterFabricator.java +++ b/src/main/java/techreborn/tiles/TileMatterFabricator.java @@ -45,7 +45,7 @@ import techreborn.lib.ModInfo; @RebornRegistry(modID = ModInfo.MOD_ID) public class TileMatterFabricator extends TilePowerAcceptor - implements IToolDrop, IInventoryProvider, IContainerProvider { + implements IToolDrop, IInventoryProvider, IContainerProvider { @ConfigRegistry(config = "machines", category = "matter_fabricator", key = "MatterFabricatorMaxInput", comment = "Matter Fabricator Max Input (Value in EU)") public static int maxInput = 8192; @@ -62,7 +62,7 @@ public class TileMatterFabricator extends TilePowerAcceptor public TileMatterFabricator() { super(); } - + private boolean spaceForOutput() { for (int i = 6; i < 11; i++) { if (spaceForOutput(i)) { @@ -73,9 +73,9 @@ public class TileMatterFabricator extends TilePowerAcceptor } private boolean spaceForOutput(int slot) { - return this.inventory.getStackInSlot(slot).isEmpty() - || ItemUtils.isItemEqual(this.inventory.getStackInSlot(slot), new ItemStack(ModItems.UU_MATTER), true, true) - && this.inventory.getStackInSlot(slot).getCount() < 64; + return inventory.getStackInSlot(slot).isEmpty() + || ItemUtils.isItemEqual(inventory.getStackInSlot(slot), new ItemStack(ModItems.UU_MATTER), true, true) + && inventory.getStackInSlot(slot).getCount() < 64; } private void addOutputProducts() { @@ -88,20 +88,21 @@ public class TileMatterFabricator extends TilePowerAcceptor } private void addOutputProducts(int slot) { - if (this.inventory.getStackInSlot(slot).isEmpty()) { - this.inventory.setInventorySlotContents(slot, new ItemStack(ModItems.UU_MATTER)); - } else if (ItemUtils.isItemEqual(this.inventory.getStackInSlot(slot), new ItemStack(ModItems.UU_MATTER), true, true)) { - this.inventory.getStackInSlot(slot).setCount((Math.min(64, 1 + this.inventory.getStackInSlot(slot).getCount()))); + if (inventory.getStackInSlot(slot).isEmpty()) { + inventory.setInventorySlotContents(slot, new ItemStack(ModItems.UU_MATTER)); + } + else if (ItemUtils.isItemEqual(this.inventory.getStackInSlot(slot), new ItemStack(ModItems.UU_MATTER), true, true)) { + inventory.getStackInSlot(slot).setCount((Math.min(64, 1 + inventory.getStackInSlot(slot).getCount()))); } } - public boolean decreaseStoredEnergy(final double aEnergy, final boolean aIgnoreTooLessEnergy) { - if (this.getEnergy() - aEnergy < 0 && !aIgnoreTooLessEnergy) { + public boolean decreaseStoredEnergy(double aEnergy, boolean aIgnoreTooLessEnergy) { + if (getEnergy() - aEnergy < 0 && !aIgnoreTooLessEnergy) { return false; } else { - this.setEnergy(this.getEnergy() - aEnergy); - if (this.getEnergy() < 0) { - this.setEnergy(0); + setEnergy(getEnergy() - aEnergy); + if (getEnergy() < 0) { + setEnergy(0); return false; } else { return true; @@ -109,8 +110,9 @@ public class TileMatterFabricator extends TilePowerAcceptor } } - public int getValue(final ItemStack itemStack) { - if (itemStack.getItem() == ModItems.PARTS && itemStack.getItemDamage() == ItemParts.getPartByName("scrap").getItemDamage()) { + public int getValue(ItemStack itemStack) { + if (itemStack.getItem() == ModItems.PARTS + && itemStack.getItemDamage() == ItemParts.getPartByName("scrap").getItemDamage()) { return 200; } else if (itemStack.getItem() == ModItems.SCRAP_BOX) { return 2000; @@ -122,18 +124,18 @@ public class TileMatterFabricator extends TilePowerAcceptor } return 0; } - + public int getProgress() { - return this.amplifier; + return amplifier; } - public void setProgress(final int progress) { - this.amplifier = progress; + public void setProgress(int progress) { + amplifier = progress; } - public int getProgressScaled(final int scale) { - if (this.amplifier != 0) { - return Math.min(this.amplifier * scale / fabricationRate, 100); + public int getProgressScaled(int scale) { + if (amplifier != 0) { + return Math.min(amplifier * scale / fabricationRate, 100); } return 0; } @@ -141,27 +143,29 @@ public class TileMatterFabricator extends TilePowerAcceptor // TilePowerAcceptor @Override public void update() { - if (world.isRemote){ return; } - + if (world.isRemote) { + return; + } + super.update(); this.charge(11); for (int i = 0; i < 6; i++) { - final ItemStack stack = this.inventory.getStackInSlot(i); + final ItemStack stack = inventory.getStackInSlot(i); if (!stack.isEmpty() && spaceForOutput()) { - final int amp = this.getValue(stack); + final int amp = getValue(stack); final int euNeeded = amp * energyPerAmp; if (amp != 0 && this.canUseEnergy(euNeeded)) { - this.useEnergy(euNeeded); - this.amplifier += amp; - this.inventory.decrStackSize(i, 1); + useEnergy(euNeeded); + amplifier += amp; + inventory.decrStackSize(i, 1); } } } if (amplifier >= fabricationRate) { if (spaceForOutput()) { - this.addOutputProducts(); + addOutputProducts(); amplifier -= fabricationRate; } } @@ -173,12 +177,12 @@ public class TileMatterFabricator extends TilePowerAcceptor } @Override - public boolean canAcceptEnergy(final EnumFacing direction) { + public boolean canAcceptEnergy(EnumFacing direction) { return true; } @Override - public boolean canProvideEnergy(final EnumFacing direction) { + public boolean canProvideEnergy(EnumFacing direction) { return false; } @@ -191,28 +195,28 @@ public class TileMatterFabricator extends TilePowerAcceptor public double getBaseMaxInput() { return maxInput; } - - //TileLegacyMachineBase + + // TileLegacyMachineBase @Override public boolean canBeUpgraded() { return false; } - + // IToolDrop @Override - public ItemStack getToolDrop(final EntityPlayer entityPlayer) { + public ItemStack getToolDrop(EntityPlayer entityPlayer) { return new ItemStack(ModBlocks.MATTER_FABRICATOR, 1); } // IInventoryProvider @Override public Inventory getInventory() { - return this.inventory; + return inventory; } // IContainerProvider @Override - public BuiltContainer createContainer(final EntityPlayer player) { + public BuiltContainer createContainer(EntityPlayer player) { return new ContainerBuilder("matterfabricator").player(player.inventory).inventory().hotbar().addInventory() .tile(this).slot(0, 30, 20).slot(1, 50, 20).slot(2, 70, 20).slot(3, 90, 20).slot(4, 110, 20) .slot(5, 130, 20).outputSlot(6, 40, 66).outputSlot(7, 60, 66).outputSlot(8, 80, 66) diff --git a/src/main/java/techreborn/tiles/TileQuantumChest.java b/src/main/java/techreborn/tiles/TileQuantumChest.java index bdeea391f..91699112a 100644 --- a/src/main/java/techreborn/tiles/TileQuantumChest.java +++ b/src/main/java/techreborn/tiles/TileQuantumChest.java @@ -47,9 +47,4 @@ public class TileQuantumChest extends TileTechStorageBase implements IContainerP return new ContainerBuilder("quantumchest").player(player.inventory).inventory().hotbar().addInventory() .tile(this).slot(0, 80, 24).outputSlot(1, 80, 64).addInventory().create(this); } - - @Override - public boolean canBeUpgraded() { - return false; - } } diff --git a/src/main/java/techreborn/tiles/TileQuantumTank.java b/src/main/java/techreborn/tiles/TileQuantumTank.java index e03c34a54..03605d413 100644 --- a/src/main/java/techreborn/tiles/TileQuantumTank.java +++ b/src/main/java/techreborn/tiles/TileQuantumTank.java @@ -55,50 +55,62 @@ public class TileQuantumTank extends TileLegacyMachineBase @ConfigRegistry(config = "machines", category = "quantum_tank", key = "QuantumTankMaxStorage", comment = "Maximum amount of millibuckets a Quantum Tank can store") public static int maxStorage = Integer.MAX_VALUE; - // @ConfigRegistry(config = "machines", category = "quantum_tank", key = "QuantumTankWrenchDropRate", comment = "Quantum Tank Wrench Drop Rate") - public static float wrenchDropRate = 1.0F; public Tank tank = new Tank("TileQuantumTank", maxStorage, this); public Inventory inventory = new Inventory(3, "TileQuantumTank", 64, this); + public void readFromNBTWithoutCoords(final NBTTagCompound tagCompound) { + tank.readFromNBT(tagCompound); + } + + public NBTTagCompound writeToNBTWithoutCoords(final NBTTagCompound tagCompound) { + tank.writeToNBT(tagCompound); + return tagCompound; + } + + public ItemStack getDropWithNBT() { + final NBTTagCompound tileEntity = new NBTTagCompound(); + final ItemStack dropStack = new ItemStack(ModBlocks.QUANTUM_TANK, 1); + this.writeToNBTWithoutCoords(tileEntity); + dropStack.setTagCompound(new NBTTagCompound()); + dropStack.getTagCompound().setTag("tileEntity", tileEntity); + return dropStack; + } + + // TileLegacyMachineBase + @Override + public void update() { + super.update(); + if (!world.isRemote) { + if (FluidUtils.drainContainers(tank, inventory, 0, 1) + || FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluidType())) + this.syncWithAll(); + } + tank.compareAndUpdate(); + } + + @Override + public boolean canBeUpgraded() { + return false; + } + @Override public void readFromNBT(final NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); - this.readFromNBTWithoutCoords(tagCompound); - } - - public void readFromNBTWithoutCoords(final NBTTagCompound tagCompound) { - this.tank.readFromNBT(tagCompound); + readFromNBTWithoutCoords(tagCompound); } @Override public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); - this.writeToNBTWithoutCoords(tagCompound); - return tagCompound; - } - - public NBTTagCompound writeToNBTWithoutCoords(final NBTTagCompound tagCompound) { - this.tank.writeToNBT(tagCompound); + writeToNBTWithoutCoords(tagCompound); return tagCompound; } @Override public void onDataPacket(final NetworkManager net, final SPacketUpdateTileEntity packet) { - this.world.markBlockRangeForRenderUpdate(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), - this.getPos().getX(), this.getPos().getY(), this.getPos().getZ()); - this.readFromNBT(packet.getNbtCompound()); - } - - @Override - public void update() { - super.update(); - if (!this.world.isRemote) { - if (FluidUtils.drainContainers(this.tank, this.inventory, 0, 1) - || FluidUtils.fillContainers(this.tank, this.inventory, 0, 1, this.tank.getFluidType())) - this.syncWithAll(); - } - tank.compareAndUpdate(); + world.markBlockRangeForRenderUpdate(pos.getX(), pos.getY(), pos.getZ(), pos.getX(), pos.getY(), pos.getZ()); + readFromNBT(packet.getNbtCompound()); } @Override @@ -117,20 +129,19 @@ public class TileQuantumTank extends TileLegacyMachineBase return super.getCapability(capability, facing); } + // IInventoryProvider + @Override + public Inventory getInventory() { + return this.inventory; + } + + // IToolDrop @Override public ItemStack getToolDrop(final EntityPlayer entityPlayer) { return this.getDropWithNBT(); } - - public ItemStack getDropWithNBT() { - final NBTTagCompound tileEntity = new NBTTagCompound(); - final ItemStack dropStack = new ItemStack(ModBlocks.QUANTUM_TANK, 1); - this.writeToNBTWithoutCoords(tileEntity); - dropStack.setTagCompound(new NBTTagCompound()); - dropStack.getTagCompound().setTag("tileEntity", tileEntity); - return dropStack; - } - + + // IListInfoProvider @Override public void addInfo(final List info, final boolean isRealTile) { if (isRealTile) { @@ -141,23 +152,13 @@ public class TileQuantumTank extends TileLegacyMachineBase } } info.add("Capacity " + this.tank.getCapacity() + " mb"); - - } - - @Override - public Inventory getInventory() { - return this.inventory; } + // IContainerProvider @Override public BuiltContainer createContainer(final EntityPlayer player) { return new ContainerBuilder("quantumtank").player(player.inventory).inventory().hotbar() .addInventory().tile(this).fluidSlot(0, 80, 17).outputSlot(1, 80, 53).addInventory() .create(this); } - - @Override - public boolean canBeUpgraded() { - return false; - } } diff --git a/src/main/java/techreborn/tiles/TileTechStorageBase.java b/src/main/java/techreborn/tiles/TileTechStorageBase.java index 0e6816f51..f0fca398f 100644 --- a/src/main/java/techreborn/tiles/TileTechStorageBase.java +++ b/src/main/java/techreborn/tiles/TileTechStorageBase.java @@ -44,8 +44,10 @@ import reborncore.common.util.ItemUtils; import java.util.ArrayList; import java.util.List; +import javax.annotation.Nullable; + public class TileTechStorageBase extends TileLegacyMachineBase - implements IInventoryProvider, IToolDrop, IListInfoProvider, IDeepStorageUnit { + implements IInventoryProvider, IToolDrop, IListInfoProvider, IDeepStorageUnit { public final int maxCapacity; public final Inventory inventory; @@ -57,148 +59,153 @@ public class TileTechStorageBase extends TileLegacyMachineBase storedItem = ItemStack.EMPTY; inventory = new Inventory(3, name, maxCapacity, this); } - + public void readFromNBTWithoutCoords(NBTTagCompound tagCompound) { storedItem = ItemStack.EMPTY; if (tagCompound.hasKey("storedStack")) { - this.storedItem = new ItemStack((NBTTagCompound) tagCompound.getTag("storedStack")); + storedItem = new ItemStack((NBTTagCompound) tagCompound.getTag("storedStack")); } - if (!this.storedItem.isEmpty()) { - this.storedItem.setCount(Math.min(tagCompound.getInteger("storedQuantity"), this.maxCapacity)); + if (!storedItem.isEmpty()) { + storedItem.setCount(Math.min(tagCompound.getInteger("storedQuantity"), this.maxCapacity)); } inventory.readFromNBT(tagCompound); } - + public NBTTagCompound writeToNBTWithoutCoords(NBTTagCompound tagCompound) { - if (!this.storedItem.isEmpty()) { - ItemStack temp = this.storedItem.copy(); - if (this.storedItem.getCount() > storedItem.getMaxStackSize()){ + if (!storedItem.isEmpty()) { + ItemStack temp = storedItem.copy(); + if (storedItem.getCount() > storedItem.getMaxStackSize()) { temp.setCount(storedItem.getMaxStackSize()); } tagCompound.setTag("storedStack", temp.writeToNBT(new NBTTagCompound())); - tagCompound.setInteger("storedQuantity", Math.min(this.storedItem.getCount(), this.maxCapacity)); + tagCompound.setInteger("storedQuantity", Math.min(storedItem.getCount(), maxCapacity)); } else { tagCompound.setInteger("storedQuantity", 0); } inventory.writeToNBT(tagCompound); return tagCompound; } - + public ItemStack getDropWithNBT() { NBTTagCompound tileEntity = new NBTTagCompound(); - ItemStack dropStack = new ItemStack(this.getBlockType(), 1); + ItemStack dropStack = new ItemStack(getBlockType(), 1); writeToNBTWithoutCoords(tileEntity); dropStack.setTagCompound(new NBTTagCompound()); dropStack.getTagCompound().setTag("tileEntity", tileEntity); - this.storedItem.setCount(0); + storedItem.setCount(0); setInventorySlotContents(1, ItemStack.EMPTY); syncWithAll(); - + return dropStack; } - + public InvWrapper getInvWrapper() { - if (this.invWrapper == null) - this.invWrapper = new InvWrapper(this); - return this.invWrapper; + if (invWrapper == null) + invWrapper = new InvWrapper(this); + return invWrapper; } - + public int getStoredCount() { - return this.storedItem.getCount(); + return storedItem.getCount(); } - + public List getContentDrops() { ArrayList stacks = new ArrayList<>(); - if (!this.getStoredItemType().isEmpty()) { - if (!this.getStackInSlot(1).isEmpty()) { - stacks.add(this.getStackInSlot(1)); + if (!getStoredItemType().isEmpty()) { + if (!getStackInSlot(1).isEmpty()) { + stacks.add(getStackInSlot(1)); } - for (int i = 0; i < this.getStoredCount() / 64; i++) { - ItemStack droped = this.storedItem.copy(); + for (int i = 0; i < getStoredCount() / 64; i++) { + ItemStack droped = storedItem.copy(); droped.setCount(64); stacks.add(droped); } - if (this.getStoredCount() % 64 != 0) { - ItemStack droped = this.storedItem.copy(); - droped.setCount(this.getStoredCount() % 64); + if (getStoredCount() % 64 != 0) { + ItemStack droped = storedItem.copy(); + droped.setCount(getStoredCount() % 64); stacks.add(droped); } } return stacks; } - + // TileLegacyMachineBase @Override public void update() { super.update(); if (!world.isRemote) { ItemStack outputStack = ItemStack.EMPTY; - if (!this.getStackInSlot(1).isEmpty()){ - outputStack = this.getStackInSlot(1); + if (!getStackInSlot(1).isEmpty()) { + outputStack = 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(inputStack, outputStack, true, true))) { + if (getStackInSlot(0) != ItemStack.EMPTY + && (storedItem.getCount() + outputStack.getCount()) < maxCapacity) { + ItemStack inputStack = getStackInSlot(0); + if (getStoredItemType().isEmpty() + || (storedItem.isEmpty() && ItemUtils.isItemEqual(inputStack, outputStack, true, true))) { - this.storedItem = inputStack; - this.setInventorySlotContents(0, ItemStack.EMPTY); - } else if (ItemUtils.isItemEqual(this.getStoredItemType(), inputStack, true, true)) { - int reminder = this.maxCapacity - this.storedItem.getCount() - outputStack.getCount(); + storedItem = inputStack; + setInventorySlotContents(0, ItemStack.EMPTY); + } else if (ItemUtils.isItemEqual(getStoredItemType(), inputStack, true, true)) { + int reminder = maxCapacity - storedItem.getCount() - outputStack.getCount(); if (inputStack.getCount() <= reminder) { - this.setStoredItemCount(inputStack.getCount()); - this.setInventorySlotContents(0, ItemStack.EMPTY); + setStoredItemCount(inputStack.getCount()); + setInventorySlotContents(0, ItemStack.EMPTY); } else { - this.setStoredItemCount(this.maxCapacity - outputStack.getCount()); - this.getStackInSlot(0).shrink(reminder); + setStoredItemCount(maxCapacity - outputStack.getCount()); + getStackInSlot(0).shrink(reminder); } } - this.markDirty(); - this.syncWithAll(); + markDirty(); + syncWithAll(); } - if (!this.storedItem.isEmpty()) { + if (!storedItem.isEmpty()) { if (outputStack == ItemStack.EMPTY) { - ItemStack delivered = this.storedItem.copy(); - delivered.setCount(Math.min(this.storedItem.getCount(), delivered.getMaxStackSize())); - this.storedItem.shrink(delivered.getCount()); + ItemStack delivered = storedItem.copy(); + delivered.setCount(Math.min(storedItem.getCount(), delivered.getMaxStackSize())); + storedItem.shrink(delivered.getCount()); - if (this.storedItem.isEmpty()) - this.storedItem = ItemStack.EMPTY; + if (storedItem.isEmpty()) { + storedItem = ItemStack.EMPTY; + } - this.setInventorySlotContents(1, delivered); - this.markDirty(); - this.syncWithAll(); - } else if (ItemUtils.isItemEqual(this.storedItem, outputStack, true, true) - && outputStack.getCount() < outputStack.getMaxStackSize()) { + setInventorySlotContents(1, delivered); + markDirty(); + syncWithAll(); + } else if (ItemUtils.isItemEqual(storedItem, outputStack, true, true) + && outputStack.getCount() < outputStack.getMaxStackSize()) { - int wanted = Math.min(this.storedItem.getCount(), + int wanted = Math.min(storedItem.getCount(), outputStack.getMaxStackSize() - outputStack.getCount()); - outputStack.setCount(outputStack.getCount() + wanted); - this.storedItem.shrink(wanted); + storedItem.shrink(wanted); - if (this.storedItem.isEmpty()) - this.storedItem = ItemStack.EMPTY; - this.markDirty(); - this.syncWithAll(); + if (storedItem.isEmpty()) { + storedItem = ItemStack.EMPTY; + } + markDirty(); + syncWithAll(); } } } } + @Override + public boolean canBeUpgraded() { + return false; + } + @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) { - world.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(), - getPos().getY(), getPos().getZ()); + world.markBlockRangeForRenderUpdate(pos.getX(), pos.getY(), pos.getZ(), pos.getX(), pos.getY(), pos.getZ()); readFromNBT(packet.getNbtCompound()); } @@ -214,9 +221,9 @@ public class TileTechStorageBase extends TileLegacyMachineBase writeToNBTWithoutCoords(tagCompound); return tagCompound; } - + @Override - public T getCapability(final Capability capability, final EnumFacing facing) { + public T getCapability(Capability capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(getInvWrapper()); } @@ -224,18 +231,16 @@ public class TileTechStorageBase extends TileLegacyMachineBase } @Override - public boolean hasCapability(final net.minecraftforge.common.capabilities.Capability capability, - @javax.annotation.Nullable - final net.minecraft.util.EnumFacing facing) { + public boolean hasCapability(Capability capability, @Nullable EnumFacing facing) { return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing); } // IInventoryProvider @Override public Inventory getInventory() { - return this.inventory; + return inventory; } - + // IToolDrop @Override public ItemStack getToolDrop(EntityPlayer entityPlayer) { @@ -263,24 +268,24 @@ public class TileTechStorageBase extends TileLegacyMachineBase // IDeepStorageUnit @Override public ItemStack getStoredItemType() { - return this.storedItem.isEmpty() ? this.getStackInSlot(1) : this.storedItem; + return storedItem.isEmpty() ? getStackInSlot(1) : storedItem; } @Override public void setStoredItemCount(int amount) { storedItem.grow(amount); - this.markDirty(); + markDirty(); } @Override public void setStoredItemType(ItemStack type, int amount) { - this.storedItem = type; + storedItem = type; storedItem.setCount(amount); - this.markDirty(); + markDirty(); } @Override public int getMaxStoredCount() { - return this.maxCapacity; + return maxCapacity; } } diff --git a/src/main/java/techreborn/tiles/generator/TileBaseFluidGenerator.java b/src/main/java/techreborn/tiles/generator/TileBaseFluidGenerator.java index 132067d77..65fd22233 100644 --- a/src/main/java/techreborn/tiles/generator/TileBaseFluidGenerator.java +++ b/src/main/java/techreborn/tiles/generator/TileBaseFluidGenerator.java @@ -70,7 +70,7 @@ public abstract class TileBaseFluidGenerator extends TilePowerAcceptor implement @Override public void update() { super.update(); - this.ticksSinceLastChange++; + ticksSinceLastChange++; if(world.isRemote){ return; @@ -78,56 +78,56 @@ public abstract class TileBaseFluidGenerator extends TilePowerAcceptor implement // Check cells input slot 2 time per second // Please, keep ticks counting on client also to report progress to GUI - if (this.ticksSinceLastChange >= 10) { - if (!this.inventory.getStackInSlot(0).isEmpty()) { - FluidUtils.drainContainers(this.tank, this.inventory, 0, 1); - FluidUtils.fillContainers(this.tank, this.inventory, 0, 1, this.tank.getFluidType()); + if (ticksSinceLastChange >= 10) { + if (!inventory.getStackInSlot(0).isEmpty()) { + FluidUtils.drainContainers(tank, inventory, 0, 1); + FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluidType()); } tank.setTileEntity(this); tank.compareAndUpdate(); - this.ticksSinceLastChange = 0; + ticksSinceLastChange = 0; } - if (this.tank.getFluidAmount() > 0) { - if (this.currentRecipe == null || !this.currentRecipe.getFluid().equals(this.tank.getFluidType())) - this.currentRecipe = this.getRecipes().getRecipeForFluid(this.tank.getFluidType()).orElse(null); + if (tank.getFluidAmount() > 0) { + if (currentRecipe == null || !currentRecipe.getFluid().equals(tank.getFluidType())) + currentRecipe = getRecipes().getRecipeForFluid(tank.getFluidType()).orElse(null); - if (this.currentRecipe != null) { - final Integer euPerBucket = this.currentRecipe.getEnergyPerMb() * 1000; - final float millibucketsPerTick = this.euTick * 1000 / (float) euPerBucket; + if (currentRecipe != null) { + final Integer euPerBucket = currentRecipe.getEnergyPerMb() * 1000; + final float millibucketsPerTick = euTick * 1000 / (float) euPerBucket; - if (this.tryAddingEnergy(this.euTick)) { - this.pendingWithdraw += millibucketsPerTick; - final int currentWithdraw = (int) this.pendingWithdraw; - this.pendingWithdraw -= currentWithdraw; - this.tank.drain(currentWithdraw, true); - this.lastOutput = this.world.getTotalWorldTime(); + if (tryAddingEnergy(euTick)) { + pendingWithdraw += millibucketsPerTick; + final int currentWithdraw = (int) pendingWithdraw; + pendingWithdraw -= currentWithdraw; + tank.drain(currentWithdraw, true); + lastOutput = world.getTotalWorldTime(); } } } - if (this.world.getTotalWorldTime() - this.lastOutput < 30 && !this.isActive()) - this.world.setBlockState(this.getPos(), this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true)); - else if (this.world.getTotalWorldTime() - this.lastOutput > 30 && this.isActive()) - this.world.setBlockState(this.getPos(), this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false)); - - + if (world.getTotalWorldTime() - lastOutput < 30 && !isActive()) { + world.setBlockState(pos, world.getBlockState(pos).withProperty(BlockMachineBase.ACTIVE, true)); + } + else if (world.getTotalWorldTime() - lastOutput > 30 && isActive()) { + world.setBlockState(pos, world.getBlockState(pos).withProperty(BlockMachineBase.ACTIVE, false)); + } } - public int getProgressScaled(final int scale) { - if (this.isActive()){ - return this.ticksSinceLastChange * scale; + public int getProgressScaled(int scale) { + if (isActive()){ + return ticksSinceLastChange * scale; } return 0; } protected boolean tryAddingEnergy(int amount) { - if (this.getMaxPower() - this.getEnergy() >= amount) { + if (getMaxPower() - getEnergy() >= amount) { addEnergy(amount); return true; - } else if (this.getMaxPower() - this.getEnergy() > 0) { - addEnergy(this.getMaxPower() - this.getEnergy()); + } else if (getMaxPower() - getEnergy() > 0) { + addEnergy(getMaxPower() - getEnergy()); return true; } @@ -135,8 +135,8 @@ public abstract class TileBaseFluidGenerator extends TilePowerAcceptor implement } protected boolean acceptFluid() { - if (!this.getStackInSlot(0).isEmpty()) { - FluidStack stack = FluidUtils.getFluidStackInContainer(this.getStackInSlot(0)); + if (!getStackInSlot(0).isEmpty()) { + FluidStack stack = FluidUtils.getFluidStackInContainer(getStackInSlot(0)); if (stack != null) return recipes.getRecipeForFluid(stack.getFluid()).isPresent(); } diff --git a/src/main/java/techreborn/tiles/generator/TileCreativeSolarPanel.java b/src/main/java/techreborn/tiles/generator/TileCreativeSolarPanel.java index 4f1d1dd4c..a422e51ac 100644 --- a/src/main/java/techreborn/tiles/generator/TileCreativeSolarPanel.java +++ b/src/main/java/techreborn/tiles/generator/TileCreativeSolarPanel.java @@ -48,7 +48,7 @@ public class TileCreativeSolarPanel extends TilePowerAcceptor implements IToolDr @Override public void update() { super.update(); - this.setEnergy(getMaxPower()); + setEnergy(getMaxPower()); } @Override @@ -58,7 +58,7 @@ public class TileCreativeSolarPanel extends TilePowerAcceptor implements IToolDr @Override public double getBaseMaxPower() { - return 1000000; + return 1_000_000; } @Override @@ -73,7 +73,7 @@ public class TileCreativeSolarPanel extends TilePowerAcceptor implements IToolDr @Override public double getBaseMaxOutput() { - return 16192; + return 16_192; } @Override diff --git a/src/main/java/techreborn/tiles/generator/TileDragonEggSyphon.java b/src/main/java/techreborn/tiles/generator/TileDragonEggSyphon.java index f77db2b1c..11a9099d9 100644 --- a/src/main/java/techreborn/tiles/generator/TileDragonEggSyphon.java +++ b/src/main/java/techreborn/tiles/generator/TileDragonEggSyphon.java @@ -40,7 +40,8 @@ import techreborn.init.ModBlocks; import techreborn.lib.ModInfo; @RebornRegistry(modID = ModInfo.MOD_ID) -public class TileDragonEggSyphon extends TilePowerAcceptor implements IToolDrop, IInventoryProvider { +public class TileDragonEggSyphon extends TilePowerAcceptor + implements IToolDrop, IInventoryProvider { @ConfigRegistry(config = "generators", category = "dragon_egg_siphoner", key = "DragonEggSiphonerMaxOutput", comment = "Dragon Egg Siphoner Max Output (Value in EU)") public static int maxOutput = 128; @@ -55,27 +56,7 @@ public class TileDragonEggSyphon extends TilePowerAcceptor implements IToolDrop, public TileDragonEggSyphon() { super(); } - - @Override - public void update() { - super.update(); - - if (!world.isRemote) { - if (world.getBlockState(new BlockPos(getPos().getX(), getPos().getY() + 1, getPos().getZ())) - .getBlock() == Blocks.DRAGON_EGG) { - if (tryAddingEnergy(energyPerTick)) - this.lastOutput = this.world.getTotalWorldTime(); - } - - if (this.world.getTotalWorldTime() - this.lastOutput < 30 && !this.isActive()) - this.world.setBlockState(this.getPos(), - this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true)); - else if (this.world.getTotalWorldTime() - this.lastOutput > 30 && this.isActive()) - this.world.setBlockState(this.getPos(), - this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false)); - } - } - + private boolean tryAddingEnergy(int amount) { if (this.getMaxPower() - this.getEnergy() >= amount) { addEnergy(amount); @@ -86,14 +67,25 @@ public class TileDragonEggSyphon extends TilePowerAcceptor implements IToolDrop, } return false; } - + + // TilePowerAcceptor @Override - public ItemStack getToolDrop(EntityPlayer entityPlayer) { - return new ItemStack(ModBlocks.DRAGON_EGG_SYPHON, 1); - } + public void update() { + super.update(); - public boolean isComplete() { - return false; + if (!world.isRemote) { + if (world.getBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ())) + .getBlock() == Blocks.DRAGON_EGG) { + if (tryAddingEnergy(energyPerTick)) + lastOutput = world.getTotalWorldTime(); + } + + if (world.getTotalWorldTime() - lastOutput < 30 && !isActive()) { + world.setBlockState(pos, world.getBlockState(pos).withProperty(BlockMachineBase.ACTIVE, true)); + } else if (world.getTotalWorldTime() - lastOutput > 30 && isActive()) { + world.setBlockState(pos, world.getBlockState(pos).withProperty(BlockMachineBase.ACTIVE, false)); + } + } } @Override @@ -120,7 +112,14 @@ public class TileDragonEggSyphon extends TilePowerAcceptor implements IToolDrop, public double getBaseMaxInput() { return 0; } + + // IToolDrop + @Override + public ItemStack getToolDrop(EntityPlayer entityPlayer) { + return new ItemStack(ModBlocks.DRAGON_EGG_SYPHON, 1); + } + // IInventoryProvider @Override public Inventory getInventory() { return inventory; diff --git a/src/main/java/techreborn/tiles/idsu/TileInterdimensionalSU.java b/src/main/java/techreborn/tiles/idsu/TileInterdimensionalSU.java index 38d22e3e6..f2e08cebc 100644 --- a/src/main/java/techreborn/tiles/idsu/TileInterdimensionalSU.java +++ b/src/main/java/techreborn/tiles/idsu/TileInterdimensionalSU.java @@ -45,7 +45,7 @@ public class TileInterdimensionalSU extends TileEnergyStorage implements IContai @ConfigRegistry(config = "machines", category = "idsu", key = "IdsuMaxOutput", comment = "IDSU Max Output (Value in EU)") public static int maxOutput = 8192; @ConfigRegistry(config = "machines", category = "idsu", key = "IdsuMaxEnergy", comment = "IDSU Max Energy (Value in EU)") - public static int maxEnergy = 100000000; + public static int maxEnergy = 100_000_000; public String ownerUdid; diff --git a/src/main/java/techreborn/tiles/lesu/TileLSUStorage.java b/src/main/java/techreborn/tiles/lesu/TileLSUStorage.java index cd5e9a6bc..61f87f8dc 100644 --- a/src/main/java/techreborn/tiles/lesu/TileLSUStorage.java +++ b/src/main/java/techreborn/tiles/lesu/TileLSUStorage.java @@ -72,9 +72,9 @@ public class TileLSUStorage extends TileLegacyMachineBase } public final void rebuildNetwork() { - this.removeFromNetwork(); - this.resetNetwork(); - this.findAndJoinNetwork(world, getPos().getX(), getPos().getY(), getPos().getZ()); + removeFromNetwork(); + resetNetwork(); + findAndJoinNetwork(world, pos.getX(), pos.getY(), pos.getZ()); } // TileLegacyMachineBase @@ -82,7 +82,7 @@ public class TileLSUStorage extends TileLegacyMachineBase public void update() { super.update(); if (network == null) { - findAndJoinNetwork(world, getPos().getX(), getPos().getY(), getPos().getZ()); + findAndJoinNetwork(world, pos.getX(), pos.getY(), pos.getZ()); } else { if (network.master != null && network.master.getWorld().getTileEntity(new BlockPos(network.master.getPos().getX(), @@ -94,7 +94,7 @@ public class TileLSUStorage extends TileLegacyMachineBase // IToolDrop @Override - public ItemStack getToolDrop(final EntityPlayer entityPlayer) { + public ItemStack getToolDrop(EntityPlayer entityPlayer) { return new ItemStack(ModBlocks.LSU_STORAGE, 1); } } diff --git a/src/main/java/techreborn/tiles/lesu/TileLapotronicSU.java b/src/main/java/techreborn/tiles/lesu/TileLapotronicSU.java index b97cc5b3c..567e3eff2 100644 --- a/src/main/java/techreborn/tiles/lesu/TileLapotronicSU.java +++ b/src/main/java/techreborn/tiles/lesu/TileLapotronicSU.java @@ -26,6 +26,7 @@ package techreborn.tiles.lesu; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import reborncore.api.power.EnumPowerTier; @@ -50,7 +51,7 @@ public class TileLapotronicSU extends TileEnergyStorage implements IContainerPro @ConfigRegistry(config = "machines", category = "lesu", key = "LesuMaxOutput", comment = "LESU Base Output (Value in EU)") public static int baseOutput = 16; @ConfigRegistry(config = "machines", category = "lesu", key = "LesuMaxEnergyPerBlock", comment = "LESU Max Energy Per Block (Value in EU)") - public static int storagePerBlock = 1000000; + public static int storagePerBlock = 1_000_000; @ConfigRegistry(config = "machines", category = "lesu", key = "LesuExtraIO", comment = "LESU Extra I/O Multiplier") public static int extraIOPerBlock = 8; @@ -58,7 +59,7 @@ public class TileLapotronicSU extends TileEnergyStorage implements IContainerPro private ArrayList countedNetworks = new ArrayList<>(); public TileLapotronicSU() { - super("LESU", 2, ModBlocks.LAPOTRONIC_SU, EnumPowerTier.INSANE, 8192, baseOutput, 1000000); + super("LESU", 2, ModBlocks.LAPOTRONIC_SU, EnumPowerTier.INSANE, 8192, baseOutput, 1_000_000); checkOverfill = false; } @@ -71,28 +72,28 @@ public class TileLapotronicSU extends TileEnergyStorage implements IContainerPro countedNetworks.clear(); connectedBlocks = 0; for (EnumFacing dir : EnumFacing.values()) { - if (world.getTileEntity( - new BlockPos(getPos().getX() + dir.getFrontOffsetX(), getPos().getY() + dir.getFrontOffsetY(), - getPos().getZ() + dir.getFrontOffsetZ())) instanceof TileLSUStorage) { - if (((TileLSUStorage) world.getTileEntity( - new BlockPos(getPos().getX() + dir.getFrontOffsetX(), getPos().getY() + dir.getFrontOffsetY(), - getPos().getZ() + dir.getFrontOffsetZ()))).network != null) { - LesuNetwork network = ((TileLSUStorage) world.getTileEntity(new BlockPos( - getPos().getX() + dir.getFrontOffsetX(), getPos().getY() + dir.getFrontOffsetY(), - getPos().getZ() + dir.getFrontOffsetZ()))).network; - if (!countedNetworks.contains(network)) { - if (network.master == null || network.master == this) { - connectedBlocks += network.storages.size(); - countedNetworks.add(network); - network.master = this; - break; - } - } + BlockPos adjucentBlockPos = new BlockPos(pos.getX() + dir.getFrontOffsetX(), + pos.getY() + dir.getFrontOffsetY(), pos.getZ() + dir.getFrontOffsetZ()); + TileEntity adjucentTile = world.getTileEntity(adjucentBlockPos); + if (adjucentTile == null || !(adjucentTile instanceof TileLSUStorage)) { + continue; + } + if (((TileLSUStorage) adjucentTile).network == null) { + continue; + } + LesuNetwork network = ((TileLSUStorage) adjucentTile).network; + if (!countedNetworks.contains(network)) { + if (network.master == null || network.master == this) { + connectedBlocks += network.storages.size(); + countedNetworks.add(network); + network.master = this; + break; } } + } setMaxStorage(); - this.maxOutput = (connectedBlocks * extraIOPerBlock) + baseOutput; + maxOutput = (connectedBlocks * extraIOPerBlock) + baseOutput; } @Override @@ -105,7 +106,7 @@ public class TileLapotronicSU extends TileEnergyStorage implements IContainerPro } public int getOutputRate() { - return this.maxOutput; + return maxOutput; } public void setOutputRate(int output) { @@ -113,7 +114,7 @@ public class TileLapotronicSU extends TileEnergyStorage implements IContainerPro } public int getConnectedBlocksNum() { - return this.connectedBlocks; + return connectedBlocks; } public void setConnectedBlocksNum(int value) { @@ -124,9 +125,9 @@ public class TileLapotronicSU extends TileEnergyStorage implements IContainerPro } public void setMaxStorage(){ - this.maxStorage = (this.connectedBlocks + 1) * storagePerBlock; - if (this.maxStorage < 0 || this.maxStorage > Integer.MAX_VALUE / RebornCoreConfig.euPerFU) { - this.maxStorage = Integer.MAX_VALUE / RebornCoreConfig.euPerFU; + maxStorage = (connectedBlocks + 1) * storagePerBlock; + if (maxStorage < 0 || maxStorage > Integer.MAX_VALUE / RebornCoreConfig.euPerFU) { + maxStorage = Integer.MAX_VALUE / RebornCoreConfig.euPerFU; } } diff --git a/src/main/java/techreborn/tiles/lighting/TileLamp.java b/src/main/java/techreborn/tiles/lighting/TileLamp.java index ec87e504b..ce0e25581 100644 --- a/src/main/java/techreborn/tiles/lighting/TileLamp.java +++ b/src/main/java/techreborn/tiles/lighting/TileLamp.java @@ -42,20 +42,21 @@ public class TileLamp extends TilePowerAcceptor @Override public void update() { super.update(); - if (world != null && !world.isRemote) { - IBlockState state = world.getBlockState(pos); - Block b = state.getBlock(); - if (b instanceof BlockLamp) { - double cost = getEuPerTick(((BlockLamp)b).getCost()); - if (this.getEnergy() > cost) { - useEnergy(getEuPerTick(cost)); - if (!BlockLamp.isActive(state)) - BlockLamp.setActive(true, world, pos); - } else if (BlockLamp.isActive(state)) { - BlockLamp.setActive(false, world, pos); - } - } + if (world == null || world.isRemote) { + return; } + IBlockState state = world.getBlockState(pos); + Block b = state.getBlock(); + if (b instanceof BlockLamp) { + double cost = getEuPerTick(((BlockLamp) b).getCost()); + if (getEnergy() > cost) { + useEnergy(getEuPerTick(cost)); + if (!BlockLamp.isActive(state)) + BlockLamp.setActive(true, world, pos); + } else if (BlockLamp.isActive(state)) { + BlockLamp.setActive(false, world, pos); + } + } } @Override diff --git a/src/main/java/techreborn/tiles/multiblock/TileDistillationTower.java b/src/main/java/techreborn/tiles/multiblock/TileDistillationTower.java index f80202cb2..831bac056 100644 --- a/src/main/java/techreborn/tiles/multiblock/TileDistillationTower.java +++ b/src/main/java/techreborn/tiles/multiblock/TileDistillationTower.java @@ -59,15 +59,15 @@ public class TileDistillationTower extends TileGenericMachine implements IContai } public boolean getMutliBlock() { - if (this.multiblockChecker == null) { + if (multiblockChecker == null) { return false; } - final boolean layer0 = this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, MultiblockChecker.ZERO_OFFSET); - final boolean layer1 = this.multiblockChecker.checkRingY(1, 1, MultiblockChecker.ADVANCED_CASING, new BlockPos(0, 1, 0)); - final boolean layer2 = this.multiblockChecker.checkRingY(1, 1, MultiblockChecker.STANDARD_CASING, new BlockPos(0, 2, 0)); - final boolean layer3 = this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.ADVANCED_CASING, new BlockPos(0, 3, 0)); - final Block centerBlock1 = this.multiblockChecker.getBlock(0, 1, 0).getBlock(); - final Block centerBlock2 = this.multiblockChecker.getBlock(0, 2, 0).getBlock(); + final boolean layer0 = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, MultiblockChecker.ZERO_OFFSET); + final boolean layer1 = multiblockChecker.checkRingY(1, 1, MultiblockChecker.ADVANCED_CASING, new BlockPos(0, 1, 0)); + final boolean layer2 = multiblockChecker.checkRingY(1, 1, MultiblockChecker.STANDARD_CASING, new BlockPos(0, 2, 0)); + final boolean layer3 = multiblockChecker.checkRectY(1, 1, MultiblockChecker.ADVANCED_CASING, new BlockPos(0, 3, 0)); + final Block centerBlock1 = multiblockChecker.getBlock(0, 1, 0).getBlock(); + final Block centerBlock2 = multiblockChecker.getBlock(0, 2, 0).getBlock(); final boolean center1 = (centerBlock1 == Blocks.AIR); final boolean center2 = (centerBlock2 == Blocks.AIR); return layer0 && layer1 && layer2 && layer3 && center1 && center2; @@ -76,9 +76,9 @@ public class TileDistillationTower extends TileGenericMachine implements IContai // TileGenericMachine @Override public void update() { - if (this.multiblockChecker == null) { - final BlockPos pos = this.getPos().offset(this.getFacing().getOpposite(), 2); - this.multiblockChecker = new MultiblockChecker(this.world, pos); + if (multiblockChecker == null) { + final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2); + multiblockChecker = new MultiblockChecker(world, downCenter); } if (!world.isRemote && getMutliBlock()){ diff --git a/src/main/java/techreborn/tiles/multiblock/TileFluidReplicator.java b/src/main/java/techreborn/tiles/multiblock/TileFluidReplicator.java index 858e8bcc0..3a6097845 100644 --- a/src/main/java/techreborn/tiles/multiblock/TileFluidReplicator.java +++ b/src/main/java/techreborn/tiles/multiblock/TileFluidReplicator.java @@ -85,8 +85,8 @@ public class TileFluidReplicator extends TileGenericMachine implements IContaine @Override public void update() { if (multiblockChecker == null) { - final BlockPos pos = getPos().offset(getFacing().getOpposite(), 2); - multiblockChecker = new MultiblockChecker(this.world, pos); + final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2); + multiblockChecker = new MultiblockChecker(world, downCenter); } ticksSinceLastChange++; diff --git a/src/main/java/techreborn/tiles/multiblock/TileImplosionCompressor.java b/src/main/java/techreborn/tiles/multiblock/TileImplosionCompressor.java index 0630590cf..bd321d29f 100644 --- a/src/main/java/techreborn/tiles/multiblock/TileImplosionCompressor.java +++ b/src/main/java/techreborn/tiles/multiblock/TileImplosionCompressor.java @@ -57,18 +57,18 @@ public class TileImplosionCompressor extends TileGenericMachine implements ICont } public boolean getMutliBlock() { - final boolean down = this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.REINFORCED_CASING, MultiblockChecker.ZERO_OFFSET); - final boolean up = this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.REINFORCED_CASING, new BlockPos(0, 2, 0)); - final boolean chamber = this.multiblockChecker.checkRingYHollow(1, 1, MultiblockChecker.REINFORCED_CASING, new BlockPos(0, 1, 0)); + final boolean down = multiblockChecker.checkRectY(1, 1, MultiblockChecker.REINFORCED_CASING, MultiblockChecker.ZERO_OFFSET); + final boolean up = multiblockChecker.checkRectY(1, 1, MultiblockChecker.REINFORCED_CASING, new BlockPos(0, 2, 0)); + final boolean chamber = multiblockChecker.checkRingYHollow(1, 1, MultiblockChecker.REINFORCED_CASING, new BlockPos(0, 1, 0)); return down && chamber && up; } // TileGenericMachine @Override public void update() { - if (this.multiblockChecker == null) { - final BlockPos pos = this.getPos().offset(this.getFacing().getOpposite(), 2); - this.multiblockChecker = new MultiblockChecker(this.world, pos); + if (multiblockChecker == null) { + final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2); + multiblockChecker = new MultiblockChecker(world, downCenter); } if (!world.isRemote && getMutliBlock()){ @@ -80,7 +80,7 @@ public class TileImplosionCompressor extends TileGenericMachine implements ICont @Override public void validate() { super.validate(); - this.multiblockChecker = new MultiblockChecker(this.world, this.getPos().down(3)); + multiblockChecker = new MultiblockChecker(world, pos.down(3)); } // IContainerProvider diff --git a/src/main/java/techreborn/tiles/multiblock/TileIndustrialBlastFurnace.java b/src/main/java/techreborn/tiles/multiblock/TileIndustrialBlastFurnace.java index b202046fc..011f59d78 100644 --- a/src/main/java/techreborn/tiles/multiblock/TileIndustrialBlastFurnace.java +++ b/src/main/java/techreborn/tiles/multiblock/TileIndustrialBlastFurnace.java @@ -70,13 +70,13 @@ public class TileIndustrialBlastFurnace extends TileGenericMachine implements IC } public int getHeat() { - if (!this.getMutliBlock()){ + if (!getMutliBlock()){ return 0; } // Bottom center of multiblock - final BlockPos location = this.getPos().offset(this.getFacing().getOpposite(), 2); - final TileEntity tileEntity = this.world.getTileEntity(location); + final BlockPos location = pos.offset(getFacing().getOpposite(), 2); + final TileEntity tileEntity = world.getTileEntity(location); if (tileEntity instanceof TileMachineCasing) { if (((TileMachineCasing) tileEntity).isConnected() @@ -86,21 +86,18 @@ public class TileIndustrialBlastFurnace extends TileGenericMachine implements IC int heat = 0; // Bottom center shouldn't have any tile entities below it - if (this.world.getBlockState(new BlockPos(location.getX(), location.getY() - 1, location.getZ())) + if (world.getBlockState(new BlockPos(location.getX(), location.getY() - 1, location.getZ())) .getBlock() == tileEntity.getBlockType()) { return 0; } for (final IMultiblockPart part : casing.connectedParts) { - final BlockMachineCasing casing1 = (BlockMachineCasing) this.world.getBlockState(part.getPos()) - .getBlock(); - heat += casing1.getHeatFromState(this.world.getBlockState(part.getPos())); + final BlockMachineCasing casing1 = (BlockMachineCasing) world.getBlockState(part.getPos()).getBlock(); + heat += casing1.getHeatFromState(world.getBlockState(part.getPos())); } - if (this.world.getBlockState(location.offset(EnumFacing.UP, 1)).getBlock().getUnlocalizedName() - .equals("tile.lava") - && this.world.getBlockState(location.offset(EnumFacing.UP, 2)).getBlock().getUnlocalizedName() - .equals("tile.lava")) { + if (world.getBlockState(location.offset(EnumFacing.UP, 1)).getBlock().getUnlocalizedName().equals("tile.lava") + && world.getBlockState(location.offset(EnumFacing.UP, 2)).getBlock().getUnlocalizedName().equals("tile.lava")) { heat += 500; } return heat; @@ -111,31 +108,31 @@ public class TileIndustrialBlastFurnace extends TileGenericMachine implements IC } public boolean getMutliBlock() { - final boolean layer0 = this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_ANY, MultiblockChecker.ZERO_OFFSET); - final boolean layer1 = this.multiblockChecker.checkRingY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 1, 0)); - final boolean layer2 = this.multiblockChecker.checkRingY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 2, 0)); - final boolean layer3 = this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 3, 0)); - final Block centerBlock1 = this.multiblockChecker.getBlock(0, 1, 0).getBlock(); - final Block centerBlock2 = this.multiblockChecker.getBlock(0, 2, 0).getBlock(); + final boolean layer0 = multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_ANY, MultiblockChecker.ZERO_OFFSET); + final boolean layer1 = multiblockChecker.checkRingY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 1, 0)); + final boolean layer2 = multiblockChecker.checkRingY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 2, 0)); + final boolean layer3 = multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 3, 0)); + final Block centerBlock1 = multiblockChecker.getBlock(0, 1, 0).getBlock(); + final Block centerBlock2 = multiblockChecker.getBlock(0, 2, 0).getBlock(); final boolean center1 = (centerBlock1 == Blocks.AIR || centerBlock1 == Blocks.LAVA); final boolean center2 = (centerBlock2 == Blocks.AIR || centerBlock2 == Blocks.LAVA); return layer0 && layer1 && layer2 && layer3 && center1 && center2; } public void setHeat(final int heat) { - this.cachedHeat = heat; + cachedHeat = heat; } public int getCachedHeat() { - return this.cachedHeat; + return cachedHeat; } // TileGenericMachine @Override public void update() { - if (this.multiblockChecker == null) { - final BlockPos pos = this.getPos().offset(this.getFacing().getOpposite(), 2); - this.multiblockChecker = new MultiblockChecker(this.world, pos); + if (multiblockChecker == null) { + final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2); + multiblockChecker = new MultiblockChecker(world, downCenter); } if (!world.isRemote && getMutliBlock()){ @@ -146,9 +143,8 @@ public class TileIndustrialBlastFurnace extends TileGenericMachine implements IC // TileLegacyMachineBase @Override public void onDataPacket(final NetworkManager net, final SPacketUpdateTileEntity packet) { - this.world.markBlockRangeForRenderUpdate(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), this.getPos().getX(), - this.getPos().getY(), this.getPos().getZ()); - this.readFromNBT(packet.getNbtCompound()); + world.markBlockRangeForRenderUpdate(pos.getX(), pos.getY(), pos.getZ(), pos.getX(), pos.getY(), pos.getZ()); + readFromNBT(packet.getNbtCompound()); } // IContainerProvider diff --git a/src/main/java/techreborn/tiles/multiblock/TileIndustrialGrinder.java b/src/main/java/techreborn/tiles/multiblock/TileIndustrialGrinder.java index 7a30d531d..b55167695 100644 --- a/src/main/java/techreborn/tiles/multiblock/TileIndustrialGrinder.java +++ b/src/main/java/techreborn/tiles/multiblock/TileIndustrialGrinder.java @@ -80,34 +80,32 @@ public class TileIndustrialGrinder extends TileGenericMachine implements IContai if (multiblockChecker == null) { return false; } - final boolean down = this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, - MultiblockChecker.ZERO_OFFSET); - final boolean up = this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, - new BlockPos(0, 2, 0)); - final boolean blade = this.multiblockChecker.checkRingY(1, 1, MultiblockChecker.REINFORCED_CASING, - new BlockPos(0, 1, 0)); - final IBlockState centerBlock = this.multiblockChecker.getBlock(0, 1, 0); + final boolean down = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, MultiblockChecker.ZERO_OFFSET); + final boolean up = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, new BlockPos(0, 2, 0)); + final boolean blade = multiblockChecker.checkRingY(1, 1, MultiblockChecker.REINFORCED_CASING, new BlockPos(0, 1, 0)); + final IBlockState centerBlock = multiblockChecker.getBlock(0, 1, 0); final boolean center = ((centerBlock.getBlock() instanceof BlockLiquid - || centerBlock.getBlock() instanceof IFluidBlock) && centerBlock.getMaterial() == Material.WATER); + || centerBlock.getBlock() instanceof IFluidBlock) + && centerBlock.getMaterial() == Material.WATER); return down && center && blade && up; } // TilePowerAcceptor @Override public void update() { - if (this.multiblockChecker == null) { - final BlockPos pos = this.getPos().offset(this.getFacing().getOpposite(), 2).down(); - this.multiblockChecker = new MultiblockChecker(this.world, pos); + if (multiblockChecker == null) { + final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2).down(); + multiblockChecker = new MultiblockChecker(world, downCenter); } - this.ticksSinceLastChange++; + ticksSinceLastChange++; // Check cells input slot 2 time per second - if (!world.isRemote && this.ticksSinceLastChange >= 10) { - if (!this.inventory.getStackInSlot(1).isEmpty()) { - FluidUtils.drainContainers(this.tank, this.inventory, 1, 6); - FluidUtils.fillContainers(this.tank, this.inventory, 1, 6, this.tank.getFluidType()); + if (!world.isRemote && ticksSinceLastChange >= 10) { + if (!inventory.getStackInSlot(1).isEmpty()) { + FluidUtils.drainContainers(tank, inventory, 1, 6); + FluidUtils.fillContainers(tank, inventory, 1, 6, tank.getFluidType()); } - this.ticksSinceLastChange = 0; + ticksSinceLastChange = 0; } if (!world.isRemote && getMutliBlock()) { @@ -120,13 +118,13 @@ public class TileIndustrialGrinder extends TileGenericMachine implements IContai @Override public void readFromNBT(final NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); - this.tank.readFromNBT(tagCompound); + tank.readFromNBT(tagCompound); } @Override public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); - this.tank.writeToNBT(tagCompound); + tank.writeToNBT(tagCompound); return tagCompound; } @@ -177,7 +175,7 @@ public class TileIndustrialGrinder extends TileGenericMachine implements IContai return false; } final FluidStack recipeFluid = recipe.fluidStack; - final FluidStack tankFluid = this.tank.getFluid(); + final FluidStack tankFluid = tank.getFluid(); if (recipe.fluidStack == null) { return true; } @@ -195,7 +193,7 @@ public class TileIndustrialGrinder extends TileGenericMachine implements IContai @Override public boolean onCraft(final TileEntity tile, final IndustrialGrinderRecipe recipe) { final FluidStack recipeFluid = recipe.fluidStack; - final FluidStack tankFluid = this.tank.getFluid(); + final FluidStack tankFluid = tank.getFluid(); if (recipe.fluidStack == null) { return true; } @@ -205,12 +203,12 @@ public class TileIndustrialGrinder extends TileGenericMachine implements IContai if (tankFluid.isFluidEqual(recipeFluid)) { if (tankFluid.amount >= recipeFluid.amount) { if (tankFluid.amount == recipeFluid.amount) { - this.tank.setFluid(null); + tank.setFluid(null); } else { tankFluid.amount -= recipeFluid.amount; } - this.syncWithAll(); + syncWithAll(); return true; } } diff --git a/src/main/java/techreborn/tiles/multiblock/TileIndustrialSawmill.java b/src/main/java/techreborn/tiles/multiblock/TileIndustrialSawmill.java index a596259bd..c1f3d5e0d 100644 --- a/src/main/java/techreborn/tiles/multiblock/TileIndustrialSawmill.java +++ b/src/main/java/techreborn/tiles/multiblock/TileIndustrialSawmill.java @@ -80,34 +80,32 @@ public class TileIndustrialSawmill extends TileGenericMachine implements IContai if (multiblockChecker == null) { return false; } - final boolean down = this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, - MultiblockChecker.ZERO_OFFSET); - final boolean up = this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, - new BlockPos(0, 2, 0)); - final boolean blade = this.multiblockChecker.checkRingY(1, 1, MultiblockChecker.REINFORCED_CASING, - new BlockPos(0, 1, 0)); - final IBlockState centerBlock = this.multiblockChecker.getBlock(0, 1, 0); + final boolean down = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, MultiblockChecker.ZERO_OFFSET); + final boolean up = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, new BlockPos(0, 2, 0)); + final boolean blade = multiblockChecker.checkRingY(1, 1, MultiblockChecker.REINFORCED_CASING, new BlockPos(0, 1, 0)); + final IBlockState centerBlock = multiblockChecker.getBlock(0, 1, 0); final boolean center = ((centerBlock.getBlock() instanceof BlockLiquid - || centerBlock.getBlock() instanceof IFluidBlock) && centerBlock.getMaterial() == Material.WATER); + || centerBlock.getBlock() instanceof IFluidBlock) + && centerBlock.getMaterial() == Material.WATER); return down && center && blade && up; } // TileGenericMachine @Override public void update() { - if (this.multiblockChecker == null) { - final BlockPos pos = this.getPos().offset(this.getFacing().getOpposite(), 2).down(); - this.multiblockChecker = new MultiblockChecker(this.world, pos); + if (multiblockChecker == null) { + final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2).down(); + multiblockChecker = new MultiblockChecker(world, downCenter); } - this.ticksSinceLastChange++; + ticksSinceLastChange++; // Check cells input slot 2 time per second - if (!world.isRemote && this.ticksSinceLastChange >= 10) { - if (!this.inventory.getStackInSlot(1).isEmpty()) { - FluidUtils.drainContainers(this.tank, this.inventory, 1, 5); - FluidUtils.fillContainers(this.tank, this.inventory, 1, 5, this.tank.getFluidType()); + if (!world.isRemote && ticksSinceLastChange >= 10) { + if (!inventory.getStackInSlot(1).isEmpty()) { + FluidUtils.drainContainers(tank, inventory, 1, 5); + FluidUtils.fillContainers(tank, inventory, 1, 5, tank.getFluidType()); } - this.ticksSinceLastChange = 0; + ticksSinceLastChange = 0; } if (!world.isRemote && getMutliBlock()) { @@ -120,13 +118,13 @@ public class TileIndustrialSawmill extends TileGenericMachine implements IContai @Override public void readFromNBT(final NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); - this.tank.readFromNBT(tagCompound); + tank.readFromNBT(tagCompound); } @Override public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); - this.tank.writeToNBT(tagCompound); + tank.writeToNBT(tagCompound); return tagCompound; } @@ -141,7 +139,7 @@ public class TileIndustrialSawmill extends TileGenericMachine implements IContai @Override public T getCapability(final Capability capability, final EnumFacing facing) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { - if (this.tank != null) { + if (tank != null) { return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tank); } } @@ -177,7 +175,7 @@ public class TileIndustrialSawmill extends TileGenericMachine implements IContai return false; } final FluidStack recipeFluid = recipe.fluidStack; - final FluidStack tankFluid = this.tank.getFluid(); + final FluidStack tankFluid = tank.getFluid(); if (recipe.fluidStack == null) { return true; } @@ -195,7 +193,7 @@ public class TileIndustrialSawmill extends TileGenericMachine implements IContai @Override public boolean onCraft(TileEntity tile, IndustrialSawmillRecipe recipe) { final FluidStack recipeFluid = recipe.fluidStack; - final FluidStack tankFluid = this.tank.getFluid(); + final FluidStack tankFluid = tank.getFluid(); if (recipe.fluidStack == null) { return true; } @@ -205,11 +203,11 @@ public class TileIndustrialSawmill extends TileGenericMachine implements IContai if (tankFluid.isFluidEqual(recipeFluid)) { if (tankFluid.amount >= recipeFluid.amount) { if (tankFluid.amount == recipeFluid.amount) { - this.tank.setFluid(null); + tank.setFluid(null); } else { tankFluid.amount -= recipeFluid.amount; } - this.syncWithAll(); + syncWithAll(); return true; } } diff --git a/src/main/java/techreborn/tiles/multiblock/TileVacuumFreezer.java b/src/main/java/techreborn/tiles/multiblock/TileVacuumFreezer.java index 07ab0ecb5..46651f182 100644 --- a/src/main/java/techreborn/tiles/multiblock/TileVacuumFreezer.java +++ b/src/main/java/techreborn/tiles/multiblock/TileVacuumFreezer.java @@ -56,7 +56,7 @@ public class TileVacuumFreezer extends TileGenericMachine implements IContainerP } public boolean getMultiBlock() { - return this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.REINFORCED_CASING, MultiblockChecker.ZERO_OFFSET); + return multiblockChecker.checkRectY(1, 1, MultiblockChecker.REINFORCED_CASING, MultiblockChecker.ZERO_OFFSET); } // TileGenericMachine @@ -71,7 +71,7 @@ public class TileVacuumFreezer extends TileGenericMachine implements IContainerP @Override public void validate() { super.validate(); - this.multiblockChecker = new MultiblockChecker(this.world, this.getPos().down()); + multiblockChecker = new MultiblockChecker(world, pos.down()); } // IContainerProvider diff --git a/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java b/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java index d5f1833b5..c28c64b94 100644 --- a/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java +++ b/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java @@ -365,10 +365,9 @@ public class TileAutoCraftingTable extends TilePowerAcceptor if (canMake(recipe)) { if (canUseEnergy(euTick)) { progress++; - if(progress == 1){ - world.playSound(null, pos.getX(), pos.getY(), - pos.getZ(), ModSounds.AUTO_CRAFTING, - SoundCategory.BLOCKS, 0.3F, 0.8F); + if (progress == 1) { + world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.AUTO_CRAFTING, + SoundCategory.BLOCKS, 0.3F, 0.8F); } useEnergy(euTick); } diff --git a/src/main/java/techreborn/tiles/tier1/TileElectricFurnace.java b/src/main/java/techreborn/tiles/tier1/TileElectricFurnace.java index 8bf015dc7..fc855337b 100644 --- a/src/main/java/techreborn/tiles/tier1/TileElectricFurnace.java +++ b/src/main/java/techreborn/tiles/tier1/TileElectricFurnace.java @@ -63,47 +63,50 @@ public class TileElectricFurnace extends TilePowerAcceptor super(); } - public int gaugeProgressScaled(final int scale) { - return this.progress * scale / this.fuelScale; + public int gaugeProgressScaled(int scale) { + return progress * scale / fuelScale; } public void cookItems() { - if (this.canSmelt()) { - final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.getStackInSlot(this.input1)); + if (canSmelt()) { + final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1)); - if (this.getStackInSlot(this.output) == ItemStack.EMPTY) { - this.setInventorySlotContents(this.output, itemstack.copy()); - } else if (this.getStackInSlot(this.output).isItemEqual(itemstack)) { - this.getStackInSlot(this.output).grow(itemstack.getCount()); + if (getStackInSlot(output) == ItemStack.EMPTY) { + setInventorySlotContents(output, itemstack.copy()); + } else if (getStackInSlot(output).isItemEqual(itemstack)) { + getStackInSlot(output).grow(itemstack.getCount()); } - if (this.getStackInSlot(this.input1).getCount() > 1) { - this.decrStackSize(this.input1, 1); + if (getStackInSlot(input1).getCount() > 1) { + decrStackSize(input1, 1); } else { - this.setInventorySlotContents(this.input1, ItemStack.EMPTY); + setInventorySlotContents(input1, ItemStack.EMPTY); } } } public boolean canSmelt() { - if (this.getStackInSlot(this.input1) == ItemStack.EMPTY) { + if (getStackInSlot(input1) == ItemStack.EMPTY) { return false; } - final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.getStackInSlot(this.input1)); - if (itemstack.isEmpty()) + final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1)); + if (itemstack.isEmpty()) { return false; - if (this.getStackInSlot(this.output) == ItemStack.EMPTY) + } + if (getStackInSlot(output) == ItemStack.EMPTY) { return true; - if (!this.getStackInSlot(this.output).isItemEqual(itemstack)) + } + if (!getStackInSlot(output).isItemEqual(itemstack)) { return false; - final int result = this.getStackInSlot(this.output).getCount() + itemstack.getCount(); + } + final int result = getStackInSlot(output).getCount() + itemstack.getCount(); return result <= this.getInventoryStackLimit() && result <= itemstack.getMaxStackSize(); } public boolean isBurning() { - return this.getEnergy() > getEuPerTick(this.cost); + return getEnergy() > getEuPerTick(cost); } - public ItemStack getResultFor(final ItemStack stack) { + public ItemStack getResultFor(ItemStack stack) { final ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack); if (!result.isEmpty()) { return result.copy(); @@ -112,26 +115,26 @@ public class TileElectricFurnace extends TilePowerAcceptor } public void updateState() { - if (wasBurning != (this.progress > 0)) { + if (wasBurning != (progress > 0)) { // skips updating the block state for 1 tick, to prevent the machine from // turning on/off rapidly causing fps drops - if (wasBurning && this.progress == 0 && canSmelt()) { + if (wasBurning && progress == 0 && canSmelt()) { wasBurning = true; return; } - final IBlockState BlockStateContainer = this.world.getBlockState(this.pos); + final IBlockState BlockStateContainer = world.getBlockState(pos); if (BlockStateContainer.getBlock() instanceof BlockMachineBase) { final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock(); - if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != this.progress > 0) - blockMachineBase.setActive(this.progress > 0, this.world, this.pos); + if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != progress > 0) + blockMachineBase.setActive(progress > 0, world, pos); } - wasBurning = (this.progress > 0); + wasBurning = (progress > 0); } } public int getBurnTime() { - return this.progress; + return progress; } public void setBurnTime(final int burnTime) { @@ -146,32 +149,31 @@ public class TileElectricFurnace extends TilePowerAcceptor } super.update(); - this.charge(2); + charge(2); - final boolean burning = this.isBurning(); + final boolean burning = isBurning(); boolean updateInventory = false; - if (this.isBurning() && this.canSmelt()) { - this.updateState(); - if (canUseEnergy(getEuPerTick(this.cost))) { - this.useEnergy(getEuPerTick(this.cost)); - this.progress++; - if (this.progress >= Math.max((int) (fuelScale * (1.0 - getSpeedMultiplier())), 5)) { - this.progress = 0; - this.cookItems(); + if (isBurning() && canSmelt()) { + updateState(); + if (canUseEnergy(getEuPerTick(cost))) { + useEnergy(getEuPerTick(cost)); + progress++; + if (progress >= Math.max((int) (fuelScale * (1.0 - getSpeedMultiplier())), 5)) { + progress = 0; + cookItems(); updateInventory = true; } } } else { - this.progress = 0; - this.updateState(); + progress = 0; + updateState(); } - if (burning != this.isBurning()) { + if (burning != isBurning()) { updateInventory = true; } if (updateInventory) { - this.markDirty(); + markDirty(); } - } @Override @@ -208,7 +210,7 @@ public class TileElectricFurnace extends TilePowerAcceptor // IInventoryProvider @Override public Inventory getInventory() { - return this.inventory; + return inventory; } // IContainerProvider diff --git a/src/main/java/techreborn/tiles/tier1/TilePlayerDectector.java b/src/main/java/techreborn/tiles/tier1/TilePlayerDectector.java index 998990e50..63fc59411 100644 --- a/src/main/java/techreborn/tiles/tier1/TilePlayerDectector.java +++ b/src/main/java/techreborn/tiles/tier1/TilePlayerDectector.java @@ -91,8 +91,8 @@ public class TilePlayerDectector extends TilePowerAcceptor implements IToolDrop useEnergy(euPerTick); } if (lastRedstone != redstone) { - WorldUtils.updateBlock(world, getPos()); - world.notifyNeighborsOfStateChange(getPos(), world.getBlockState(getPos()).getBlock(), true); + WorldUtils.updateBlock(world, pos); + world.notifyNeighborsOfStateChange(pos, world.getBlockState(pos).getBlock(), true); } } } diff --git a/src/main/java/techreborn/tiles/tier1/TileRecycler.java b/src/main/java/techreborn/tiles/tier1/TileRecycler.java index 1fa1a1973..532c0e0e2 100644 --- a/src/main/java/techreborn/tiles/tier1/TileRecycler.java +++ b/src/main/java/techreborn/tiles/tier1/TileRecycler.java @@ -62,59 +62,62 @@ public class TileRecycler extends TilePowerAcceptor super(); } - public int gaugeProgressScaled(final int scale) { - return this.progress * scale / this.time; + public int gaugeProgressScaled(int scale) { + return progress * scale / time; } public int getProgress() { - return this.progress; + return progress; } - public void setProgress(final int progress) { + public void setProgress(int progress) { this.progress = progress; } public void recycleItems() { final ItemStack itemstack = ItemParts.getPartByName("scrap"); - final int randomchance = this.world.rand.nextInt(this.chance); + final int randomchance = this.world.rand.nextInt(chance); if (randomchance == 1) { - if (this.getStackInSlot(1).isEmpty()) - this.setInventorySlotContents(1, itemstack.copy()); - else + if (getStackInSlot(1).isEmpty()) { + setInventorySlotContents(1, itemstack.copy()); + } + else { this.getStackInSlot(1).grow(itemstack.getCount()); + } } - this.decrStackSize(0, 1); + decrStackSize(0, 1); } public boolean canRecycle() { - return this.getStackInSlot(0) != ItemStack.EMPTY && this.hasSlotGotSpace(1); + return getStackInSlot(0) != ItemStack.EMPTY && hasSlotGotSpace(1); } - public boolean hasSlotGotSpace(final int slot) { - if (this.getStackInSlot(slot) == ItemStack.EMPTY) { + public boolean hasSlotGotSpace(int slot) { + if (getStackInSlot(slot) == ItemStack.EMPTY) { return true; - } else if (this.getStackInSlot(slot).getCount() < this.getStackInSlot(slot).getMaxStackSize()) { + } else if (getStackInSlot(slot).getCount() < getStackInSlot(slot).getMaxStackSize()) { return true; } return false; } public boolean isBurning() { - return this.isBurning; + return isBurning; } - public void setBurning(final boolean burning) { + public void setBurning(boolean burning) { this.isBurning = burning; } public void updateState() { - final IBlockState BlockStateContainer = this.world.getBlockState(this.pos); + final IBlockState BlockStateContainer = world.getBlockState(pos); if (BlockStateContainer.getBlock() instanceof BlockMachineBase) { final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock(); - boolean shouldBurn = this.isBurning || (this.canRecycle() && this.canUseEnergy(getEuPerTick(this.cost))); - if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != shouldBurn) - blockMachineBase.setActive(this.isBurning, this.world, this.pos); + boolean shouldBurn = isBurning || (canRecycle() && canUseEnergy(getEuPerTick(cost))); + if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != shouldBurn) { + blockMachineBase.setActive(isBurning, world, pos); + } } } @@ -122,29 +125,32 @@ public class TileRecycler extends TilePowerAcceptor @Override public void update() { super.update(); - if (this.world.isRemote) + if (world.isRemote) { return; + } + charge(2); boolean updateInventory = false; - if (this.canRecycle() && !this.isBurning() && this.getEnergy() != 0) - this.setBurning(true); - else if (this.isBurning()) { - if (this.useEnergy(getEuPerTick(this.cost)) != getEuPerTick(this.cost)) + if (canRecycle() && !isBurning() && getEnergy() != 0) { + setBurning(true); + } + else if (isBurning()) { + if (useEnergy(getEuPerTick(cost)) != getEuPerTick(cost)) { this.setBurning(false); - this.progress++; - if (this.progress >= Math.max((int) (this.time* (1.0 - getSpeedMultiplier())), 1)) { - this.progress = 0; - this.recycleItems(); + } + progress++; + if (progress >= Math.max((int) (time* (1.0 - getSpeedMultiplier())), 1)) { + progress = 0; + recycleItems(); updateInventory = true; - this.setBurning(false); + setBurning(false); } } - this.updateState(); - this.charge(2); - + updateState(); + if (updateInventory) { - this.markDirty(); + markDirty(); } } @@ -154,12 +160,12 @@ public class TileRecycler extends TilePowerAcceptor } @Override - public boolean canAcceptEnergy(final EnumFacing direction) { + public boolean canAcceptEnergy(EnumFacing direction) { return true; } @Override - public boolean canProvideEnergy(final EnumFacing direction) { + public boolean canProvideEnergy(EnumFacing direction) { return false; } @@ -181,7 +187,7 @@ public class TileRecycler extends TilePowerAcceptor // IToolDrop @Override - public ItemStack getToolDrop(final EntityPlayer entityPlayer) { + public ItemStack getToolDrop(EntityPlayer entityPlayer) { return new ItemStack(ModBlocks.RECYCLER, 1); } @@ -193,7 +199,7 @@ public class TileRecycler extends TilePowerAcceptor // IContainerProvider @Override - public BuiltContainer createContainer(final EntityPlayer player) { + public BuiltContainer createContainer(EntityPlayer player) { return new ContainerBuilder("recycler").player(player.inventory).inventory().hotbar().addInventory() .tile(this).slot(0, 55, 45).outputSlot(1, 101, 45).energySlot(2, 8, 72).syncEnergyValue() .syncIntegerValue(this::getProgress, this::setProgress).addInventory().create(this); diff --git a/src/main/java/techreborn/tiles/tier1/TileRollingMachine.java b/src/main/java/techreborn/tiles/tier1/TileRollingMachine.java index 0abc6282e..a029560ad 100644 --- a/src/main/java/techreborn/tiles/tier1/TileRollingMachine.java +++ b/src/main/java/techreborn/tiles/tier1/TileRollingMachine.java @@ -112,64 +112,69 @@ public class TileRollingMachine extends TilePowerAcceptor @Override public void update() { super.update(); - this.charge(2); - if (!this.world.isRemote) { - InventoryCrafting craftMatrix = getCraftingMatrix(); - this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, this.world); - if (this.currentRecipe != null) { - if (world.getTotalWorldTime() % 2 == 0) { - Optional balanceResult = balanceRecipe(craftMatrix); - if (balanceResult.isPresent()) { - craftMatrix = balanceResult.get(); - } - } - this.currentRecipeOutput = currentRecipe.getCraftingResult(craftMatrix); - } else { - this.currentRecipeOutput = ItemStack.EMPTY; - } + if (world.isRemote) { + return; + } + charge(2); - if (!this.currentRecipeOutput.isEmpty() && this.canMake(craftMatrix)) { - if (this.tickTime >= Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1)) { - this.currentRecipeOutput = RollingMachineRecipe.instance.findMatchingRecipeOutput(craftMatrix, this.world); - if (!this.currentRecipeOutput.isEmpty()) { - boolean hasCrafted = false; - if (this.inventory.getStackInSlot(outputSlot) == ItemStack.EMPTY) { - this.inventory.setInventorySlotContents(outputSlot, this.currentRecipeOutput); - this.tickTime = 0; + InventoryCrafting craftMatrix = getCraftingMatrix(); + currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world); + if (currentRecipe != null) { + if (world.getTotalWorldTime() % 2 == 0) { + Optional balanceResult = balanceRecipe(craftMatrix); + if (balanceResult.isPresent()) { + craftMatrix = balanceResult.get(); + } + } + currentRecipeOutput = currentRecipe.getCraftingResult(craftMatrix); + } else { + currentRecipeOutput = ItemStack.EMPTY; + } + + if (!currentRecipeOutput.isEmpty() && canMake(craftMatrix)) { + if (tickTime >= Math.max((int) (runTime * (1.0 - getSpeedMultiplier())), 1)) { + currentRecipeOutput = RollingMachineRecipe.instance.findMatchingRecipeOutput(craftMatrix, world); + if (!currentRecipeOutput.isEmpty()) { + boolean hasCrafted = false; + if (inventory.getStackInSlot(outputSlot) == ItemStack.EMPTY) { + inventory.setInventorySlotContents(outputSlot, currentRecipeOutput); + tickTime = 0; + hasCrafted = true; + } else { + if (inventory.getStackInSlot(outputSlot).getCount() + + currentRecipeOutput.getCount() <= currentRecipeOutput.getMaxStackSize()) { + final ItemStack stack = inventory.getStackInSlot(outputSlot); + stack.setCount(stack.getCount() + currentRecipeOutput.getCount()); + inventory.setInventorySlotContents(outputSlot, stack); + tickTime = 0; hasCrafted = true; - } else { - if (this.inventory.getStackInSlot(outputSlot).getCount() + this.currentRecipeOutput.getCount() <= this.currentRecipeOutput - .getMaxStackSize()) { - final ItemStack stack = this.inventory.getStackInSlot(outputSlot); - stack.setCount(stack.getCount() + this.currentRecipeOutput.getCount()); - this.inventory.setInventorySlotContents(outputSlot, stack); - this.tickTime = 0; - hasCrafted = true; - } - } - if (hasCrafted) { - for (int i = 0; i < craftMatrix.getSizeInventory(); i++) { - inventory.decrStackSize(i, 1); - } - this.currentRecipeOutput = ItemStack.EMPTY; - this.currentRecipe = null; } } - } - } else { - this.tickTime = 0; - } - if (!this.currentRecipeOutput.isEmpty()) { - if (this.canUseEnergy(getEuPerTick(energyPerTick)) && this.tickTime < Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1) && canMake(craftMatrix)) { - this.useEnergy(getEuPerTick(energyPerTick)); - this.tickTime++; + if (hasCrafted) { + for (int i = 0; i < craftMatrix.getSizeInventory(); i++) { + inventory.decrStackSize(i, 1); + } + currentRecipeOutput = ItemStack.EMPTY; + currentRecipe = null; + } } } - if (this.currentRecipeOutput.isEmpty()) { - this.tickTime = 0; - this.currentRecipe = null; + } else { + tickTime = 0; + } + if (!currentRecipeOutput.isEmpty()) { + if (canUseEnergy(getEuPerTick(energyPerTick)) + && tickTime < Math.max((int) (runTime * (1.0 - getSpeedMultiplier())), 1) + && canMake(craftMatrix)) { + useEnergy(getEuPerTick(energyPerTick)); + tickTime++; } } + if (currentRecipeOutput.isEmpty()) { + tickTime = 0; + currentRecipe = null; + } + } public Optional balanceRecipe(InventoryCrafting craftCache) { @@ -301,11 +306,11 @@ public class TileRollingMachine extends TilePowerAcceptor @Override public Inventory getInventory() { - return this.inventory; + return inventory; } public int getBurnTime() { - return this.tickTime; + return tickTime; } public void setBurnTime(final int burnTime) { @@ -313,10 +318,10 @@ public class TileRollingMachine extends TilePowerAcceptor } public int getBurnTimeRemainingScaled(final int scale) { - if (this.tickTime == 0 || Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1) == 0) { + if (tickTime == 0 || Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1) == 0) { return 0; } - return this.tickTime * scale / Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1); + return tickTime * scale / Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1); } @Override diff --git a/src/main/java/techreborn/tiles/transformers/TileTransformer.java b/src/main/java/techreborn/tiles/transformers/TileTransformer.java index 04078b304..0ac4b00f4 100644 --- a/src/main/java/techreborn/tiles/transformers/TileTransformer.java +++ b/src/main/java/techreborn/tiles/transformers/TileTransformer.java @@ -134,7 +134,7 @@ public class TileTransformer extends TilePowerAcceptor // IToolDrop @Override - public ItemStack getToolDrop(EntityPlayer p0) { + public ItemStack getToolDrop(EntityPlayer playerIn) { return new ItemStack(wrenchDrop); }