Refactor tank recipes

This commit is contained in:
modmuss50 2019-08-04 18:59:02 +01:00
parent ea91d852af
commit 536de89742
17 changed files with 134 additions and 159 deletions

View file

@ -34,7 +34,7 @@ import techreborn.blockentity.machine.multiblock.IndustrialBlastFurnaceBlockEnti
public class BlastFurnaceRecipe extends RebornRecipe { public class BlastFurnaceRecipe extends RebornRecipe {
int heat; private int heat;
public BlastFurnaceRecipe(RebornRecipeType<?> type, Identifier name) { public BlastFurnaceRecipe(RebornRecipeType<?> type, Identifier name) {
super(type, name); super(type, name);
@ -61,8 +61,4 @@ public class BlastFurnaceRecipe extends RebornRecipe {
return false; return false;
} }
@Override
public boolean onCraft(final BlockEntity blockEntity) {
return true;
}
} }

View file

@ -26,65 +26,32 @@ package techreborn.api.recipe.recipes;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import reborncore.common.crafting.RebornFluidRecipe;
import reborncore.common.crafting.RebornRecipe; import reborncore.common.crafting.RebornRecipe;
import reborncore.common.crafting.RebornRecipeType; import reborncore.common.crafting.RebornRecipeType;
import io.github.prospector.silk.fluid.FluidInstance; import io.github.prospector.silk.fluid.FluidInstance;
import reborncore.common.util.Tank;
import techreborn.blockentity.machine.multiblock.IndustrialGrinderBlockEntity; import techreborn.blockentity.machine.multiblock.IndustrialGrinderBlockEntity;
public class IndustrialGrinderRecipe extends RebornRecipe { public class IndustrialGrinderRecipe extends RebornFluidRecipe {
//TODO 1.14 fluids
FluidInstance fluidStack = null;
public IndustrialGrinderRecipe(RebornRecipeType<?> type, Identifier name) { public IndustrialGrinderRecipe(RebornRecipeType<?> type, Identifier name) {
super(type, name); super(type, name);
} }
@Override @Override
public boolean canCraft(final BlockEntity be) { public Tank getTank(BlockEntity be) {
IndustrialGrinderBlockEntity blockEntity = (IndustrialGrinderBlockEntity) be;
return blockEntity.getTank();
}
@Override
public boolean canCraft(BlockEntity be) {
IndustrialGrinderBlockEntity blockEntity = (IndustrialGrinderBlockEntity) be; IndustrialGrinderBlockEntity blockEntity = (IndustrialGrinderBlockEntity) be;
if (!blockEntity.getMultiBlock()) { if (!blockEntity.getMultiBlock()) {
return false; return false;
} }
final FluidInstance recipeFluid = fluidStack; return super.canCraft(be);
final FluidInstance tankFluid = blockEntity.tank.getFluidInstance();
if (fluidStack == null) {
return true;
}
if (tankFluid == null) {
return false;
}
if (tankFluid.getFluid().equals(recipeFluid.getFluid())) {
if (tankFluid.getAmount() >= recipeFluid.getAmount()) {
return true;
}
}
return false;
} }
@Override
public boolean onCraft(final BlockEntity be) {
IndustrialGrinderBlockEntity blockEntity = (IndustrialGrinderBlockEntity) be;
final FluidInstance recipeFluid = fluidStack;
final FluidInstance tankFluid = blockEntity.tank.getFluidInstance();
if (fluidStack == null) {
return true;
}
if (tankFluid == null) {
return false;
}
if (tankFluid.getFluid().equals(recipeFluid.getFluid())) {
if (tankFluid.getAmount() >= recipeFluid.getAmount()) {
if (tankFluid.getAmount() == recipeFluid.getAmount()) {
blockEntity.tank.setFluid(null);
}
else {
tankFluid.subtractAmount(recipeFluid.getAmount());
}
blockEntity.syncWithAll();
return true;
}
}
return false;
}
} }

View file

@ -24,31 +24,23 @@
package techreborn.api.recipe.recipes; package techreborn.api.recipe.recipes;
import com.google.gson.JsonObject;
import io.github.prospector.silk.fluid.FluidInstance;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.fluid.Fluids;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import reborncore.common.crafting.RebornFluidRecipe;
import javax.annotation.Nonnull;
import reborncore.common.crafting.RebornRecipe;
import reborncore.common.crafting.RebornRecipeType; import reborncore.common.crafting.RebornRecipeType;
import reborncore.common.util.Tank;
import techreborn.blockentity.machine.multiblock.IndustrialSawmillBlockEntity; import techreborn.blockentity.machine.multiblock.IndustrialSawmillBlockEntity;
public class IndustrialSawmillRecipe extends RebornRecipe { public class IndustrialSawmillRecipe extends RebornFluidRecipe {
@Nonnull
private FluidInstance fluidInstance = FluidInstance.EMPTY;
public IndustrialSawmillRecipe(RebornRecipeType<?> type, Identifier name) { public IndustrialSawmillRecipe(RebornRecipeType<?> type, Identifier name) {
super(type, name); super(type, name);
} }
@Override @Override
public void deserialize(JsonObject jsonObject) { public Tank getTank(BlockEntity be) {
super.deserialize(jsonObject); IndustrialSawmillBlockEntity blockEntity = (IndustrialSawmillBlockEntity) be;
fluidInstance = new FluidInstance(Fluids.WATER, 1000); return blockEntity.getTank();
} }
@Override @Override
@ -57,39 +49,7 @@ public class IndustrialSawmillRecipe extends RebornRecipe {
if (!blockEntity.getMutliBlock()) { if (!blockEntity.getMutliBlock()) {
return false; return false;
} }
final FluidInstance recipeFluid = fluidInstance; return super.canCraft(be);
final FluidInstance tankFluid = blockEntity.tank.getFluidInstance();
if (fluidInstance.isEmpty()) {
return true;
}
if (tankFluid.isEmpty()) {
return false;
}
if (tankFluid.getFluid().equals(recipeFluid.getFluid())) {
if (tankFluid.getAmount() >= recipeFluid.getAmount()) {
return true;
}
}
return false;
} }
@Override
public boolean onCraft(BlockEntity be) {
IndustrialSawmillBlockEntity blockEntity = (IndustrialSawmillBlockEntity) be;
final FluidInstance recipeFluid = fluidInstance;
final FluidInstance tankFluid = blockEntity.tank.getFluidInstance();
if (fluidInstance.isEmpty()) {
return true;
}
if (tankFluid.isEmpty()) {
return false;
}
if (tankFluid.getFluid().equals(recipeFluid.getFluid())) {
if (tankFluid.getAmount() >= recipeFluid.getAmount()) {
tankFluid.subtractAmount(recipeFluid.getAmount());
return true;
}
}
return false;
}
} }

