Refactor tank recipes
This commit is contained in:
parent
ea91d852af
commit
536de89742
17 changed files with 134 additions and 159 deletions
|
@ -34,7 +34,7 @@ import techreborn.blockentity.machine.multiblock.IndustrialBlastFurnaceBlockEnti
|
|||
|
||||
public class BlastFurnaceRecipe extends RebornRecipe {
|
||||
|
||||
int heat;
|
||||
private int heat;
|
||||
|
||||
public BlastFurnaceRecipe(RebornRecipeType<?> type, Identifier name) {
|
||||
super(type, name);
|
||||
|
@ -61,8 +61,4 @@ public class BlastFurnaceRecipe extends RebornRecipe {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCraft(final BlockEntity blockEntity) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,65 +26,32 @@ package techreborn.api.recipe.recipes;
|
|||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import reborncore.common.crafting.RebornFluidRecipe;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.crafting.RebornRecipeType;
|
||||
import io.github.prospector.silk.fluid.FluidInstance;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.blockentity.machine.multiblock.IndustrialGrinderBlockEntity;
|
||||
|
||||
public class IndustrialGrinderRecipe extends RebornRecipe {
|
||||
|
||||
//TODO 1.14 fluids
|
||||
FluidInstance fluidStack = null;
|
||||
public class IndustrialGrinderRecipe extends RebornFluidRecipe {
|
||||
|
||||
public IndustrialGrinderRecipe(RebornRecipeType<?> type, Identifier name) {
|
||||
super(type, name);
|
||||
}
|
||||
|
||||
@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;
|
||||
if (!blockEntity.getMultiBlock()) {
|
||||
return false;
|
||||
}
|
||||
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()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return super.canCraft(be);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,31 +24,23 @@
|
|||
|
||||
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.fluid.Fluids;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.crafting.RebornFluidRecipe;
|
||||
import reborncore.common.crafting.RebornRecipeType;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.blockentity.machine.multiblock.IndustrialSawmillBlockEntity;
|
||||
|
||||
public class IndustrialSawmillRecipe extends RebornRecipe {
|
||||
|
||||
@Nonnull
|
||||
private FluidInstance fluidInstance = FluidInstance.EMPTY;
|
||||
public class IndustrialSawmillRecipe extends RebornFluidRecipe {
|
||||
|
||||
public IndustrialSawmillRecipe(RebornRecipeType<?> type, Identifier name) {
|
||||
super(type, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(JsonObject jsonObject) {
|
||||
super.deserialize(jsonObject);
|
||||
fluidInstance = new FluidInstance(Fluids.WATER, 1000);
|
||||
public Tank getTank(BlockEntity be) {
|
||||
IndustrialSawmillBlockEntity blockEntity = (IndustrialSawmillBlockEntity) be;
|
||||
return blockEntity.getTank();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,39 +49,7 @@ public class IndustrialSawmillRecipe extends RebornRecipe {
|
|||
if (!blockEntity.getMutliBlock()) {
|
||||
return false;
|
||||
}
|
||||
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()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return super.canCraft(be);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,63 +1,63 @@
|
|||
/*
|
||||
* 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.blocks;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.world.BlockView;
|
||||
import reborncore.api.blockentity.IMachineGuiHandler;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import techreborn.client.EGui;
|
||||
|
||||
/**
|
||||
* @author drcrazy
|
||||
*
|
||||
*/
|
||||
public class GenericMachineBlock extends BlockMachineBase {
|
||||
|
||||
private EGui gui;
|
||||
private Supplier<BlockEntity> blockEntityClass;
|
||||
|
||||
public GenericMachineBlock(EGui gui, Supplier<BlockEntity> blockEntityClass) {
|
||||
super();
|
||||
this.blockEntityClass = blockEntityClass;
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockView worldIn) {
|
||||
if (blockEntityClass == null) {
|
||||
return null;
|
||||
}
|
||||
return blockEntityClass.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMachineGuiHandler getGui() {
|
||||
return gui;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* 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.blocks;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.world.BlockView;
|
||||
import reborncore.api.blockentity.IMachineGuiHandler;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import techreborn.client.EGui;
|
||||
|
||||
/**
|
||||
* @author drcrazy
|
||||
*
|
||||
*/
|
||||
public class GenericMachineBlock extends BlockMachineBase {
|
||||
|
||||
private EGui gui;
|
||||
private Supplier<BlockEntity> blockEntityClass;
|
||||
|
||||
public GenericMachineBlock(EGui gui, Supplier<BlockEntity> blockEntityClass) {
|
||||
super();
|
||||
this.blockEntityClass = blockEntityClass;
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockView worldIn) {
|
||||
if (blockEntityClass == null) {
|
||||
return null;
|
||||
}
|
||||
return blockEntityClass.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMachineGuiHandler getGui() {
|
||||
return gui;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
"type": "techreborn:industrial_sawmill",
|
||||
"power": 128,
|
||||
"time": 100,
|
||||
"tank" : {
|
||||
"fluid": "minecraft:water",
|
||||
"amount": 1000
|
||||
},
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "minecraft:acacia_log"
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
"type": "techreborn:industrial_sawmill",
|
||||
"power": 128,
|
||||
"time": 100,
|
||||
"tank" : {
|
||||
"fluid": "minecraft:water",
|
||||
"amount": 1000
|
||||
},
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "minecraft:stripped_acacia_log"
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
"type": "techreborn:industrial_sawmill",
|
||||
"power": 128,
|
||||
"time": 100,
|
||||
"tank" : {
|
||||
"fluid": "minecraft:water",
|
||||
"amount": 1000
|
||||
},
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "minecraft:birch_log"
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
"type": "techreborn:industrial_sawmill",
|
||||
"power": 128,
|
||||
"time": 100,
|
||||
"tank" : {
|
||||
"fluid": "minecraft:water",
|
||||
"amount": 1000
|
||||
},
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "minecraft:stripped_birch_log"
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
"type": "techreborn:industrial_sawmill",
|
||||
"power": 128,
|
||||
"time": 100,
|
||||
"tank" : {
|
||||
"fluid": "minecraft:water",
|
||||
"amount": 1000
|
||||
},
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "minecraft:dark_oak_log"
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
"type": "techreborn:industrial_sawmill",
|
||||
"power": 128,
|
||||
"time": 100,
|
||||
"tank" : {
|
||||
"fluid": "minecraft:water",
|
||||
"amount": 1000
|
||||
},
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "minecraft:stripped_dark_oak_log"
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
"type": "techreborn:industrial_sawmill",
|
||||
"power": 128,
|
||||
"time": 100,
|
||||
"tank" : {
|
||||
"fluid": "minecraft:water",
|
||||
"amount": 1000
|
||||
},
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "minecraft:jungle_log"
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
"type": "techreborn:industrial_sawmill",
|
||||
"power": 128,
|
||||
"time": 100,
|
||||
"tank" : {
|
||||
"fluid": "minecraft:water",
|
||||
"amount": 1000
|
||||
},
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "minecraft:stripped_jungle_log"
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
"type": "techreborn:industrial_sawmill",
|
||||
"power": 128,
|
||||
"time": 100,
|
||||
"tank" : {
|
||||
"fluid": "minecraft:water",
|
||||
"amount": 1000
|
||||
},
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "minecraft:oak_log"
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
"type": "techreborn:industrial_sawmill",
|
||||
"power": 128,
|
||||
"time": 100,
|
||||
"tank" : {
|
||||
"fluid": "minecraft:water",
|
||||
"amount": 1000
|
||||
},
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "minecraft:stripped_oak_log"
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
"type": "techreborn:industrial_sawmill",
|
||||
"power": 128,
|
||||
"time": 100,
|
||||
"tank" : {
|
||||
"fluid": "minecraft:water",
|
||||
"amount": 1000
|
||||
},
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "techreborn:rubber_log"
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
"type": "techreborn:industrial_sawmill",
|
||||
"power": 128,
|
||||
"time": 100,
|
||||
"tank" : {
|
||||
"fluid": "minecraft:water",
|
||||
"amount": 1000
|
||||
},
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "minecraft:spruce_log"
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
"type": "techreborn:industrial_sawmill",
|
||||
"power": 128,
|
||||
"time": 100,
|
||||
"tank" : {
|
||||
"fluid": "minecraft:water",
|
||||
"amount": 1000
|
||||
},
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "minecraft:stripped_spruce_log"
|
||||
|
|
Loading…
Reference in a new issue