Fusion Reactor recipe start

This commit is contained in:
drcrazy 2019-08-07 18:17:39 +03:00
parent a2bb34ead0
commit 6d4ea13284
8 changed files with 216 additions and 237 deletions

View file

@ -1,135 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2018 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.api.reactor;
import net.minecraft.item.ItemStack;
public class FusionReactorRecipe {
/**
* This is the item stack that is required in the top slot
* <p>
* This cannot be null
*/
ItemStack topInput;
/**
* This is the item stack that is required in the bottom slot
* <p>
* This can be null
*/
ItemStack bottomInput;
/**
* This is the output stack
* <p>
* This cannot be null
*/
ItemStack output;
/**
* This is the required eu that has to be in the rector for the reaction to
* start
*/
double startEU;
/**
* This is the eu that changes every tick, set as a minus number to use
* power and a positive number to gen power.
*/
double euTick;
/**
* This is the time in ticks that the reaction takes to complete
*/
int tickTime;
/**
* This is the minium reactor size that this recipe can work with
*/
int minSize;
/**
* @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 behavior
*/
public FusionReactorRecipe(ItemStack topInput, ItemStack bottomInput, ItemStack output, double startEU,
double euTick, int tickTime) {
this(topInput, bottomInput, output, startEU, euTick, tickTime, 0);
}
/**
* @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
* @param minSize This is the min size of reactor required for this recipe
*/
public FusionReactorRecipe(ItemStack topInput, ItemStack bottomInput, ItemStack output, double startEU,
double euTick, int tickTime, int minSize) {
this.topInput = topInput;
this.bottomInput = bottomInput;
this.output = output;
this.startEU = startEU;
this.euTick = euTick;
this.tickTime = tickTime;
this.minSize = minSize;
}
public ItemStack getTopInput() {
return topInput;
}
public ItemStack getBottomInput() {
return bottomInput;
}
public ItemStack getOutput() {
return output;
}
public double getStartEU() {
return startEU;
}
public double getEuTick() {
return euTick;
}
public int getTickTime() {
return tickTime;
}
public int getMinSize() {
return minSize;
}
}

View file

@ -1,44 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2018 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.api.reactor;
import java.util.ArrayList;
public class FusionReactorRecipeHelper {
/**
* This is the list of all the recipes
*/
public static ArrayList<FusionReactorRecipe> reactorRecipes = new ArrayList<>();
/**
* Register your reactor recipe here
*
* @param reactorRecipe the recipe you want to add
*/
public static void registerRecipe(FusionReactorRecipe reactorRecipe) {
reactorRecipes.add(reactorRecipe);
}
}

View file

@ -1,3 +1,27 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2018 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.api.recipe.recipes;
import net.minecraft.block.entity.BlockEntity;

View file

@ -0,0 +1,76 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2018 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.api.recipe.recipes;
import com.google.gson.JsonObject;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper;
import reborncore.common.crafting.RebornRecipe;
import reborncore.common.crafting.RebornRecipeType;
import techreborn.blockentity.fusionReactor.FusionControlComputerBlockEntity;
/**
* @author drcrazy
*
*/
public class FusionReactorRecipe extends RebornRecipe {
private int startE;
private int minSize;
public FusionReactorRecipe(RebornRecipeType<?> type, Identifier name) {
super(type, name);
}
public int getStartEnergy () {
return startE;
}
@Override
public void deserialize(JsonObject jsonObject) {
super.deserialize(jsonObject);
startE = JsonHelper.getInt(jsonObject, "start-power");
minSize = JsonHelper.getInt(jsonObject, "min-size");
}
@Override
public void serialize(JsonObject jsonObject) {
super.serialize(jsonObject);
jsonObject.addProperty("start-power", startE);
jsonObject.addProperty("min-size", minSize);
}
@Override
public boolean canCraft(final BlockEntity blockEntity) {
if (blockEntity instanceof FusionControlComputerBlockEntity) {
final FusionControlComputerBlockEntity reactor = (FusionControlComputerBlockEntity) blockEntity;
return reactor.getSize() >= minSize && reactor.getEnergy() >= startE;
}
return false;
}
}

View file

