Keep state for running reactor. Closes #1187

This commit is contained in:
drcrazy 2017-10-02 18:38:47 +03:00
parent 1c57bd0100
commit 0ae99ebae8
3 changed files with 123 additions and 98 deletions

View file

@ -39,8 +39,6 @@ import reborncore.common.util.ItemUtils;
import reborncore.common.util.OreUtil; import reborncore.common.util.OreUtil;
import reborncore.common.util.RebornCraftingHelper; import reborncore.common.util.RebornCraftingHelper;
import techreborn.Core; import techreborn.Core;
import techreborn.api.reactor.FusionReactorRecipe;
import techreborn.api.reactor.FusionReactorRecipeHelper;
import techreborn.api.recipe.machines.*; import techreborn.api.recipe.machines.*;
import techreborn.blocks.BlockOre; import techreborn.blocks.BlockOre;
import techreborn.compat.CompatManager; import techreborn.compat.CompatManager;
@ -78,11 +76,11 @@ public class ModRecipes {
ImplosionCompressorRecipes.init(); ImplosionCompressorRecipes.init();
ScrapboxRecipes.init(); ScrapboxRecipes.init();
ChemicalReactorRecipes.init(); ChemicalReactorRecipes.init();
FusionReactorRecipes.init();
addAlloySmelterRecipes(); addAlloySmelterRecipes();
addBlastFurnaceRecipes(); addBlastFurnaceRecipes();
addVacuumFreezerRecipes(); addVacuumFreezerRecipes();
addReactorRecipes();
addIc2Recipes(); addIc2Recipes();
addGrinderRecipes(); addGrinderRecipes();
addCompressorRecipes(); addCompressorRecipes();
@ -246,21 +244,6 @@ public class ModRecipes {
} }
} }
static void addReactorRecipes() {
FusionReactorRecipeHelper.registerRecipe(
new FusionReactorRecipe(ItemCells.getCellByName("helium3"), ItemCells.getCellByName("deuterium"),
ItemCells.getCellByName("heliumplasma"), 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));
FusionReactorRecipeHelper.registerRecipe(
new FusionReactorRecipe(ItemCells.getCellByName("wolframium"), ItemCells.getCellByName("lithium"),
BlockOre.getOreByName("iridium"), 90000000, -2048, 1024));
}
static void addVacuumFreezerRecipes() { static void addVacuumFreezerRecipes() {
RecipeHandler.addRecipe(new VacuumFreezerRecipe( RecipeHandler.addRecipe(new VacuumFreezerRecipe(
new ItemStack(Blocks.ICE, 2), new ItemStack(Blocks.ICE, 2),

View file

@ -0,0 +1,52 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2017 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.init.recipes;
import techreborn.api.reactor.FusionReactorRecipe;
import techreborn.api.reactor.FusionReactorRecipeHelper;
import techreborn.blocks.BlockOre;
import techreborn.items.ItemCells;
import techreborn.items.ItemDusts;
/**
* @author drcrazy
*
*/
public class FusionReactorRecipes extends RecipeMethods {
public static void init(){
FusionReactorRecipeHelper.registerRecipe(
new FusionReactorRecipe(ItemCells.getCellByName("helium3"), ItemCells.getCellByName("deuterium"),
ItemCells.getCellByName("heliumplasma"), 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));
FusionReactorRecipeHelper.registerRecipe(
new FusionReactorRecipe(ItemCells.getCellByName("wolframium"), ItemCells.getCellByName("lithium"),
BlockOre.getOreByName("iridium"), 90000000, -2048, 1024));
}
}

View file

@ -173,87 +173,77 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IInv
public void update() { public void update() {
super.update(); super.update();
// TODO improve this code a lot // TODO improve this code a lot
if (this.world.isRemote) {
return;
}
if (this.world.getTotalWorldTime() % 20 == 0) { if (this.world.getTotalWorldTime() % 20 == 0) {
this.checkCoils(); this.checkCoils();
} }
if (!this.world.isRemote) { if (this.coilStatus == 0) {
if (this.coilStatus == 1) { this.resetCrafter();
if (this.currentRecipe == null) { return;
if (this.inventory.hasChanged || this.crafingTickTime != 0) { }
for (final FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
if (ItemUtils.isItemEqual(this.getStackInSlot(this.topStackSlot), reactorRecipe.getTopInput(), true, if (this.currentRecipe == null && this.inventory.hasChanged){
true, true)) { this.crafingTickTime = 0;
if (reactorRecipe.getBottomInput() != null) { for (final FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
if (!ItemUtils.isItemEqual(this.getStackInSlot(this.bottomStackSlot), if (this.validateRecipe(reactorRecipe)){
reactorRecipe.getBottomInput(), true, true, true)) { this.currentRecipe = reactorRecipe;
break; this.finalTickTime = this.currentRecipe.getTickTime();
} this.neededPower = (int) this.currentRecipe.getStartEU();
} this.hasStartedCrafting = false;
if (this.canFitStack(reactorRecipe.getOutput(), this.outputStackSlot, true)) { break;
this.currentRecipe = reactorRecipe; }
if (this.crafingTickTime != 0) { }
this.finalTickTime = this.currentRecipe.getTickTime(); }
this.neededPower = (int) this.currentRecipe.getStartEU(); else {
} if (this.inventory.hasChanged) {
this.hasStartedCrafting = false; if (!this.validateRecipe(this.currentRecipe)) {
this.crafingTickTime = 0; this.resetCrafter();
this.finalTickTime = this.currentRecipe.getTickTime(); return;
this.neededPower = (int) this.currentRecipe.getStartEU(); }
break; }
} }
}
} if (this.currentRecipe != null) {
} if (!this.hasStartedCrafting) {
} else { // Ignition!
if (this.inventory.hasChanged) { if (this.canUseEnergy(this.currentRecipe.getStartEU())) {
if (!this.validateRecipe()) { this.useEnergy(this.currentRecipe.getStartEU());
this.resetCrafter(); this.hasStartedCrafting = true;
return; }
} }
} if (this.crafingTickTime < this.finalTickTime) {
if (!this.hasStartedCrafting) { this.crafingTickTime++;
if (this.canUseEnergy(this.currentRecipe.getStartEU() + 64)) { // Power gen
this.useEnergy(this.currentRecipe.getStartEU()); if (this.currentRecipe.getEuTick() > 0) {
this.hasStartedCrafting = true; // Waste power if it has no where to go
} this.addEnergy(this.currentRecipe.getEuTick());
} else { } else { // Power user
if (this.crafingTickTime < this.currentRecipe.getTickTime()) { if (this.canUseEnergy(this.currentRecipe.getEuTick() * -1)) {
if (this.currentRecipe.getEuTick() > 0) { // Power gen this.setEnergy(this.getEnergy() - this.currentRecipe.getEuTick() * -1);
this.addEnergy(this.currentRecipe.getEuTick()); // Waste
// power
// if it
// has
// no
// where
// to go
this.crafingTickTime++;
} else { // Power user
if (this.canUseEnergy(this.currentRecipe.getEuTick() * -1)) {
this.setEnergy(this.getEnergy() - this.currentRecipe.getEuTick() * -1);
this.crafingTickTime++;
}
}
} else {
if (this.canFitStack(this.currentRecipe.getOutput(), this.outputStackSlot, true)) {
if (this.getStackInSlot(this.outputStackSlot) == ItemStack.EMPTY) {
this.setInventorySlotContents(this.outputStackSlot, this.currentRecipe.getOutput().copy());
} else {
this.decrStackSize(this.outputStackSlot, -this.currentRecipe.getOutput().getCount());
}
this.decrStackSize(this.topStackSlot, this.currentRecipe.getTopInput().getCount());
if (this.currentRecipe.getBottomInput() != ItemStack.EMPTY) {
this.decrStackSize(this.bottomStackSlot, this.currentRecipe.getBottomInput().getCount());
}
this.resetCrafter();
}
}
} }
} }
} else { } else if (this.crafingTickTime >= this.finalTickTime) {
if (this.currentRecipe != null) { if (this.canFitStack(this.currentRecipe.getOutput(), this.outputStackSlot, true)) {
this.resetCrafter(); if (this.getStackInSlot(this.outputStackSlot).isEmpty()) {
this.setInventorySlotContents(this.outputStackSlot, this.currentRecipe.getOutput().copy());
} else {
this.decrStackSize(this.outputStackSlot, -this.currentRecipe.getOutput().getCount());
}
this.decrStackSize(this.topStackSlot, this.currentRecipe.getTopInput().getCount());
if (!this.currentRecipe.getBottomInput().isEmpty()) {
this.decrStackSize(this.bottomStackSlot, this.currentRecipe.getBottomInput().getCount());
}
if (this.validateRecipe(this.currentRecipe)){
this.crafingTickTime = 0;
}
else {
this.resetCrafter();
}
} }
} }
} }
@ -263,15 +253,15 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IInv
} }
} }
private boolean validateRecipe() { private boolean validateRecipe(FusionReactorRecipe recipe) {
if (ItemUtils.isItemEqual(this.getStackInSlot(this.topStackSlot), this.currentRecipe.getTopInput(), true, true, true)) { if (ItemUtils.isItemEqual(this.getStackInSlot(this.topStackSlot), recipe.getTopInput(), true, true, true)) {
if (this.currentRecipe.getBottomInput() != null) { if (recipe.getBottomInput() != null) {
if (!ItemUtils.isItemEqual(this.getStackInSlot(this.bottomStackSlot), this.currentRecipe.getBottomInput(), true, true, if (!ItemUtils.isItemEqual(this.getStackInSlot(this.bottomStackSlot), recipe.getBottomInput(), true, true,
true)) { true)) {
return false; return false;
} }
} }
if (this.canFitStack(this.currentRecipe.getOutput(), this.outputStackSlot, true)) { if (this.canFitStack(recipe.getOutput(), this.outputStackSlot, true)) {
return true; return true;
} }
} }
@ -290,7 +280,7 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IInv
if (stack.isEmpty()) { if (stack.isEmpty()) {
return true; return true;
} }
if (this.inventory.getStackInSlot(slot) == ItemStack.EMPTY) { if (this.inventory.getStackInSlot(slot).isEmpty()) {
return true; return true;
} }
if (ItemUtils.isItemEqual(this.inventory.getStackInSlot(slot), stack, true, true, oreDic)) { if (ItemUtils.isItemEqual(this.inventory.getStackInSlot(slot), stack, true, true, oreDic)) {