diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/FurnaceEngineBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/FurnaceEngineBlock.java index 04d95e7d2..09629ecf5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/FurnaceEngineBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/FurnaceEngineBlock.java @@ -33,7 +33,7 @@ public class FurnaceEngineBlock extends EngineBlock implements ITE, Float> blockModifiers = new HashMap<>(); + protected Map, Function> blockActivators = new HashMap<>(); public void register(IRegistryDelegate block, float modifier) { this.blockModifiers.put(block, modifier); } + + public void register(IRegistryDelegate block, float modifier, Function engineState) { + this.blockModifiers.put(block, modifier); + this.blockActivators.put(block, engineState); + } - public float getModifierOrDefault(BlockState state, float defaultValue) { + private float getModifierOrDefault(BlockState state, float defaultValue) { return blockModifiers.getOrDefault(state.getBlock().delegate, defaultValue); } + + private Function getEngineStateOrDefault(BlockState state, Function engineState) { + return blockActivators.getOrDefault(state.getBlock().delegate, engineState); + } public float getModifier(BlockState state) { return getModifierOrDefault(state, 1f); } + + public EngineState getEngineState(BlockState state) { + return getEngineStateOrDefault(state, s -> s.getBlock() instanceof AbstractFurnaceBlock && s.hasProperty(AbstractFurnaceBlock.LIT) ? (s.getValue(AbstractFurnaceBlock.LIT) ? EngineState.ACTIVE : EngineState.VALID) : EngineState.EMPTY).apply(state); + } public static void register() { INSTANCE.register(Blocks.BLAST_FURNACE.delegate, 2f); + //INSTANCE.register(Blocks.REDSTONE_LAMP.delegate, 1f, s -> s.getBlock() instanceof RedstoneLampBlock && s.hasProperty(RedstoneLampBlock.LIT) ? (s.getValue(RedstoneLampBlock.LIT) ? EngineState.ACTIVE : EngineState.VALID) : EngineState.EMPTY); + } + + public enum EngineState { + EMPTY, + VALID, + ACTIVE; + + public boolean isEngine() { + return this != EMPTY; + } + + public boolean isActive() { + return this == ACTIVE; + } + + public boolean isEmpty() { + return this == EMPTY; + } } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/FurnaceEngineTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/FurnaceEngineTileEntity.java index 1851c5878..0dbe13f2e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/FurnaceEngineTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/FurnaceEngineTileEntity.java @@ -1,10 +1,10 @@ package com.simibubi.create.content.contraptions.components.flywheel.engine; import com.simibubi.create.AllBlocks; +import com.simibubi.create.content.contraptions.components.flywheel.engine.FurnaceEngineModifiers.EngineState; import com.simibubi.create.foundation.block.BlockStressValues; import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.AbstractFurnaceBlock; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; @@ -22,11 +22,12 @@ public class FurnaceEngineTileEntity extends EngineTileEntity { public void updateFurnace() { BlockState state = level.getBlockState(EngineBlock.getBaseBlockPos(getBlockState(), worldPosition)); - if (!(state.getBlock() instanceof AbstractFurnaceBlock)) + EngineState engineState = FurnaceEngineModifiers.INSTANCE.getEngineState(state); + if (engineState.isEmpty()) return; float modifier = FurnaceEngineModifiers.INSTANCE.getModifier(state); - boolean active = state.hasProperty(AbstractFurnaceBlock.LIT) && state.getValue(AbstractFurnaceBlock.LIT); + boolean active = engineState.isActive(); float speed = active ? 16 * modifier : 0; float capacity = (float) (active ? BlockStressValues.getCapacity(AllBlocks.FURNACE_ENGINE.get())