@ -35,6 +35,9 @@ import reborncore.client.containerBuilder.IContainerProvider;
import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.containerBuilder.builder.ContainerBuilder;
import reborncore.common.RebornCoreConfig;
import reborncore.common.crafting.RebornRecipe;
import reborncore.common.crafting.ingredient.RebornIngredient;
import reborncore.common.crafting.ingredient.StackIngredient;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.registration.RebornRegister;
import reborncore.common.registration.config.ConfigRegistry;
@ -42,12 +45,13 @@ import reborncore.common.util.RebornInventory;
import reborncore.common.util.ItemUtils;
import reborncore.common.util.Torus;
import techreborn.TechReborn;
import techreborn.api.reactor.FusionReactorRecipe;
import techreborn.api.reactor.FusionReactorRecipeHelper;
import techreborn.api.recipe.recipes.FusionReactorRecipe;
import techreborn.init.TRContent;
import techreborn.init.ModRecipes;
import techreborn.init.TRBlockEntities;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@RebornRegister(TechReborn.MOD_ID)
public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
@ -163,42 +167,70 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
* Tries to set current recipe based in inputs in reactor
*/
private void updateCurrentRecipe() {
for (final FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
if (validateReactorRecipe(reactorRecipe)) {
currentRecipe = reactorRecipe;
for (RebornRecipe recipe : ModRecipes.FUSION_REACTOR.getRecipes(getWorld())) {
if (recipe.canCraft(this) && validateRecipe((FusionReactorRecipe) recipe)) {
currentRecipe = (FusionReactorRecipe) recipe;
crafingTickTime = 0;
finalTickTime = currentRecipe.getTickTime();
neededPower = (int) currentRecipe.getStartEU();
finalTickTime = currentRecipe.getTime();
neededPower = currentRecipe.getStartEnergy();
hasStartedCrafting = false;
break;
}
}
}
/**
* Validates that reactor can execute recipe provided, e.g. has all inputs and can fit output
* Validates if reactor has all inputs and can output result
*
* @param recipe FusionReactorRecipe Recipe to validate
* @return boolean True if reactor can execute recipe provided
* @param recipe
* @return
*/
private boolean validateReactorRecipe(FusionReactorRecipe recipe) {
boolean validRecipe = validateReactorRecipeInputs(recipe, inventory.getInvStack(topStackSlot), inventory.getInvStack(bottomStackSlot)) || validateReactorRecipeInputs(recipe, inventory.getInvStack(bottomStackSlot), inventory.getInvStack(topStackSlot));
return validRecipe && getSize() >= recipe.getMinSize();
private boolean validateRecipe(FusionReactorRecipe recipe) {
return hasAllInputs(recipe) && canFitStack(recipe.getOutputs().get(0), outputStackSlot, true);
}
private boolean validateReactorRecipeInputs(FusionReactorRecipe recipe, ItemStack slot1, ItemStack slot2) {
if (ItemUtils.isItemEqual(slot1, recipe.getTopInput(), true, true)) {
if (recipe.getBottomInput() != null) {
if (!ItemUtils.isItemEqual(slot2, recipe.getBottomInput(), true, true)) {
return false;
}
/**
* Check if BlockEntity has all necessary inputs for recipe provided
*
* @param recipeType RebornRecipe Recipe to check inputs
* @return Boolean True if reactor has all inputs for recipe
*/
private boolean hasAllInputs(RebornRecipe recipeType) {
if (recipeType == null) {
return false;
}
for (RebornIngredient ingredient : recipeType.getRebornIngredients()) {
boolean hasItem = false;
if (ingredient.test(inventory.getInvStack(topStackSlot))
|| ingredient.test(inventory.getInvStack(bottomStackSlot))) {
hasItem = true;
}
if (canFitStack(recipe.getOutput(), outputStackSlot, true)) {
return true;
if (!hasItem) {
return false;
}
}
return false;
return true;
}
/**
* Decrease stack size on the given slot according to recipe input
*
* @param slot int Slot number
*/
private void useInput(int slot) {
if (currentRecipe == null) {
return;
}
for (RebornIngredient ingredient : currentRecipe.getRebornIngredients()) {
if (ingredient.test(inventory.getInvStack(slot))) {
AtomicInteger count = new AtomicInteger(1);
ingredient.ifType(StackIngredient.class, stackIngredient -> count.set(stackIngredient.getCount()));
inventory.shrinkSlot(slot, count.get());
break;
}
}
}
// TilePowerAcceptor
@Override
@ -231,47 +263,44 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
}
if (currentRecipe != null) {
if (!hasStartedCrafting && inventory.hasChanged() && !validateReactorRecipe(currentRecipe)) {
if (!hasStartedCrafting && inventory.hasChanged() && !validateRecipe(currentRecipe)) {
resetCrafter();
return;
}
if (!hasStartedCrafting) {
// Ignition!
if (canUseEnergy(currentRecipe.getStartEU())) {
useEnergy(currentRecipe.getStartEU());
if (canUseEnergy(currentRecipe.getStartEnergy())) {
useEnergy(currentRecipe.getStartEnergy());
hasStartedCrafting = true;
inventory.shrinkSlot(topStackSlot, currentRecipe.getTopInput().getCount());
if (!currentRecipe.getBottomInput().isEmpty()) {
inventory.shrinkSlot(bottomStackSlot, currentRecipe.getBottomInput().getCount());
}
useInput(topStackSlot);
useInput(bottomStackSlot);
}
}
if (hasStartedCrafting && crafingTickTime < finalTickTime) {
crafingTickTime++;
// Power gen
if (currentRecipe.getEuTick() > 0) {
if (currentRecipe.getPower() > 0) {
// Waste power if it has no where to go
addEnergy(currentRecipe.getEuTick() * getPowerMultiplier());
powerChange = currentRecipe.getEuTick() * getPowerMultiplier();
addEnergy(currentRecipe.getPower() * getPowerMultiplier());
powerChange = currentRecipe.getPower() * getPowerMultiplier();
} else { // Power user
if (canUseEnergy(currentRecipe.getEuTick() * -1)) {
setEnergy(getEnergy() - currentRecipe.getEuTick() * -1);
if (canUseEnergy(currentRecipe.getPower() * -1)) {
setEnergy(getEnergy() - currentRecipe.getPower() * -1);
}
}
} else if (crafingTickTime >= finalTickTime) {
if (canFitStack(currentRecipe.getOutput(), outputStackSlot, true)) {
ItemStack result = currentRecipe.getOutputs().get(0);
if (canFitStack(result, outputStackSlot, true)) {
if (inventory.getInvStack(outputStackSlot).isEmpty()) {
inventory.setInvStack(outputStackSlot, currentRecipe.getOutput().copy());
inventory.setInvStack(outputStackSlot, result.copy());
} else {
inventory.shrinkSlot(outputStackSlot, -currentRecipe.getOutput().getCount());
inventory.shrinkSlot(outputStackSlot, -result.getCount());
}
if (validateReactorRecipe(this.currentRecipe)) {
if (validateRecipe(this.currentRecipe)) {
crafingTickTime = 0;
inventory.shrinkSlot(topStackSlot, currentRecipe.getTopInput().getCount());
if (!currentRecipe.getBottomInput().isEmpty()) {
inventory.shrinkSlot(bottomStackSlot, currentRecipe.getBottomInput().getCount());
}
useInput(topStackSlot);
useInput(bottomStackSlot);
} else {
resetCrafter();
}
@ -329,9 +358,9 @@ public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
this.neededPower = tagCompound.getInt("neededPower");
this.hasStartedCrafting = tagCompound.getBoolean("hasStartedCrafting");
if(tagCompound.containsKey("hasActiveRecipe") && tagCompound.getBoolean("hasActiveRecipe") && this.currentRecipe == null){
for (final FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
if (validateReactorRecipe(reactorRecipe)) {
this.currentRecipe = reactorRecipe;
for (final RebornRecipe reactorRecipe : ModRecipes.FUSION_REACTOR.getRecipes(getWorld())) {
if (validateRecipe((FusionReactorRecipe) reactorRecipe)) {
this.currentRecipe = (FusionReactorRecipe) reactorRecipe;
}
}
}

View file

@ -30,6 +30,7 @@ import reborncore.common.crafting.RebornRecipeType;
import reborncore.common.crafting.RecipeManager;
import techreborn.api.recipe.recipes.BlastFurnaceRecipe;
import techreborn.api.recipe.recipes.FluidReplicatorRecipe;
import techreborn.api.recipe.recipes.FusionReactorRecipe;
import techreborn.api.recipe.recipes.IndustrialGrinderRecipe;
import techreborn.api.recipe.recipes.IndustrialSawmillRecipe;
@ -52,5 +53,6 @@ public class ModRecipes {
public static final RebornRecipeType<RebornRecipe> SCRAPBOX = RecipeManager.newRecipeType(RebornRecipe.class, new Identifier("techreborn:scrapbox"));
public static final RebornRecipeType<RebornRecipe> VACUUM_FREEZER = RecipeManager.newRecipeType(RebornRecipe.class, new Identifier("techreborn:vacuum_freezer"));
public static final RebornRecipeType<FluidReplicatorRecipe> FLUID_REPLICATOR = RecipeManager.newRecipeType(FluidReplicatorRecipe.class, new Identifier("techreborn:fluid_replicator"));
public static final RebornRecipeType<FusionReactorRecipe> FUSION_REACTOR = RecipeManager.newRecipeType(FusionReactorRecipe.class, new Identifier("techreborn:fusion_reactor"));
}

View file

@ -24,13 +24,6 @@
package techreborn.init.recipes;
import net.minecraft.item.ItemStack;
import techreborn.api.reactor.FusionReactorRecipe;
import techreborn.api.reactor.FusionReactorRecipeHelper;
import techreborn.init.ModFluids;
import techreborn.init.TRContent;
import techreborn.items.ItemDynamicCell;
/**
* @author drcrazy
*
@ -38,9 +31,18 @@ import techreborn.items.ItemDynamicCell;
public class FusionReactorRecipes extends RecipeMethods {
public static void init() {
FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemDynamicCell.getCellWithFluid(ModFluids.HELIUM_3.getFluid()), ItemDynamicCell.getCellWithFluid(ModFluids.DEUTERIUM.getFluid()), ItemDynamicCell.getCellWithFluid(ModFluids.HELIUMPLASMA.getFluid()), 40000000, 32768, 1024));
FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemDynamicCell.getCellWithFluid(ModFluids.TRITIUM.getFluid()), ItemDynamicCell.getCellWithFluid(ModFluids.DEUTERIUM.getFluid()), ItemDynamicCell.getCellWithFluid(ModFluids.HELIUM_3.getFluid()), 60000000, 16384, 2048));
FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemDynamicCell.getCellWithFluid(ModFluids.WOLFRAMIUM.getFluid()), ItemDynamicCell.getCellWithFluid(ModFluids.BERYLIUM.getFluid()), TRContent.Dusts.PLATINUM.getStack(), 80000000, -2048, 1024));
FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemDynamicCell.getCellWithFluid(ModFluids.WOLFRAMIUM.getFluid()), ItemDynamicCell.getCellWithFluid(ModFluids.LITHIUM.getFluid()), new ItemStack(TRContent.Ores.IRIDIUM.asItem()), 90000000, -2048, 1024));
// FusionReactorRecipeHelper
// .registerRecipe(new FusionReactorRecipe(ItemDynamicCell.getCellWithFluid(ModFluids.HELIUM_3.getFluid()),
// ItemDynamicCell.getCellWithFluid(ModFluids.DEUTERIUM.getFluid()),
// ItemDynamicCell.getCellWithFluid(ModFluids.HELIUMPLASMA.getFluid()), 40000000, 32768, 1024));
//
// FusionReactorRecipeHelper.registerRecipe(
// new FusionReactorRecipe(ItemDynamicCell.getCellWithFluid(ModFluids.WOLFRAMIUM.getFluid()),
// ItemDynamicCell.getCellWithFluid(ModFluids.BERYLIUM.getFluid()),
// TRContent.Dusts.PLATINUM.getStack(), 80000000, -2048, 1024));
// FusionReactorRecipeHelper.registerRecipe(
// new FusionReactorRecipe(ItemDynamicCell.getCellWithFluid(ModFluids.WOLFRAMIUM.getFluid()),
// ItemDynamicCell.getCellWithFluid(ModFluids.LITHIUM.getFluid()),
// new ItemStack(TRContent.Ores.IRIDIUM.asItem()), 90000000, -2048, 1024));
}
}

View file

@ -0,0 +1,25 @@
{
"type": "techreborn:fusion_reactor",
"power": 16384,
"time": 2048,
"start-power": 1,
"min-size": 1,
"ingredients": [
{
"fluid": "techreborn:tritium",
"holder": "techreborn:cell"
},
{
"fluid": "techreborn:deuterium",
"holder": "techreborn:cell"
}
],
"results": [
{
"item": "techreborn:cell",
"nbt":{
"fluid": "techreborn:helium3"
}
}
]
}