mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-28 16:06:48 +01:00
Disconnecting the Furnace Engine from AbstractFurnaceBlock
Adds the abillity to register any block as a power source to the furnace engine. This will allow for more flexability and remove the need to implement AbstractFurnaceBlock and AbstractFurnaceBlockEntity.
This commit is contained in:
parent
1bae455045
commit
8145014847
3 changed files with 42 additions and 5 deletions
|
@ -33,7 +33,7 @@ public class FurnaceEngineBlock extends EngineBlock implements ITE<FurnaceEngine
|
|||
|
||||
@Override
|
||||
protected boolean isValidBaseBlock(BlockState baseBlock, BlockGetter world, BlockPos pos) {
|
||||
return baseBlock.getBlock() instanceof AbstractFurnaceBlock;
|
||||
return FurnaceEngineModifiers.INSTANCE.getEngineState(baseBlock).isEngine();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,9 +2,12 @@ package com.simibubi.create.content.contraptions.components.flywheel.engine;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
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;
|
||||
|
||||
|
@ -13,20 +16,53 @@ public class FurnaceEngineModifiers {
|
|||
public final static FurnaceEngineModifiers INSTANCE = new FurnaceEngineModifiers();
|
||||
|
||||
protected Map<IRegistryDelegate<Block>, Float> blockModifiers = new HashMap<>();
|
||||
protected Map<IRegistryDelegate<Block>, Function<BlockState, EngineState>> blockActivators = new HashMap<>();
|
||||
|
||||
public void register(IRegistryDelegate<Block> block, float modifier) {
|
||||
this.blockModifiers.put(block, modifier);
|
||||
}
|
||||
|
||||
public float getModifierOrDefault(BlockState state, float defaultValue) {
|
||||
public void register(IRegistryDelegate<Block> block, float modifier, Function<BlockState, EngineState> engineState) {
|
||||
this.blockModifiers.put(block, modifier);
|
||||
this.blockActivators.put(block, engineState);
|
||||
}
|
||||
|
||||
private float getModifierOrDefault(BlockState state, float defaultValue) {
|
||||
return blockModifiers.getOrDefault(state.getBlock().delegate, defaultValue);
|
||||
}
|
||||
|
||||
private Function<BlockState, EngineState> getEngineStateOrDefault(BlockState state, Function<BlockState, EngineState> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue