From 06fad2264fa1cab14de1b0336c3df50cf517f75f Mon Sep 17 00:00:00 2001 From: Dragon2488 Date: Fri, 22 Jul 2016 21:45:55 +0700 Subject: [PATCH] Fusion reactor fixes & rewrite, energy fixes. --- .../blocks/BlockFusionControlComputer.java | 2 +- .../container/ContainerFusionReactor.java | 127 +++---- .../client/gui/GuiFusionReactor.java | 32 +- src/main/java/techreborn/init/OreDict.java | 8 + .../parts/powerCables/CableMultipart.java | 30 +- src/main/java/techreborn/tiles/TileAesu.java | 28 +- .../TileEntityFusionController.java | 354 +++++++----------- .../java/techreborn/tiles/idsu/TileIDSU.java | 22 +- .../java/techreborn/tiles/lesu/TileLesu.java | 22 +- .../techreborn/tiles/storage/TileBatBox.java | 2 +- .../tiles/storage/TileEnergyStorage.java | 34 +- .../techreborn/tiles/storage/TileMFE.java | 2 +- .../techreborn/tiles/storage/TileMFSU.java | 2 +- 13 files changed, 279 insertions(+), 386 deletions(-) diff --git a/src/main/java/techreborn/blocks/BlockFusionControlComputer.java b/src/main/java/techreborn/blocks/BlockFusionControlComputer.java index 5ca0b9190..37693d82e 100644 --- a/src/main/java/techreborn/blocks/BlockFusionControlComputer.java +++ b/src/main/java/techreborn/blocks/BlockFusionControlComputer.java @@ -44,7 +44,7 @@ public class BlockFusionControlComputer extends BlockMachineBase implements IAdv super.onEntityWalk(worldIn, pos, entityIn); if (worldIn.getTileEntity(pos) instanceof TileEntityFusionController) { - if (((TileEntityFusionController) worldIn.getTileEntity(pos)).crafingTickTime != 0 + if (((TileEntityFusionController) worldIn.getTileEntity(pos)).recipe != null && ((TileEntityFusionController) worldIn.getTileEntity(pos)).checkCoils()) { entityIn.attackEntityFrom(new FusionDamageSource(), 200F); diff --git a/src/main/java/techreborn/client/container/ContainerFusionReactor.java b/src/main/java/techreborn/client/container/ContainerFusionReactor.java index b79d5b149..c1fdb798a 100644 --- a/src/main/java/techreborn/client/container/ContainerFusionReactor.java +++ b/src/main/java/techreborn/client/container/ContainerFusionReactor.java @@ -7,21 +7,22 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import reborncore.client.gui.SlotOutput; import reborncore.common.container.RebornContainer; +import techreborn.api.reactor.FusionReactorRecipe; import techreborn.tiles.fusionReactor.TileEntityFusionController; -public class ContainerFusionReactor extends RebornContainer -{ +public class ContainerFusionReactor extends RebornContainer { - public int coilStatus; - public int energy; public int tickTime; public int finalTickTime; - public int neededEU; + + public int neededEnergy; + public int energy; + + public boolean hasCoils; TileEntityFusionController fusionController; - public ContainerFusionReactor(TileEntityFusionController tileEntityFusionController, EntityPlayer player) - { + public ContainerFusionReactor(TileEntityFusionController tileEntityFusionController, EntityPlayer player) { super(); this.fusionController = tileEntityFusionController; @@ -31,105 +32,73 @@ public class ContainerFusionReactor extends RebornContainer int i; - for (i = 0; i < 3; ++i) - { - for (int j = 0; j < 9; ++j) - { + for (i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { this.addSlotToContainer(new BaseSlot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } - for (i = 0; i < 9; ++i) - { + for (i = 0; i < 9; ++i) { this.addSlotToContainer(new BaseSlot(player.inventory, i, 8 + i * 18, 142)); } } @Override - public boolean canInteractWith(EntityPlayer player) - { + public boolean canInteractWith(EntityPlayer player) { return true; } @Override - public void detectAndSendChanges() - { + public void detectAndSendChanges() { super.detectAndSendChanges(); - for (int i = 0; i < this.listeners.size(); i++) - { - IContainerListener IContainerListener = this.listeners.get(i); - if (this.coilStatus != fusionController.coilStatus) - { - IContainerListener.sendProgressBarUpdate(this, 0, fusionController.coilStatus); - } - if (this.energy != (int) fusionController.getEnergy()) - { - IContainerListener.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy()); - } - if (this.tickTime != fusionController.crafingTickTime) - { - IContainerListener.sendProgressBarUpdate(this, 2, fusionController.crafingTickTime); - } - if (this.finalTickTime != fusionController.finalTickTime) - { - IContainerListener.sendProgressBarUpdate(this, 3, fusionController.finalTickTime); - } - if (this.neededEU != fusionController.neededPower) - { - IContainerListener.sendProgressBarUpdate(this, 4, fusionController.neededPower); - } + FusionReactorRecipe rec = fusionController.recipe; + for (int i = 0; i < this.listeners.size(); i++) { + IContainerListener listener = this.listeners.get(i); + listener.sendProgressBarUpdate(this, 0, fusionController.hasCoils ? 1 : 0); + listener.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy()); + listener.sendProgressBarUpdate(this, 2, rec == null ? 0 : (int) rec.getStartEU()); + listener.sendProgressBarUpdate(this, 3, rec == null ? -1 : fusionController.recipeTickTime); + listener.sendProgressBarUpdate(this, 4, rec == null ? 0 : rec.getTickTime()); } } @Override - public void addListener(IContainerListener crafting) - { - super.addListener(crafting); - crafting.sendProgressBarUpdate(this, 0, fusionController.coilStatus); - crafting.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy()); - crafting.sendProgressBarUpdate(this, 2, fusionController.crafingTickTime); - crafting.sendProgressBarUpdate(this, 3, fusionController.finalTickTime); - crafting.sendProgressBarUpdate(this, 4, fusionController.neededPower); + public void addListener(IContainerListener listener) { + super.addListener(listener); + FusionReactorRecipe rec = fusionController.recipe; + listener.sendProgressBarUpdate(this, 0, fusionController.hasCoils ? 1 : 0); + listener.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy()); + listener.sendProgressBarUpdate(this, 2, rec == null ? 0 : (int) rec.getStartEU()); + listener.sendProgressBarUpdate(this, 3, rec == null ? -1 : fusionController.recipeTickTime); + listener.sendProgressBarUpdate(this, 4, rec == null ? 0 : rec.getTickTime()); } @SideOnly(Side.CLIENT) @Override - public void updateProgressBar(int id, int value) - { - if (id == 0) - { - this.coilStatus = value; - } else if (id == 1) - { - this.energy = value; - } else if (id == 2) - { - this.tickTime = value; - } else if (id == 3) - { - this.finalTickTime = value; - } else if (id == 4) - { - this.neededEU = value; - } - if (tickTime == -1) - { - tickTime = 0; - } - if (finalTickTime == -1) - { - finalTickTime = 0; - } - if (neededEU == -1) - { - neededEU = 0; + public void updateProgressBar(int id, int value) { + switch (id) { + case 0: + this.hasCoils = value == 1; + break; + case 1: + this.energy = value; + break; + case 2: + this.neededEnergy = value; + break; + case 3: + this.tickTime = value; + break; + case 4: + this.finalTickTime = value; + break; } } - public int getProgressScaled() - { + public int getProgressScaled() { return Math.max(0, Math.min(24, (this.tickTime > 0 ? 1 : 0) + this.tickTime * 24 / (this.finalTickTime < 1 ? 1 : this.finalTickTime))); } + } diff --git a/src/main/java/techreborn/client/gui/GuiFusionReactor.java b/src/main/java/techreborn/client/gui/GuiFusionReactor.java index 14be4a15f..4d3edc819 100644 --- a/src/main/java/techreborn/client/gui/GuiFusionReactor.java +++ b/src/main/java/techreborn/client/gui/GuiFusionReactor.java @@ -9,6 +9,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.translation.I18n; import reborncore.common.powerSystem.PowerSystem; +import techreborn.api.reactor.FusionReactorRecipe; import techreborn.client.container.ContainerFusionReactor; import techreborn.tiles.fusionReactor.TileEntityFusionController; @@ -19,29 +20,28 @@ public class GuiFusionReactor extends GuiContainer "textures/gui/fusion_reactor.png"); ContainerFusionReactor containerFusionReactor; - TileEntityFusionController fusionController; - - public GuiFusionReactor(EntityPlayer player, TileEntityFusionController tileaesu) - { + public GuiFusionReactor(EntityPlayer player, TileEntityFusionController tileaesu) { super(new ContainerFusionReactor(tileaesu, player)); containerFusionReactor = (ContainerFusionReactor) this.inventorySlots; - this.fusionController = tileaesu; } - protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) - { + protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) { String name = I18n.translateToLocal("tile.techreborn.fusioncontrolcomputer.name"); this.fontRendererObj.drawString(name, 87, 6, 4210752); - this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8, - this.ySize - 96 + 2, 4210752); + this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory"), 8, this.ySize - 96 + 2, 4210752); this.fontRendererObj.drawString(PowerSystem.getLocalizedPower(containerFusionReactor.energy), 11, 8, 16448255); - this.fontRendererObj.drawString("Coils: " + (containerFusionReactor.coilStatus == 1 ? "Yes" : "No"), 11, 16, - 16448255); - if (containerFusionReactor.neededEU > 1 && containerFusionReactor.tickTime < 1) - this.fontRendererObj.drawString( - "Start: " + percentage(containerFusionReactor.neededEU, containerFusionReactor.energy) + "%", 11, - 24, 16448255); + this.fontRendererObj.drawString("Coils: " + (containerFusionReactor.hasCoils ? "Yes" : "No"), 11, 16, 16448255); + + if(containerFusionReactor.tickTime != -1) { + if (containerFusionReactor.tickTime == 0) { + this.fontRendererObj.drawString("Start: " + percentage(containerFusionReactor.neededEnergy, + containerFusionReactor.energy) + "%", 11, 24, 16448255); + } else { + this.fontRendererObj.drawString("Fusion: " + percentage(containerFusionReactor.finalTickTime, + containerFusionReactor.tickTime) + "%", 11, 24, 16448255); + } + } } @@ -85,7 +85,7 @@ public class GuiFusionReactor extends GuiContainer } - public int percentage(int MaxValue, int CurrentValue) + public int percentage(double MaxValue, double CurrentValue) { if (CurrentValue == 0) return 0; diff --git a/src/main/java/techreborn/init/OreDict.java b/src/main/java/techreborn/init/OreDict.java index 097a44df7..1aa61254f 100644 --- a/src/main/java/techreborn/init/OreDict.java +++ b/src/main/java/techreborn/init/OreDict.java @@ -4,6 +4,8 @@ import com.google.common.collect.ImmutableList; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.oredict.OreDictionary; import techreborn.Core; @@ -119,6 +121,12 @@ public class OreDict { String oreDictName = "nugget" + OreDictUtils.toFirstUpper(type); OreDictionary.registerOre(oreDictName, ItemNuggets.getNuggetByName(type)); } + + for(Fluid fluid : FluidRegistry.getRegisteredFluids().values()) { + ItemStack cell = DynamicCell.getCellWithFluid(fluid); + String oreDictName = "cell" + OreDictUtils.toFirstUpper(fluid.getName().toLowerCase()); + OreDictionary.registerOre(oreDictName, cell); + } } diff --git a/src/main/java/techreborn/parts/powerCables/CableMultipart.java b/src/main/java/techreborn/parts/powerCables/CableMultipart.java index a473ee149..6082c48f1 100644 --- a/src/main/java/techreborn/parts/powerCables/CableMultipart.java +++ b/src/main/java/techreborn/parts/powerCables/CableMultipart.java @@ -3,7 +3,9 @@ package techreborn.parts.powerCables; import cofh.api.energy.IEnergyConnection; import cofh.api.energy.IEnergyProvider; import cofh.api.energy.IEnergyReceiver; -import ic2.api.energy.tile.*; +import ic2.api.energy.tile.IEnergyAcceptor; +import ic2.api.energy.tile.IEnergyEmitter; +import ic2.api.energy.tile.IEnergySource; import ic2.api.tile.IEnergyStorage; import net.darkhax.tesla.api.ITeslaProducer; import net.darkhax.tesla.capability.TeslaCapabilities; @@ -34,7 +36,6 @@ import net.minecraftforge.common.property.IExtendedBlockState; import net.minecraftforge.common.property.IUnlistedProperty; import net.minecraftforge.common.property.Properties; import net.minecraftforge.fml.common.Loader; -import reborncore.api.power.IEnergyInterfaceTile; import reborncore.api.power.tile.IEnergyProducerTile; import reborncore.api.power.tile.IEnergyReceiverTile; import reborncore.common.RebornCoreConfig; @@ -300,36 +301,36 @@ public class CableMultipart extends Multipart if(tileEntity == null) continue; EnumFacing opposite = connection.getOpposite(); - //TODO rewrite for new version if(tileEntity instanceof IEnergyProducerTile) { IEnergyProducerTile interfaceTile = (IEnergyProducerTile) tileEntity; if(interfaceTile.canProvideEnergy(opposite)) { double extractedEU = interfaceTile.useEnergy(getCableType().transferRate, true); double dispatched = EnergyUtils.dispatchWiresEnergyPacket(getWorld(), getPos(), extractedEU, blockPos); interfaceTile.useEnergy(dispatched); - continue; + if(extractedEU != 0) continue; } } if(Loader.isModLoaded("IC2") && RebornCoreConfig.getRebornPower().eu()) { if (tileEntity instanceof IEnergySource) { IEnergySource source = (IEnergySource) tileEntity; - if(source.emitsEnergyTo((emitter, from) -> true, opposite)) { + if (source.emitsEnergyTo((emitter, from) -> true, opposite)) { double extractedEU = source.getOfferedEnergy(); if (extractedEU > getCableType().transferRate) extractedEU = getCableType().transferRate; double dispatched = EnergyUtils.dispatchWiresEnergyPacket(getWorld(), getPos(), extractedEU, blockPos); source.drawEnergy(dispatched); - continue; + if (extractedEU != 0) continue; } - } else if(tileEntity instanceof IEnergyStorage) { + } + if (tileEntity instanceof IEnergyStorage) { IEnergyStorage storage = (IEnergyStorage) tileEntity; double extractedEU = storage.getStored(); - if(extractedEU > getCableType().transferRate) + if (extractedEU > getCableType().transferRate) extractedEU = getCableType().transferRate; double dispatched = EnergyUtils.dispatchWiresEnergyPacket(getWorld(), getPos(), extractedEU, blockPos); storage.setStored((int) (extractedEU - dispatched)); - continue; + if (extractedEU != 0) continue; } } @@ -342,18 +343,17 @@ public class CableMultipart extends Multipart double extractedEU = extractedRF / (RebornCoreConfig.euPerRF * 1f); double dispatched = EnergyUtils.dispatchWiresEnergyPacket(getWorld(), getPos(), extractedEU, blockPos); provider.extractEnergy(opposite, (int) (dispatched * RebornCoreConfig.euPerRF), false); - continue; + if (extractedEU != 0) continue; } - } else if(tileEntity instanceof cofh.api.energy.IEnergyStorage) { + } + if (tileEntity instanceof cofh.api.energy.IEnergyStorage) { cofh.api.energy.IEnergyStorage energyStorage = (cofh.api.energy.IEnergyStorage) tileEntity; int extractedRF = energyStorage.extractEnergy( getCableType().transferRate * RebornCoreConfig.euPerRF, true); double extractedEU = extractedRF / (RebornCoreConfig.euPerRF * 1f); - if (extractedEU > getCableType().transferRate) - extractedEU = getCableType().transferRate; double dispatched = EnergyUtils.dispatchWiresEnergyPacket(getWorld(), getPos(), extractedEU, blockPos); energyStorage.extractEnergy((int) (dispatched * RebornCoreConfig.euPerRF), false); - continue; + if (extractedEU != 0) continue; } } @@ -364,7 +364,7 @@ public class CableMultipart extends Multipart double extractedEU = extractedRF / (RebornCoreConfig.euPerRF * 1F); double dispatched = EnergyUtils.dispatchWiresEnergyPacket(getWorld(), getPos(), extractedEU, blockPos); producer.takePower((long) (dispatched * RebornCoreConfig.euPerRF), false); - continue; + if (extractedEU != 0) continue; } } diff --git a/src/main/java/techreborn/tiles/TileAesu.java b/src/main/java/techreborn/tiles/TileAesu.java index 274b8653a..917ae0d36 100644 --- a/src/main/java/techreborn/tiles/TileAesu.java +++ b/src/main/java/techreborn/tiles/TileAesu.java @@ -1,20 +1,20 @@ package techreborn.tiles; import net.minecraft.util.math.BlockPos; +import reborncore.api.power.tile.IEnergyProducerTile; import reborncore.common.IWrenchable; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import reborncore.api.power.EnumPowerTier; -import reborncore.common.powerSystem.TilePowerAcceptor; -import reborncore.common.tile.TilePowerAcceptorProducer; +import reborncore.common.tile.TilePowerAcceptor; import reborncore.common.util.Inventory; import techreborn.config.ConfigTechReborn; import techreborn.init.ModBlocks; import techreborn.power.EnergyUtils; -public class TileAesu extends TilePowerAcceptorProducer implements IWrenchable { +public class TileAesu extends TilePowerAcceptor implements IEnergyProducerTile, IWrenchable { public static final int MAX_OUTPUT = ConfigTechReborn.AesuMaxOutput; public static final int MAX_STORAGE = ConfigTechReborn.AesuMaxStorage; @@ -44,19 +44,11 @@ public class TileAesu extends TilePowerAcceptorProducer implements IWrenchable { if (!worldObj.isRemote && getEnergy() > 0) { double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy(); - for(EnumFacing facing : EnumFacing.VALUES) { - double disposed = emitEnergy(facing, maxOutput); - if(disposed != 0) { - maxOutput -= disposed; - useEnergy(disposed); - if (maxOutput == 0) return; - } - } + double disposed = emitEnergy(getFacingEnum(), maxOutput); + if (maxOutput != 0 && disposed != 0) useEnergy(disposed); } - } - //TODO move to RebornCore public double emitEnergy(EnumFacing enumFacing, double amount) { BlockPos pos = getPos().offset(enumFacing); EnergyUtils.PowerNetReceiver receiver = EnergyUtils.getReceiver( @@ -67,6 +59,16 @@ public class TileAesu extends TilePowerAcceptorProducer implements IWrenchable { return 0; } + @Override + public boolean canAcceptEnergy(EnumFacing direction) { + return getFacingEnum() != direction; + } + + @Override + public boolean canProvideEnergy(EnumFacing direction) { + return getFacingEnum() == direction; + } + @Override public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) { diff --git a/src/main/java/techreborn/tiles/fusionReactor/TileEntityFusionController.java b/src/main/java/techreborn/tiles/fusionReactor/TileEntityFusionController.java index adbea923a..7c03f3715 100644 --- a/src/main/java/techreborn/tiles/fusionReactor/TileEntityFusionController.java +++ b/src/main/java/techreborn/tiles/fusionReactor/TileEntityFusionController.java @@ -5,10 +5,12 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; import reborncore.api.power.EnumPowerTier; +import reborncore.api.power.tile.IEnergyProducerTile; import reborncore.api.tile.IInventoryProvider; -import reborncore.common.powerSystem.TilePowerAcceptor; -import reborncore.common.tile.TilePowerAcceptorProducer; +import reborncore.common.explosion.RebornExplosion; +import reborncore.common.tile.TilePowerAcceptor; import reborncore.common.util.Inventory; import reborncore.common.util.ItemUtils; import techreborn.api.reactor.FusionReactorRecipe; @@ -16,21 +18,16 @@ import techreborn.api.reactor.FusionReactorRecipeHelper; import techreborn.init.ModBlocks; import techreborn.power.EnergyUtils; -public class TileEntityFusionController extends TilePowerAcceptorProducer implements IInventoryProvider -{ +public class TileEntityFusionController extends TilePowerAcceptor implements IEnergyProducerTile, IInventoryProvider { public Inventory inventory = new Inventory(3, "TileEntityFusionController", 64, this); - // 0= no coils, 1 = coils - public int coilStatus = 0; - public int crafingTickTime = 0; - public int finalTickTime = 0; - public int neededPower = 0; - int topStackSlot = 0; - int bottomStackSlot = 1; - int outputStackSlot = 2; - FusionReactorRecipe currentRecipe = null; - boolean hasStartedCrafting = false; + public boolean hasCoils; + + public int recipeTickTime = 0; + + public FusionReactorRecipe recipe = null; + public boolean repeatSameRecipe = false; @Override public double getMaxPower() { @@ -39,66 +36,54 @@ public class TileEntityFusionController extends TilePowerAcceptorProducer implem @Override public boolean canAcceptEnergy(EnumFacing direction) { - return hasStartedCrafting; + return recipeTickTime == 0; } @Override public boolean canProvideEnergy(EnumFacing direction) { - return !hasStartedCrafting; + return recipeTickTime != 0; } @Override public double getMaxOutput() { - if (!hasStartedCrafting) - { - return 0; - } return 1000000; } @Override - public EnumPowerTier getTier() - { + public EnumPowerTier getTier() { return EnumPowerTier.INSANE; } @Override - public void readFromNBT(NBTTagCompound tagCompound) - { + public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); - crafingTickTime = tagCompound.getInteger("crafingTickTime"); - finalTickTime = tagCompound.getInteger("finalTickTime"); - neededPower = tagCompound.getInteger("neededPower"); - hasStartedCrafting = tagCompound.getBoolean("hasStartedCrafting"); + if(tagCompound.hasKey("recipeTickTime") && checkCoils()) { + ItemStack topInput = ItemStack.loadItemStackFromNBT(tagCompound.getCompoundTag("TopInput")); + ItemStack bottomInput = ItemStack.loadItemStackFromNBT(tagCompound.getCompoundTag("BottomInput")); + FusionReactorRecipe newRecipe = findNewNBTRecipe(topInput, bottomInput); + if(newRecipe != null) { + this.recipeTickTime = tagCompound.getInteger("recipeTickTime"); + this.repeatSameRecipe = tagCompound.getBoolean("repeatSameRecipe"); + this.recipe = newRecipe; + } + } } @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { + public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); + if(recipe != null) { + tagCompound.setTag("TopInput", recipe.getTopInput().writeToNBT(new NBTTagCompound())); + tagCompound.setTag("BottomInput", recipe.getBottomInput().writeToNBT(new NBTTagCompound())); - if (crafingTickTime == -1) - { - crafingTickTime = 0; + tagCompound.setInteger("recipeTickTime", recipeTickTime); + tagCompound.setBoolean("repeatSameRecipe", repeatSameRecipe); } - if (finalTickTime == -1) - { - finalTickTime = 0; - } - if (neededPower == -1) - { - neededPower = 0; - } - tagCompound.setInteger("crafingTickTime", crafingTickTime); - tagCompound.setInteger("finalTickTime", finalTickTime); - tagCompound.setInteger("neededPower", neededPower); - tagCompound.setBoolean("hasStartedCrafting", hasStartedCrafting); return tagCompound; } - public boolean checkCoils() - { + public boolean checkCoils() { if ((isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ() + 1)) && (isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ())) && (isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ() - 1)) @@ -122,211 +107,140 @@ public class TileEntityFusionController extends TilePowerAcceptorProducer implem && (isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() - 2)) && (isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() - 3)) && (isCoil(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ() + 3)) - && (isCoil(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ() - 3))) - { - coilStatus = 1; + && (isCoil(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ() - 3))) { + hasCoils = true; return true; } - coilStatus = 0; + hasCoils = false; return false; } - private boolean isCoil(int x, int y, int z) - { + private boolean isCoil(int x, int y, int z) { return worldObj.getBlockState(new BlockPos(x, y, z)).getBlock() == ModBlocks.FusionCoil; } @Override - public void update() - { + public void update() { super.update(); - // TODO improve this code a lot - if (worldObj.getTotalWorldTime() % 20 == 0) - { - checkCoils(); - } + if (!worldObj.isRemote) { + if (worldObj.getTotalWorldTime() % 20 == 0) { + checkCoils(); + } - if (!worldObj.isRemote) - { - if (coilStatus == 1) - { - if (currentRecipe == null) - { - if (inventory.hasChanged || crafingTickTime != 0) - { - for (FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) - { - if (ItemUtils.isItemEqual(getStackInSlot(topStackSlot), reactorRecipe.getTopInput(), true, - true, true)) - { - if (reactorRecipe.getBottomInput() != null) - { - if (!ItemUtils.isItemEqual(getStackInSlot(bottomStackSlot), - reactorRecipe.getBottomInput(), true, true, true)) - { - break; - } - } - if (canFitStack(reactorRecipe.getOutput(), outputStackSlot, true)) - { - currentRecipe = reactorRecipe; - if (crafingTickTime != 0) - { - finalTickTime = currentRecipe.getTickTime(); - neededPower = (int) currentRecipe.getStartEU(); - } - hasStartedCrafting = false; - crafingTickTime = 0; - finalTickTime = currentRecipe.getTickTime(); - neededPower = (int) currentRecipe.getStartEU(); - break; - } - } - } - } - } else - { - if (inventory.hasChanged) - { - if (!validateRecipe()) - { - resetCrafter(); - return; - } - } - if (!hasStartedCrafting) - { - if (canUseEnergy(currentRecipe.getStartEU() + 64)) - { - useEnergy(currentRecipe.getStartEU()); - hasStartedCrafting = true; - } - } else - { - if (crafingTickTime < currentRecipe.getTickTime()) - { - if (currentRecipe.getEuTick() > 0) - { // Power gen - addEnergy(currentRecipe.getEuTick()); // Waste - // power - // if it - // has - // no - // where - // to go - crafingTickTime++; - } else - { // Power user - if (canUseEnergy(currentRecipe.getEuTick() * -1)) - { - setEnergy(getEnergy() - (currentRecipe.getEuTick() * -1)); - crafingTickTime++; - } - } - } else - { - if (canFitStack(currentRecipe.getOutput(), outputStackSlot, true)) - { - if (getStackInSlot(outputStackSlot) == null) - { - setInventorySlotContents(outputStackSlot, currentRecipe.getOutput().copy()); - } else - { - decrStackSize(outputStackSlot, -currentRecipe.getOutput().stackSize); - } - decrStackSize(topStackSlot, currentRecipe.getTopInput().stackSize); - if (currentRecipe.getBottomInput() != null) - { - decrStackSize(bottomStackSlot, currentRecipe.getBottomInput().stackSize); - } - resetCrafter(); - } - } + if (hasCoils) { + if (recipe == null || inventory.hasChanged) { + FusionReactorRecipe newRecipe = findNewRecipe(); + if (newRecipe != null && newRecipe != recipe) { + this.recipe = newRecipe; + this.repeatSameRecipe = false; + this.recipeTickTime = 0; } } - } else - { - if (currentRecipe != null) - { - resetCrafter(); + + if (recipe != null) { + if (recipeTickTime == 0) { + if (canUseEnergy(recipe.getStartEU())) { + useEnergy(recipe.getStartEU()); + consumeInputStacks(); + ++recipeTickTime; + } + } else if (++recipeTickTime >= recipe.getTickTime()) { + addOutputStack(recipe.getOutput()); + FusionReactorRecipe newRecipe = findNewRecipe(); + if (newRecipe == recipe) { + consumeInputStacks(); + this.repeatSameRecipe = true; + recipeTickTime = 1; + } else { + this.recipe = null; + this.repeatSameRecipe = false; + recipeTickTime = 0; + } + } else { + double euTick = recipe.getEuTick(); + if (euTick > 0) addEnergy(euTick); + else if (useEnergy(-euTick) != euTick) { + this.recipeTickTime = 0; + this.repeatSameRecipe = false; + this.recipe = null; + } + } } } - } - if (inventory.hasChanged) - { - inventory.hasChanged = false; - } - - if (!worldObj.isRemote && getEnergy() > 0 && hasStartedCrafting) { - double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy(); - for(EnumFacing facing : EnumFacing.VALUES) { - double disposed = emitEnergy(facing, maxOutput); - if(disposed != 0) { - maxOutput -= disposed; - useEnergy(disposed); - if (maxOutput == 0) return; + if (!worldObj.isRemote && getEnergy() > 0 && recipeTickTime != 0) { + double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy(); + double disposed = 0; + for(EnumFacing facing : EnumFacing.VALUES) { + if(canProvideEnergy(facing)) { + double emitted = emitEnergy(facing, maxOutput); + maxOutput -= emitted; + disposed += emitted; + } } + if (disposed != 0) + useEnergy(disposed); } } } - //TODO move to RebornCore + public FusionReactorRecipe findNewRecipe() { + for(FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) { + if(canFitStack(reactorRecipe.getOutput(), 2) && + canEmptyStack(reactorRecipe.getTopInput(), 0) && + canEmptyStack(reactorRecipe.getBottomInput(), 1)) { + return reactorRecipe; + } + } + return null; + } + + public FusionReactorRecipe findNewNBTRecipe(ItemStack top, ItemStack bottom) { + for(FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) { + if(canFitStack(reactorRecipe.getOutput(), 2) && + ItemUtils.isItemEqual(top, reactorRecipe.getTopInput(), true, true) && + ItemUtils.isItemEqual(bottom, reactorRecipe.getBottomInput(), true, true)) { + return reactorRecipe; + } + } + return null; + } + + public double emitEnergy(EnumFacing enumFacing, double amount) { BlockPos pos = getPos().offset(enumFacing); EnergyUtils.PowerNetReceiver receiver = EnergyUtils.getReceiver( worldObj, enumFacing.getOpposite(), pos); - if(receiver != null) { + if (receiver != null) { return receiver.receiveEnergy(amount, false); } return 0; } - private boolean validateRecipe() - { - if (ItemUtils.isItemEqual(getStackInSlot(topStackSlot), currentRecipe.getTopInput(), true, true, true)) - { - if (currentRecipe.getBottomInput() != null) - { - if (!ItemUtils.isItemEqual(getStackInSlot(bottomStackSlot), currentRecipe.getBottomInput(), true, true, - true)) - { - return false; - } - } - if (canFitStack(currentRecipe.getOutput(), outputStackSlot, true)) - { - return true; - } - } - return false; + public void consumeInputStacks() { + if(--getStackInSlot(0).stackSize == 0) setInventorySlotContents(0, null); + if(--getStackInSlot(1).stackSize == 0) setInventorySlotContents(1, null); } - private void resetCrafter() - { - currentRecipe = null; - crafingTickTime = -1; - finalTickTime = -1; - neededPower = -1; - hasStartedCrafting = false; + public void addOutputStack(ItemStack output) { + ItemStack stack = getStackInSlot(2); + if(stack == null) setInventorySlotContents(2, output); + else stack.stackSize++; } - public boolean canFitStack(ItemStack stack, int slot, boolean oreDic) - {// Checks to see if it can fit the stack - if (stack == null) - { + public boolean canEmptyStack(ItemStack stack, int slot) { + return inventory.getStackInSlot(slot) != null && + ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true, true); + } + + public boolean canFitStack(ItemStack stack, int slot) { + if (stack == null || inventory.getStackInSlot(slot) == null) { return true; } - if (inventory.getStackInSlot(slot) == null) - { - return true; - } - if (ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true, oreDic)) - { - if (stack.stackSize + inventory.getStackInSlot(slot).stackSize <= stack.getMaxStackSize()) - { + if (ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true, true)) { + if (stack.stackSize + inventory.getStackInSlot(slot).stackSize <= stack.getMaxStackSize()) { return true; } } @@ -334,25 +248,23 @@ public class TileEntityFusionController extends TilePowerAcceptorProducer implem } @Override - public String getName() - { + public String getName() { return "Fusion Reactor"; } @Override - public boolean hasCustomName() - { + public boolean hasCustomName() { return false; } @Override - public ITextComponent getDisplayName() - { - return null; + public ITextComponent getDisplayName() { + return new TextComponentString(getName()); } @Override public Inventory getInventory() { return inventory; } + } diff --git a/src/main/java/techreborn/tiles/idsu/TileIDSU.java b/src/main/java/techreborn/tiles/idsu/TileIDSU.java index ed2cac286..7a12cea2d 100644 --- a/src/main/java/techreborn/tiles/idsu/TileIDSU.java +++ b/src/main/java/techreborn/tiles/idsu/TileIDSU.java @@ -101,19 +101,11 @@ public class TileIDSU extends TilePowerAcceptorProducer implements IWrenchable { if (!worldObj.isRemote && getEnergy() > 0) { double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy(); - for(EnumFacing facing : EnumFacing.VALUES) { - double disposed = emitEnergy(facing, maxOutput); - if(disposed != 0) { - maxOutput -= disposed; - useEnergy(disposed); - if (maxOutput == 0) return; - } - } + double disposed = emitEnergy(getFacingEnum(), maxOutput); + if (maxOutput != 0 && disposed != 0) useEnergy(disposed); } - } - //TODO move to RebornCore public double emitEnergy(EnumFacing enumFacing, double amount) { BlockPos pos = getPos().offset(enumFacing); EnergyUtils.PowerNetReceiver receiver = EnergyUtils.getReceiver( @@ -124,6 +116,16 @@ public class TileIDSU extends TilePowerAcceptorProducer implements IWrenchable { return 0; } + @Override + public boolean canAcceptEnergy(EnumFacing direction) { + return getFacingEnum() != direction; + } + + @Override + public boolean canProvideEnergy(EnumFacing direction) { + return getFacingEnum() == direction; + } + public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) { return false; diff --git a/src/main/java/techreborn/tiles/lesu/TileLesu.java b/src/main/java/techreborn/tiles/lesu/TileLesu.java index afd9bb723..5a3df5ae8 100644 --- a/src/main/java/techreborn/tiles/lesu/TileLesu.java +++ b/src/main/java/techreborn/tiles/lesu/TileLesu.java @@ -72,19 +72,11 @@ public class TileLesu extends TilePowerAcceptorProducer {// TODO wrench if (!worldObj.isRemote && getEnergy() > 0) { double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy(); - for(EnumFacing facing : EnumFacing.VALUES) { - double disposed = emitEnergy(facing, maxOutput); - if(disposed != 0) { - maxOutput -= disposed; - useEnergy(disposed); - if (maxOutput == 0) return; - } - } + double disposed = emitEnergy(getFacingEnum(), maxOutput); + if (maxOutput != 0 && disposed != 0) useEnergy(disposed); } - } - //TODO move to RebornCore public double emitEnergy(EnumFacing enumFacing, double amount) { BlockPos pos = getPos().offset(enumFacing); EnergyUtils.PowerNetReceiver receiver = EnergyUtils.getReceiver( @@ -95,6 +87,16 @@ public class TileLesu extends TilePowerAcceptorProducer {// TODO wrench return 0; } + @Override + public boolean canAcceptEnergy(EnumFacing direction) { + return getFacingEnum() != direction; + } + + @Override + public boolean canProvideEnergy(EnumFacing direction) { + return getFacingEnum() == direction; + } + public double getEuChange() { if (euChange == -1) { diff --git a/src/main/java/techreborn/tiles/storage/TileBatBox.java b/src/main/java/techreborn/tiles/storage/TileBatBox.java index f5af97fac..80ddedd7a 100644 --- a/src/main/java/techreborn/tiles/storage/TileBatBox.java +++ b/src/main/java/techreborn/tiles/storage/TileBatBox.java @@ -9,7 +9,7 @@ import techreborn.init.ModBlocks; public class TileBatBox extends TileEnergyStorage { public TileBatBox() { - super("BatBox", 2, ModBlocks.batBox, EnumPowerTier.LOW, 32, 32, 40000); + super("BatBox", 2, ModBlocks.batBox, EnumPowerTier.LOW, 40000); } } diff --git a/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java b/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java index 51c4b1d09..85591e498 100644 --- a/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java +++ b/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java @@ -9,9 +9,11 @@ import net.minecraft.util.math.BlockPos; import reborncore.api.IListInfoProvider; import reborncore.api.power.EnumPowerTier; import reborncore.api.power.IEnergyItemInfo; +import reborncore.api.power.tile.IEnergyProducerTile; import reborncore.api.tile.IInventoryProvider; import reborncore.common.IWrenchable; import reborncore.common.powerSystem.PoweredItem; +import reborncore.common.tile.TilePowerAcceptor; import reborncore.common.tile.TilePowerAcceptorProducer; import reborncore.common.util.Inventory; import techreborn.blocks.storage.BlockEnergyStorage; @@ -22,23 +24,19 @@ import java.util.List; /** * Created by Rushmead */ -public class TileEnergyStorage extends TilePowerAcceptorProducer implements IWrenchable, ITickable, IInventoryProvider, IListInfoProvider { +public class TileEnergyStorage extends TilePowerAcceptor implements IEnergyProducerTile, IWrenchable, ITickable, IInventoryProvider, IListInfoProvider { public Inventory inventory; public String name; public Block wrenchDrop; public EnumPowerTier tier; - public int maxInput; - public int maxOutput; public int maxStorage; - public TileEnergyStorage(String name, int invSize, Block wrenchDrop, EnumPowerTier tier, int maxInput, int maxOuput, int maxStorage) { + public TileEnergyStorage(String name, int invSize, Block wrenchDrop, EnumPowerTier tier, int maxStorage) { inventory = new Inventory(invSize, "Tile" + name, 64, this); this.wrenchDrop = wrenchDrop; this.tier = tier; this.name = name; - this.maxInput = maxInput; - this.maxOutput = maxOuput; this.maxStorage = maxStorage; } @@ -93,23 +91,13 @@ public class TileEnergyStorage extends TilePowerAcceptorProducer implements IWre } } - - if (!worldObj.isRemote && getEnergy() > 0) { double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy(); - for(EnumFacing facing : EnumFacing.VALUES) { - double disposed = emitEnergy(facing, maxOutput); - if(disposed != 0) { - maxOutput -= disposed; - useEnergy(disposed); - if (maxOutput == 0) return; - } - } + double disposed = emitEnergy(getFacingEnum(), maxOutput); + if (maxOutput != 0 && disposed != 0) useEnergy(disposed); } - } - //TODO move to RebornCore public double emitEnergy(EnumFacing enumFacing, double amount) { BlockPos pos = getPos().offset(enumFacing); EnergyUtils.PowerNetReceiver receiver = EnergyUtils.getReceiver( @@ -120,6 +108,16 @@ public class TileEnergyStorage extends TilePowerAcceptorProducer implements IWre return 0; } + @Override + public boolean canAcceptEnergy(EnumFacing direction) { + return getFacingEnum() != direction; + } + + @Override + public boolean canProvideEnergy(EnumFacing direction) { + return getFacingEnum() == direction; + } + @Override public void setFacing(EnumFacing enumFacing) { worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockEnergyStorage.FACING, enumFacing)); diff --git a/src/main/java/techreborn/tiles/storage/TileMFE.java b/src/main/java/techreborn/tiles/storage/TileMFE.java index 115d9d2ec..9d46ba799 100644 --- a/src/main/java/techreborn/tiles/storage/TileMFE.java +++ b/src/main/java/techreborn/tiles/storage/TileMFE.java @@ -9,7 +9,7 @@ import techreborn.init.ModBlocks; public class TileMFE extends TileEnergyStorage { public TileMFE() { - super("MFE", 2, ModBlocks.mfe, EnumPowerTier.MEDIUM, 512, 512, 4000000); + super("MFE", 2, ModBlocks.mfe, EnumPowerTier.HIGH, 4000000); } } \ No newline at end of file diff --git a/src/main/java/techreborn/tiles/storage/TileMFSU.java b/src/main/java/techreborn/tiles/storage/TileMFSU.java index 81a99c6f0..a3e2feffa 100644 --- a/src/main/java/techreborn/tiles/storage/TileMFSU.java +++ b/src/main/java/techreborn/tiles/storage/TileMFSU.java @@ -9,7 +9,7 @@ import techreborn.init.ModBlocks; public class TileMFSU extends TileEnergyStorage { public TileMFSU() { - super("MFSU", 2, ModBlocks.mfsu, EnumPowerTier.HIGH, 2048, 2048, 40000000); + super("MFSU", 2, ModBlocks.mfsu, EnumPowerTier.EXTREME, 40000000); } } \ No newline at end of file