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

@ -1,63 +1,63 @@
/* /*
* This file is part of TechReborn, licensed under the MIT License (MIT). * This file is part of TechReborn, licensed under the MIT License (MIT).
* *
* Copyright (c) 2018 TechReborn * Copyright (c) 2018 TechReborn
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in all * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. * copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * 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 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
package techreborn.blocks; package techreborn.blocks;
import java.util.function.Supplier; import java.util.function.Supplier;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import reborncore.api.blockentity.IMachineGuiHandler; import reborncore.api.blockentity.IMachineGuiHandler;
import reborncore.common.blocks.BlockMachineBase; import reborncore.common.blocks.BlockMachineBase;
import techreborn.client.EGui; import techreborn.client.EGui;
/** /**
* @author drcrazy * @author drcrazy
* *
*/ */
public class GenericMachineBlock extends BlockMachineBase { public class GenericMachineBlock extends BlockMachineBase {
private EGui gui; private EGui gui;
private Supplier<BlockEntity> blockEntityClass; private Supplier<BlockEntity> blockEntityClass;
public GenericMachineBlock(EGui gui, Supplier<BlockEntity> blockEntityClass) { public GenericMachineBlock(EGui gui, Supplier<BlockEntity> blockEntityClass) {
super(); super();
this.blockEntityClass = blockEntityClass; this.blockEntityClass = blockEntityClass;
this.gui = gui; this.gui = gui;
} }
@Override @Override
public BlockEntity createBlockEntity(BlockView worldIn) { public BlockEntity createBlockEntity(BlockView worldIn) {
if (blockEntityClass == null) { if (blockEntityClass == null) {
return null; return null;
} }
return blockEntityClass.get(); return blockEntityClass.get();
} }
@Override @Override
public IMachineGuiHandler getGui() { public IMachineGuiHandler getGui() {
return gui; return gui;
} }
} }

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"