Update FurnaceEngineModifiers.java

- Use registry delegates
- Reduce boilerplate
This commit is contained in:
simibubi 2021-10-21 19:23:49 +02:00
parent 6173f9600c
commit 855fc52d62

View file

@ -6,34 +6,27 @@ import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraftforge.registries.IRegistryDelegate;
public class FurnaceEngineModifiers {
public final static FurnaceEngineModifiers INSTANCE = new FurnaceEngineModifiers();
protected Map<Block, Float> blockModifiers;
public FurnaceEngineModifiers(Map<Block, Float> blockModifiers) {
this.blockModifiers = blockModifiers;
}
public FurnaceEngineModifiers() {
this(new HashMap<>());
}
public void set(Block block, float modifier) {
protected Map<IRegistryDelegate<Block>, Float> blockModifiers = new HashMap<>();
public void register(IRegistryDelegate<Block> block, float modifier) {
this.blockModifiers.put(block, modifier);
}
public float getModifier(BlockState state, float def) {
return blockModifiers.getOrDefault(state.getBlock(), def);
public float getModifierOrDefault(BlockState state, float defaultValue) {
return blockModifiers.getOrDefault(state.getBlock().delegate, defaultValue);
}
public float getModifier(BlockState state) {
return getModifier(state, 1f);
return getModifierOrDefault(state, 1f);
}
public static void register() {
INSTANCE.set(Blocks.BLAST_FURNACE, 2f);
INSTANCE.register(Blocks.BLAST_FURNACE.delegate, 2f);
}
}