2019-11-16 08:26:17 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.block;
|
|
|
|
|
2019-11-16 09:26:10 +01:00
|
|
|
import java.util.EnumMap;
|
|
|
|
|
2019-11-16 08:26:17 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockState;
|
2019-11-16 09:26:10 +01:00
|
|
|
import net.minecraft.block.RedstoneLampBlock;
|
2019-11-16 08:26:17 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.Hand;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.BlockRayTraceResult;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.ToolType;
|
|
|
|
|
2019-11-16 09:26:10 +01:00
|
|
|
public class ColoredLampBlock extends RedstoneLampBlock {
|
|
|
|
|
|
|
|
public static final EnumMap<LampColor, ColoredLampBlock> LAMPS = new EnumMap<>(LampColor.class);
|
|
|
|
|
|
|
|
protected LampColor color;
|
|
|
|
|
|
|
|
public ColoredLampBlock(LampColor color) {
|
|
|
|
super(Properties.create(Material.REDSTONE_LIGHT).harvestTool(ToolType.PICKAXE).lightValue(15).hardnessAndResistance(0.5F, 3.0F));
|
|
|
|
this.setDefaultState(getDefaultState().with(LIT, false));
|
|
|
|
this.color = color;
|
|
|
|
LAMPS.put(color, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Deprecated
|
|
|
|
public boolean onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
|
|
|
|
ItemStack stack = player.getHeldItem(hand);
|
|
|
|
if (player.isSneaking() && stack.isEmpty()) {
|
|
|
|
world.setBlockState(pos, state.cycle(LIT));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
LampColor color = LampColor.getColorFromStack(stack);
|
|
|
|
if (color != null && color != this.color) {
|
|
|
|
world.setBlockState(pos, LAMPS.get(color).getDefaultState().with(LIT, state.get(LIT)));
|
|
|
|
if (!player.abilities.isCreativeMode) {
|
|
|
|
stack.shrink(1);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void neighborChanged(BlockState state, World world, BlockPos pos, Block from, BlockPos fromPos, boolean isMoving) {
|
|
|
|
if (!world.isRemote) {
|
|
|
|
if (world.getBlockState(fromPos).canProvidePower()) {
|
|
|
|
world.setBlockState(pos, state.with(LIT, world.isBlockPowered(pos)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-16 08:26:17 +01:00
|
|
|
}
|