This commit is contained in:
MRH0 2021-12-31 16:29:22 +01:00
parent 8145014847
commit 6107b939a5
3 changed files with 23 additions and 9 deletions

View file

@ -33,7 +33,7 @@ public class FurnaceEngineBlock extends EngineBlock implements ITE<FurnaceEngine
@Override @Override
protected boolean isValidBaseBlock(BlockState baseBlock, BlockGetter world, BlockPos pos) { protected boolean isValidBaseBlock(BlockState baseBlock, BlockGetter world, BlockPos pos) {
return FurnaceEngineModifiers.INSTANCE.getEngineState(baseBlock).isEngine(); return FurnaceEngineModifiers.get().getEngineState(baseBlock).isEngine();
} }
@Override @Override

View file

@ -7,16 +7,20 @@ import java.util.function.Function;
import net.minecraft.world.level.block.AbstractFurnaceBlock; import net.minecraft.world.level.block.AbstractFurnaceBlock;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RedstoneLampBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.registries.IRegistryDelegate; import net.minecraftforge.registries.IRegistryDelegate;
public class FurnaceEngineModifiers { public class FurnaceEngineModifiers {
public final static FurnaceEngineModifiers INSTANCE = new FurnaceEngineModifiers(); private final static FurnaceEngineModifiers INSTANCE = new FurnaceEngineModifiers();
protected FurnaceEngineModifiers() {
blockModifiers = new HashMap<>();
blockActivators = new HashMap<>();
}
protected Map<IRegistryDelegate<Block>, Float> blockModifiers = new HashMap<>(); private final Map<IRegistryDelegate<Block>, Float> blockModifiers;
protected Map<IRegistryDelegate<Block>, Function<BlockState, EngineState>> blockActivators = new HashMap<>(); private final Map<IRegistryDelegate<Block>, Function<BlockState, EngineState>> blockActivators;
public void register(IRegistryDelegate<Block> block, float modifier) { public void register(IRegistryDelegate<Block> block, float modifier) {
this.blockModifiers.put(block, modifier); this.blockModifiers.put(block, modifier);
@ -40,12 +44,22 @@ public class FurnaceEngineModifiers {
} }
public EngineState getEngineState(BlockState state) { 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); 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() { public static void register() {
INSTANCE.register(Blocks.BLAST_FURNACE.delegate, 2f); 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);
// Example:
// 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 static FurnaceEngineModifiers get() {
return INSTANCE;
} }
public enum EngineState { public enum EngineState {

View file

@ -22,11 +22,11 @@ public class FurnaceEngineTileEntity extends EngineTileEntity {
public void updateFurnace() { public void updateFurnace() {
BlockState state = level.getBlockState(EngineBlock.getBaseBlockPos(getBlockState(), worldPosition)); BlockState state = level.getBlockState(EngineBlock.getBaseBlockPos(getBlockState(), worldPosition));
EngineState engineState = FurnaceEngineModifiers.INSTANCE.getEngineState(state); EngineState engineState = FurnaceEngineModifiers.get().getEngineState(state);
if (engineState.isEmpty()) if (engineState.isEmpty())
return; return;
float modifier = FurnaceEngineModifiers.INSTANCE.getModifier(state); float modifier = FurnaceEngineModifiers.get().getModifier(state);
boolean active = engineState.isActive(); boolean active = engineState.isActive();
float speed = active ? 16 * modifier : 0; float speed = active ? 16 * modifier : 0;
float capacity = float capacity =