diff --git a/src/main/java/techreborn/api/reactor/FusionReactorRecipe.java b/src/main/java/techreborn/api/reactor/FusionReactorRecipe.java index 16576eb17..de6bd2f8d 100644 --- a/src/main/java/techreborn/api/reactor/FusionReactorRecipe.java +++ b/src/main/java/techreborn/api/reactor/FusionReactorRecipe.java @@ -41,6 +41,15 @@ public class FusionReactorRecipe { */ int tickTime; + /** + * + * @param topInput This is the top slot stack + * @param bottomInput This is the bottom slot stack + * @param output This is the output stack + * @param startEU This is the inital EU amount + * @param euTick This is the eu that is transfured every tick + * @param tickTime This is the time the recipe takes to process + */ public FusionReactorRecipe(ItemStack topInput, ItemStack bottomInput, ItemStack output, double startEU, double euTick, int tickTime) { this.topInput = topInput; this.bottomInput = bottomInput; diff --git a/src/main/java/techreborn/client/container/ContainerFusionReactor.java b/src/main/java/techreborn/client/container/ContainerFusionReactor.java index 053cd0a30..a866996ce 100644 --- a/src/main/java/techreborn/client/container/ContainerFusionReactor.java +++ b/src/main/java/techreborn/client/container/ContainerFusionReactor.java @@ -14,6 +14,9 @@ public class ContainerFusionReactor extends RebornContainer { public int coilStatus; public int energy; + public int tickTime; + public int finalTickTime; + public int neededEU; TileEntityFusionController fusionController; @@ -58,6 +61,15 @@ public class ContainerFusionReactor extends RebornContainer { if (this.energy != (int) fusionController.getEnergy()) { icrafting.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy()); } + if (this.tickTime != fusionController.crafingTickTime) { + icrafting.sendProgressBarUpdate(this, 2, fusionController.crafingTickTime); + } + if (this.finalTickTime != fusionController.finalTickTime) { + icrafting.sendProgressBarUpdate(this, 3, fusionController.finalTickTime); + } + if (this.neededEU != fusionController.neededPower) { + icrafting.sendProgressBarUpdate(this, 4, fusionController.neededPower); + } } } @@ -66,6 +78,9 @@ public class ContainerFusionReactor extends RebornContainer { super.addCraftingToCrafters(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); } @SideOnly(Side.CLIENT) @@ -75,6 +90,16 @@ public class ContainerFusionReactor extends RebornContainer { 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; } } + + 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 b62fcc8d6..99d66a884 100644 --- a/src/main/java/techreborn/client/gui/GuiFusionReactor.java +++ b/src/main/java/techreborn/client/gui/GuiFusionReactor.java @@ -28,6 +28,8 @@ public class GuiFusionReactor extends GuiContainer { this.fontRendererObj.drawString("EU: " + containerFusionReactor.energy, 11, 8, 16448255); this.fontRendererObj.drawString("Coils: " + (containerFusionReactor.coilStatus == 1 ? "Yes" : "No") , 11, 16, 16448255); + this.fontRendererObj.drawString("Start EU: " + containerFusionReactor.neededEU, 11, 24, 16448255); + } @Override @@ -40,7 +42,7 @@ public class GuiFusionReactor extends GuiContainer { drawTexturedModalRect(k + 88, l + 36, 176, 0, 14, 14); //progressBar - drawTexturedModalRect(k + 111, l + 34, 176, 14, 24, 16); + drawTexturedModalRect(k + 111, l + 34, 176, 14, containerFusionReactor.getProgressScaled(), 16); } } diff --git a/src/main/java/techreborn/compat/recipes/RecipesIC2.java b/src/main/java/techreborn/compat/recipes/RecipesIC2.java index 5d428021e..45d27e226 100644 --- a/src/main/java/techreborn/compat/recipes/RecipesIC2.java +++ b/src/main/java/techreborn/compat/recipes/RecipesIC2.java @@ -23,6 +23,8 @@ import reborncore.common.util.CraftingHelper; import reborncore.common.util.OreUtil; import reborncore.common.util.RecipeRemover; import techreborn.Core; +import techreborn.api.reactor.FusionReactorRecipe; +import techreborn.api.reactor.FusionReactorRecipeHelper; import techreborn.api.recipe.RecipeHandler; import techreborn.api.recipe.machines.*; import techreborn.compat.ICompatModule; @@ -51,6 +53,8 @@ public class RecipesIC2 implements ICompatModule { addTRThermalCentrifugeRecipes(); addMetalFormerRecipes(); addTRRecipes(); + + FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("wolframium"), ItemCells.getCellByName("lithium"), IC2Items.getItem("iridiumOre"), 90000000, -2048, 1024)); } @Override diff --git a/src/main/java/techreborn/init/ModRecipes.java b/src/main/java/techreborn/init/ModRecipes.java index c5359cde9..e97243edc 100644 --- a/src/main/java/techreborn/init/ModRecipes.java +++ b/src/main/java/techreborn/init/ModRecipes.java @@ -12,6 +12,8 @@ import reborncore.common.util.CraftingHelper; import reborncore.common.util.OreUtil; import techreborn.Core; import techreborn.api.TechRebornAPI; +import techreborn.api.reactor.FusionReactorRecipe; +import techreborn.api.reactor.FusionReactorRecipeHelper; import techreborn.api.recipe.RecipeHandler; import techreborn.api.recipe.machines.*; import techreborn.blocks.BlockOre; @@ -45,6 +47,14 @@ public class addBlastFurnaceRecipes(); addIndustrialGrinderRecipes(); addImplosionCompressorRecipes(); + addReactorRecipes(); + } + + static void addReactorRecipes(){ + + FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("tritium"), ItemCells.getCellByName("deuterium"), ItemCells.getCellByName("helium"), 40000000, 32768, 1024)); + FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("tritium"), ItemCells.getCellByName("deuterium"), ItemCells.getCellByName("helium3"), 60000000, 32768, 2048)); + FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("wolframium"), ItemCells.getCellByName("Berylium"), ItemDusts.getDustByName("platinum"), 80000000, -2048, 1024)); } static void addGeneralShapedRecipes() { @@ -245,8 +255,6 @@ public class 'P', "plateCopper" ); - GameRegistry.addShapelessRecipe(ItemCells.getCellByName("heliumPlasma"), ItemCells.getCellByName("tritium"), ItemCells.getCellByName("deuterium")); - Core.logHelper.info("Shapped Recipes Added"); } diff --git a/src/main/java/techreborn/tiles/fusionReactor/TileEntityFusionController.java b/src/main/java/techreborn/tiles/fusionReactor/TileEntityFusionController.java index b3b709d8c..52bb2aaa0 100644 --- a/src/main/java/techreborn/tiles/fusionReactor/TileEntityFusionController.java +++ b/src/main/java/techreborn/tiles/fusionReactor/TileEntityFusionController.java @@ -6,6 +6,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import reborncore.common.util.Inventory; +import reborncore.common.util.ItemUtils; +import techreborn.api.reactor.FusionReactorRecipe; +import techreborn.api.reactor.FusionReactorRecipeHelper; import techreborn.init.ModBlocks; import techreborn.powerSystem.TilePowerAcceptor; @@ -17,6 +20,17 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn //0= no coils, 1 = coils public int coilStatus = 0; + int topStackSlot = 0; + int bottomStackSlot = 1; + int outputStackSlot = 2; + + public int crafingTickTime = 0; + public int finalTickTime = 0; + public int neededPower = 0; + + FusionReactorRecipe currentRecipe = null; + boolean hasStartedCrafting = false; + public TileEntityFusionController() { super(4); } @@ -164,5 +178,115 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn if(worldObj.getTotalWorldTime() % 20 == 0){ checkCoils(); } + +if(!worldObj.isRemote){ + if(coilStatus == 1){ + if(currentRecipe == null){ + if(inventory.hasChanged){ + for(FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes){ + System.out.println(getStackInSlot(topStackSlot) + "@" + reactorRecipe.getTopInput()); + if(ItemUtils.isItemEqual(getStackInSlot(topStackSlot), reactorRecipe.getTopInput(), true, true, true)){ + if(reactorRecipe.getBottomInput() != null){ + if(ItemUtils.isItemEqual(getStackInSlot(bottomStackSlot), reactorRecipe.getBottomInput(), true, true, true) == false){ + break; + } + } + if(canFitStack(reactorRecipe.getOutput(), outputStackSlot, true)){ + currentRecipe = reactorRecipe; + hasStartedCrafting = false; + crafingTickTime = 0; + finalTickTime = currentRecipe.getTickTime(); + neededPower = (int) currentRecipe.getStartEU(); + break; + } + } + } + } + } else { + if(inventory.hasChanged){ + if(!validateRecipe()){ + resetCrafter(); + } + } + if(!hasStartedCrafting){ + if(canUseEnergy(currentRecipe.getStartEU())){ + setEnergy(getEnergy() - 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(); + } + } + } + } + } else { + if(currentRecipe != null){ + resetCrafter(); + } + } +} + + + if (inventory.hasChanged) { + inventory.hasChanged = false; + } + } + + 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) == false){ + return false; + } + } + if(canFitStack(currentRecipe.getOutput(), outputStackSlot, true)){ + return true; + } + } + return false; + } + + private void resetCrafter(){ + currentRecipe = null; + crafingTickTime = 0; + finalTickTime = 0; + neededPower = 0; + hasStartedCrafting = false; + } + + public boolean canFitStack(ItemStack stack, int slot, boolean oreDic) {//Checks to see if it can fit the stack + if (stack == 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()) { + return true; + } + } + return false; } }