Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mcjty.modtut.neons;
- import java.util.Random;
- import mcjty.modtut.Lanterns;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.PropertyDirection;
- import net.minecraft.block.properties.PropertyInteger;
- import net.minecraft.block.state.BlockStateContainer;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.client.renderer.block.model.ModelResourceLocation;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import net.minecraftforge.client.model.ModelLoader;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- public class NeonLetterENeon extends Block {
- public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
- public static final PropertyInteger STATE = PropertyInteger.create("state", 0, 1);
- public NeonLetterENeon() {
- super(Material.IRON);
- this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.WEST));
- this.setCreativeTab(Lanterns.tabLetters);
- this.disableStats();
- this.setTickRandomly(true);
- }
- @SideOnly(Side.CLIENT)
- public void initModel() {
- ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
- }
- @SideOnly(Side.CLIENT)
- @Override
- public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
- return false;
- }
- @Override
- public boolean isBlockNormalCube(IBlockState blockState) {
- return false;
- }
- @Override
- public boolean isOpaqueCube(IBlockState blockState) {
- return false;
- }
- @Override
- public BlockStateContainer createBlockState() {
- return new BlockStateContainer(this, FACING);
- }
- @Override
- public int getMetaFromState(IBlockState state) {
- return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
- }
- @Override
- public IBlockState getStateFromMeta(int meta) {
- return getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
- }
- @Override
- public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack) {
- EnumFacing entityFacing = entity.getHorizontalFacing();
- if(!world.isRemote) {
- if(entityFacing == EnumFacing.NORTH) {
- entityFacing = EnumFacing.NORTH;
- } else if(entityFacing == EnumFacing.EAST) {
- entityFacing = EnumFacing.EAST;
- } else if(entityFacing == EnumFacing.SOUTH) {
- entityFacing = EnumFacing.SOUTH;
- } else if(entityFacing == EnumFacing.WEST) {
- entityFacing = EnumFacing.WEST;
- }
- world.setBlockState(pos, state.withProperty(FACING, entityFacing), 2);
- }
- }
- @Override
- public boolean isTopSolid(IBlockState state)
- {
- return false;
- }
- protected PropertyInteger getStateProperty()
- {
- return STATE;
- }
- public int getMaxState()
- {
- return 7;
- }
- protected int getState(IBlockState state)
- {
- return ((Integer)state.getValue(this.getStateProperty())).intValue();
- }
- public IBlockState withState(int State)
- {
- return this.getDefaultState().withProperty(this.getStateProperty(), Integer.valueOf(State));
- }
- public boolean isMaxState(IBlockState state)
- {
- return ((Integer)state.getValue(this.getStateProperty())).intValue() >= this.getMaxState();
- }
- public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
- {
- super.updateTick(worldIn, pos, state, rand);
- if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
- {
- int isActive = this.getState(state);
- if(isActive == this.getMaxState())
- {
- this.setLightLevel(1F);
- }else
- {
- this.setLightLevel(0F);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment