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
protected boolean isValidBaseBlock(BlockState baseBlock, BlockGetter world, BlockPos pos) {
return FurnaceEngineModifiers.INSTANCE.getEngineState(baseBlock).isEngine();
return FurnaceEngineModifiers.get().getEngineState(baseBlock).isEngine();
}
@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.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RedstoneLampBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.registries.IRegistryDelegate;
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<>();
protected Map<IRegistryDelegate<Block>, Function<BlockState, EngineState>> blockActivators = new HashMap<>();
private final Map<IRegistryDelegate<Block>, Float> blockModifiers;
private final Map<IRegistryDelegate<Block>, Function<BlockState, EngineState>> blockActivators;
public void register(IRegistryDelegate<Block> block, float modifier) {
this.blockModifiers.put(block, modifier);
@ -40,12 +44,22 @@ public class FurnaceEngineModifiers {
}
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() {
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 {

View file

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