View file

@ -2,6 +2,10 @@
"type": "techreborn:industrial_sawmill", "type": "techreborn:industrial_sawmill",
"power": 128, "power": 128,
"time": 100, "time": 100,
"tank" : {
"fluid": "minecraft:water",
"amount": 1000
},
"ingredients": [ "ingredients": [
{ {
"item": "minecraft:acacia_log" "item": "minecraft:acacia_log"

View file

@ -2,6 +2,10 @@
"type": "techreborn:industrial_sawmill", "type": "techreborn:industrial_sawmill",
"power": 128, "power": 128,
"time": 100, "time": 100,
"tank" : {
"fluid": "minecraft:water",
"amount": 1000
},
"ingredients": [ "ingredients": [
{ {
"item": "minecraft:stripped_acacia_log" "item": "minecraft:stripped_acacia_log"

View file

@ -2,6 +2,10 @@
"type": "techreborn:industrial_sawmill", "type": "techreborn:industrial_sawmill",
"power": 128, "power": 128,
"time": 100, "time": 100,
"tank" : {
"fluid": "minecraft:water",
"amount": 1000
},
"ingredients": [ "ingredients": [
{ {
"item": "minecraft:birch_log" "item": "minecraft:birch_log"

View file

@ -2,6 +2,10 @@
"type": "techreborn:industrial_sawmill", "type": "techreborn:industrial_sawmill",
"power": 128, "power": 128,
"time": 100, "time": 100,
"tank" : {
"fluid": "minecraft:water",
"amount": 1000
},
"ingredients": [ "ingredients": [
{ {
"item": "minecraft:stripped_birch_log" "item": "minecraft:stripped_birch_log"

View file

@ -2,6 +2,10 @@
"type": "techreborn:industrial_sawmill", "type": "techreborn:industrial_sawmill",
"power": 128, "power": 128,
"time": 100, "time": 100,
"tank" : {
"fluid": "minecraft:water",
"amount": 1000
},
"ingredients": [ "ingredients": [
{ {
"item": "minecraft:dark_oak_log" "item": "minecraft:dark_oak_log"

View file

@ -2,6 +2,10 @@
"type": "techreborn:industrial_sawmill", "type": "techreborn:industrial_sawmill",
"power": 128, "power": 128,
"time": 100, "time": 100,
"tank" : {
"fluid": "minecraft:water",
"amount": 1000
},
"ingredients": [ "ingredients": [
{ {
"item": "minecraft:stripped_dark_oak_log" "item": "minecraft:stripped_dark_oak_log"

View file

@ -2,6 +2,10 @@
"type": "techreborn:industrial_sawmill", "type": "techreborn:industrial_sawmill",
"power": 128, "power": 128,
"time": 100, "time": 100,
"tank" : {
"fluid": "minecraft:water",
"amount": 1000
},
"ingredients": [ "ingredients": [
{ {
"item": "minecraft:jungle_log" "item": "minecraft:jungle_log"

View file

@ -2,6 +2,10 @@
"type": "techreborn:industrial_sawmill", "type": "techreborn:industrial_sawmill",
"power": 128, "power": 128,
"time": 100, "time": 100,
"tank" : {
"fluid": "minecraft:water",
"amount": 1000
},
"ingredients": [ "ingredients": [
{ {
"item": "minecraft:stripped_jungle_log" "item": "minecraft:stripped_jungle_log"

View file

@ -2,6 +2,10 @@
"type": "techreborn:industrial_sawmill", "type": "techreborn:industrial_sawmill",
"power": 128, "power": 128,
"time": 100, "time": 100,
"tank" : {
"fluid": "minecraft:water",
"amount": 1000
},
"ingredients": [ "ingredients": [
{ {
"item": "minecraft:oak_log" "item": "minecraft:oak_log"

View file

@ -2,6 +2,10 @@
"type": "techreborn:industrial_sawmill", "type": "techreborn:industrial_sawmill",
"power": 128, "power": 128,
"time": 100, "time": 100,
"tank" : {
"fluid": "minecraft:water",
"amount": 1000
},
"ingredients": [ "ingredients": [
{ {
"item": "minecraft:stripped_oak_log" "item": "minecraft:stripped_oak_log"

View file

@ -2,6 +2,10 @@
"type": "techreborn:industrial_sawmill", "type": "techreborn:industrial_sawmill",
"power": 128, "power": 128,
"time": 100, "time": 100,
"tank" : {
"fluid": "minecraft:water",
"amount": 1000
},
"ingredients": [ "ingredients": [
{ {
"item": "techreborn:rubber_log" "item": "techreborn:rubber_log"

View file

@ -2,6 +2,10 @@
"type": "techreborn:industrial_sawmill", "type": "techreborn:industrial_sawmill",
"power": 128, "power": 128,
"time": 100, "time": 100,
"tank" : {
"fluid": "minecraft:water",
"amount": 1000
},
"ingredients": [ "ingredients": [
{ {
"item": "minecraft:spruce_log" "item": "minecraft:spruce_log"

View file

@ -2,6 +2,10 @@
"type": "techreborn:industrial_sawmill", "type": "techreborn:industrial_sawmill",
"power": 128, "power": 128,
"time": 100, "time": 100,
"tank" : {
"fluid": "minecraft:water",
"amount": 1000
},
"ingredients": [ "ingredients": [
{ {
"item": "minecraft:stripped_spruce_log" "item": "minecraft:stripped_spruce_log"