package com.miningmark48.pearcelmod.block; import com.miningmark48.pearcelmod.init.ModBlocks; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import java.util.Random; public class BlockPearcelLamp extends Block{ private final boolean isOn; public BlockPearcelLamp(boolean isOn){ super(Material.REDSTONE_LIGHT); this.isOn = isOn; if (isOn) { this.setLightLevel(5.0F); } } @Override public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { if (!worldIn.isRemote) { if (this.isOn && !worldIn.isBlockPowered(pos)) { worldIn.setBlockState(pos, ModBlocks.pearcel_lamp.getDefaultState(), 2); } else if (!this.isOn && worldIn.isBlockPowered(pos)) { worldIn.setBlockState(pos, ModBlocks.lit_pearcel_lamp.getDefaultState(), 2); } } } @Override public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) { if (!worldIn.isRemote) { if (this.isOn && !worldIn.isBlockPowered(pos)) { worldIn.scheduleUpdate(pos, this, 4); } else if (!this.isOn && worldIn.isBlockPowered(pos)) { worldIn.setBlockState(pos, ModBlocks.lit_pearcel_lamp.getDefaultState(), 2); } } } @Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote) { if (this.isOn && !worldIn.isBlockPowered(pos)) { worldIn.setBlockState(pos, ModBlocks.pearcel_lamp.getDefaultState(), 2); } } } @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return Item.getItemFromBlock(ModBlocks.pearcel_lamp); } @Override public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) { return new ItemStack(ModBlocks.pearcel_lamp); } }