Lamps require energy to work. Again. Closes #2227

This commit is contained in:
drcrazy 2020-09-25 00:54:48 +03:00
parent 22b0cdfe23
commit 7ba962196b
4 changed files with 30 additions and 21 deletions

View file

@ -31,7 +31,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Direction;
import reborncore.api.IToolDrop;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import techreborn.blocks.lighting.BlockLamp;
import techreborn.blocks.lighting.LampBlock;
import techreborn.init.TRBlockEntities;
public class LampBlockEntity extends PowerAcceptorBlockEntity
@ -52,14 +52,14 @@ public class LampBlockEntity extends PowerAcceptorBlockEntity
}
BlockState state = world.getBlockState(pos);
Block b = state.getBlock();
if (b instanceof BlockLamp) {
double cost = getEuPerTick(((BlockLamp) b).getCost());
if (b instanceof LampBlock) {
double cost = getEuPerTick(((LampBlock) b).getCost());
if (getEnergy() > cost) {
useEnergy(getEuPerTick(cost));
if (!BlockLamp.isActive(state))
BlockLamp.setActive(true, world, pos);
} else if (BlockLamp.isActive(state)) {
BlockLamp.setActive(false, world, pos);
if (!LampBlock.isActive(state))
LampBlock.setActive(true, world, pos);
} else if (LampBlock.isActive(state)) {
LampBlock.setActive(false, world, pos);
}
}
}
@ -75,7 +75,7 @@ public class LampBlockEntity extends PowerAcceptorBlockEntity
// Blame tooltip for this
return true;
}
Direction me = BlockLamp.getFacing(world.getBlockState(pos)).getOpposite();
Direction me = LampBlock.getFacing(world.getBlockState(pos)).getOpposite();
return direction == me;
}

View file

@ -41,7 +41,7 @@ import reborncore.common.blockentity.MultiblockWriter;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.ItemUtils;
import reborncore.common.util.RebornInventory;
import techreborn.blocks.lighting.BlockLamp;
import techreborn.blocks.lighting.LampBlock;
import techreborn.blocks.misc.BlockRubberLog;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
@ -240,7 +240,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
for (int i = 0; i < 3; i++) {
for (int j = -1; j < 2; j++) {
writer.add(i * 3 + 2, 3, j * 3, (world, pos) -> BlockLamp.isActive(world.getBlockState(pos)), lamp);
writer.add(i * 3 + 2, 3, j * 3, (world, pos) -> LampBlock.isActive(world.getBlockState(pos)), lamp);
}
}

View file

@ -50,7 +50,9 @@ import techreborn.blockentity.lighting.LampBlockEntity;
import org.jetbrains.annotations.Nullable;
public class BlockLamp extends BaseBlockEntityProvider {
import java.util.function.ToIntFunction;
public class LampBlock extends BaseBlockEntityProvider {
public static DirectionProperty FACING = Properties.FACING;
public static BooleanProperty ACTIVE;
@ -59,14 +61,18 @@ public class BlockLamp extends BaseBlockEntityProvider {
private final int cost;
private static final int brightness = 15;
public BlockLamp(int cost, double depth, double width) {
super(FabricBlockSettings.of(Material.REDSTONE_LAMP).strength(2f, 2f).lightLevel(brightness));
public LampBlock(int cost, double depth, double width) {
super(FabricBlockSettings.of(Material.REDSTONE_LAMP).strength(2f, 2f).lightLevel(createLightLevelFromBlockState()));
this.shape = genCuboidShapes(depth, width);
this.cost = cost;
this.setDefaultState(this.getStateManager().getDefaultState().with(FACING, Direction.NORTH).with(ACTIVE, false));
BlockWrenchEventHandler.wrenableBlocks.add(this);
}
private static ToIntFunction<BlockState> createLightLevelFromBlockState() {
return (blockState) -> isActive(blockState) ? brightness : 0;
}
private VoxelShape[] genCuboidShapes(double depth, double width) {
double culling = (16.0D - width) / 2;
return new VoxelShape[]{
@ -79,11 +85,6 @@ public class BlockLamp extends BaseBlockEntityProvider {
};
}
@Override
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, ShapeContext shapeContext) {
return shape[blockState.get(FACING).ordinal()];
}
public static boolean isActive(BlockState state) {
return state.contains(ACTIVE) && state.get(ACTIVE);
}
@ -131,11 +132,19 @@ public class BlockLamp extends BaseBlockEntityProvider {
return null;
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, ShapeContext shapeContext) {
return shape[blockState.get(FACING).ordinal()];
}
@SuppressWarnings("deprecation")
@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn, Hand hand, BlockHitResult hitResult) {
ItemStack stack = playerIn.getStackInHand(Hand.MAIN_HAND);

View file

@ -60,7 +60,7 @@ import techreborn.blocks.generator.BlockFusionCoil;
import techreborn.blocks.generator.BlockFusionControlComputer;
import techreborn.blocks.generator.BlockSolarPanel;
import techreborn.blocks.generator.GenericGeneratorBlock;
import techreborn.blocks.lighting.BlockLamp;
import techreborn.blocks.lighting.LampBlock;
import techreborn.blocks.machine.tier0.IronAlloyFurnaceBlock;
import techreborn.blocks.machine.tier0.IronFurnaceBlock;
import techreborn.blocks.machine.tier1.PlayerDetectorBlock;
@ -558,8 +558,8 @@ public class TRContent {
ALARM(new BlockAlarm()),
CHUNK_LOADER(new GenericMachineBlock(GuiType.CHUNK_LOADER, ChunkLoaderBlockEntity::new)),
LAMP_INCANDESCENT(new BlockLamp(4, 10, 8)),
LAMP_LED(new BlockLamp(1, 1, 12)),
LAMP_INCANDESCENT(new LampBlock(4, 10, 8)),
LAMP_LED(new LampBlock(1, 1, 12)),
PLAYER_DETECTOR(new PlayerDetectorBlock());
public final String name;