mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-28 22:05:01 +01:00
Merge pull request #2529 from mrh0/furnaceEngineChanges
- Addons are now able to register non-furnace blocks as valid sources of a furnace engines' power
This commit is contained in:
commit
b75c844adb
3 changed files with 62 additions and 9 deletions
|
@ -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 baseBlock.getBlock() instanceof AbstractFurnaceBlock;
|
return FurnaceEngineModifiers.get().getEngineState(baseBlock).isEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,7 +2,9 @@ package com.simibubi.create.content.contraptions.components.flywheel.engine;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
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.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
@ -10,23 +12,73 @@ 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;
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void register(IRegistryDelegate<Block> block, float modifier, Function<BlockState, EngineState> 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);
|
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) {
|
public float getModifier(BlockState state) {
|
||||||
return getModifierOrDefault(state, 1f);
|
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() {
|
public static void register() {
|
||||||
INSTANCE.register(Blocks.BLAST_FURNACE.delegate, 2f);
|
get().register(Blocks.BLAST_FURNACE.delegate, 2f);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Example:
|
||||||
|
get().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 {
|
||||||
|
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;
|
package com.simibubi.create.content.contraptions.components.flywheel.engine;
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
import com.simibubi.create.AllBlocks;
|
||||||
|
import com.simibubi.create.content.contraptions.components.flywheel.engine.FurnaceEngineModifiers.EngineState;
|
||||||
import com.simibubi.create.foundation.block.BlockStressValues;
|
import com.simibubi.create.foundation.block.BlockStressValues;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
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.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
|
@ -22,11 +22,12 @@ 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));
|
||||||
if (!(state.getBlock() instanceof AbstractFurnaceBlock))
|
EngineState engineState = FurnaceEngineModifiers.get().getEngineState(state);
|
||||||
|
if (engineState.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float modifier = FurnaceEngineModifiers.INSTANCE.getModifier(state);
|
float modifier = FurnaceEngineModifiers.get().getModifier(state);
|
||||||
boolean active = state.hasProperty(AbstractFurnaceBlock.LIT) && state.getValue(AbstractFurnaceBlock.LIT);
|
boolean active = engineState.isActive();
|
||||||
float speed = active ? 16 * modifier : 0;
|
float speed = active ? 16 * modifier : 0;
|
||||||
float capacity =
|
float capacity =
|
||||||
(float) (active ? BlockStressValues.getCapacity(AllBlocks.FURNACE_ENGINE.get())
|
(float) (active ? BlockStressValues.getCapacity(AllBlocks.FURNACE_ENGINE.get())
|
||||||
|
|
Loading…
Reference in a new issue