Advertisement
Reygok

TinyDirt

Jun 29th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.34 KB | None | 0 0
  1. package com.reygok.octablocks.blocks;
  2.  
  3. import java.util.List;
  4.  
  5. import com.reygok.octablocks.OctablocksMod;
  6.  
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.BlockDirt;
  9. import net.minecraft.block.BlockStairs;
  10. import net.minecraft.block.ITileEntityProvider;
  11. import net.minecraft.block.material.Material;
  12. import net.minecraft.block.properties.IProperty;
  13. import net.minecraft.block.properties.PropertyBool;
  14. import net.minecraft.block.state.BlockState;
  15. import net.minecraft.block.state.IBlockState;
  16. import net.minecraft.creativetab.CreativeTabs;
  17. import net.minecraft.entity.Entity;
  18. import net.minecraft.entity.EntityLivingBase;
  19. import net.minecraft.item.Item;
  20. import net.minecraft.item.ItemStack;
  21. import net.minecraft.tileentity.TileEntity;
  22. import net.minecraft.util.AxisAlignedBB;
  23. import net.minecraft.util.BlockPos;
  24. import net.minecraft.util.EnumWorldBlockLayer;
  25. import net.minecraft.world.IBlockAccess;
  26. import net.minecraft.world.World;
  27. import net.minecraftforge.common.property.ExtendedBlockState;
  28. import net.minecraftforge.common.property.IExtendedBlockState;
  29. import net.minecraftforge.common.property.IUnlistedProperty;
  30. import net.minecraftforge.common.property.Properties;
  31. import net.minecraftforge.fml.relauncher.Side;
  32. import net.minecraftforge.fml.relauncher.SideOnly;
  33.  
  34.  
  35. public class TinyDirt extends Block implements ITileEntityProvider
  36. {
  37.     public static final IUnlistedProperty<Boolean> BOT_NW = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("bottom_north_west"));
  38.     public static final IUnlistedProperty<Boolean> BOT_NE = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("bottom_north_east"));
  39.     public static final IUnlistedProperty<Boolean> BOT_SE = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("bottom_south_east"));
  40.     public static final IUnlistedProperty<Boolean> BOT_SW = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("bottom_south_west"));
  41.     public static final IUnlistedProperty<Boolean> TOP_NW = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("top_north_west"));
  42.     public static final IUnlistedProperty<Boolean> TOP_NE = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("top_north_east"));
  43.     public static final IUnlistedProperty<Boolean> TOP_SE = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("top_south_east"));
  44.     public static final IUnlistedProperty<Boolean> TOP_SW = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("top_south_west"));
  45.  
  46.     //public static final PropertyBool isFull = PropertyBool.create("isFull");
  47.  
  48.     private final String name = "tinyDirt";
  49.  
  50.     public TinyDirt()
  51.     {
  52.         super(Material.ground);
  53.         setUnlocalizedName(OctablocksMod.MODID + "_" + name);
  54.         setCreativeTab(CreativeTabs.tabBlock);
  55.         setHarvestLevel("shovel", 0);
  56.         setHardness(0.5F);
  57.         setStepSound(soundTypeGravel); 
  58.     }
  59.  
  60.     @SideOnly(Side.CLIENT)
  61.     public EnumWorldBlockLayer getBlockLayer()
  62.     {
  63.         return EnumWorldBlockLayer.SOLID;
  64.     }
  65.  
  66.     public String getName()
  67.     {
  68.         return name;
  69.     }
  70.    
  71.  
  72.     public Object getVariant(ItemStack stack)
  73.     {
  74.         return BlockDirt.DirtType.byMetadata(stack.getMetadata() & 7);
  75.     }
  76.  
  77.     @Override
  78.     public TileEntity createNewTileEntity(World worldIn, int meta)
  79.     {
  80.         return new TileEntityTinyDirt();
  81.     }
  82.    
  83.    
  84.     @Override
  85.     public void breakBlock(World world, BlockPos pos, IBlockState state) {
  86.         super.breakBlock(world, pos, state);
  87.         world.removeTileEntity(pos);
  88.     }
  89.  
  90.     @Override
  91.     public boolean onBlockEventReceived(World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam) {
  92.         super.onBlockEventReceived(worldIn, pos, state, eventID, eventParam);
  93.         TileEntity tileentity = worldIn.getTileEntity(pos);
  94.         return tileentity == null ? false : tileentity.receiveClientEvent(eventID, eventParam);
  95.     }
  96.    
  97.  
  98.     @Override
  99.     protected BlockState createBlockState() {
  100.         IProperty [] listedProperties = new IProperty[] {}; // no listed properties
  101.         IUnlistedProperty [] unlistedProperties = new IUnlistedProperty[] {BOT_NW, BOT_NE, BOT_SE, BOT_SW, TOP_NW, TOP_NE, TOP_SE, TOP_SW};
  102.         return new ExtendedBlockState(this, listedProperties, unlistedProperties);
  103.     }
  104.  
  105.     @Override
  106.     public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
  107.         if (state instanceof IExtendedBlockState) {  // avoid crash in case of mismatch
  108.             IExtendedBlockState stateExt = (IExtendedBlockState)state;
  109.             TileEntityTinyDirt tileEntity = (TileEntityTinyDirt) world.getTileEntity(pos);
  110.  
  111.             boolean bot_nw = tileEntity.isBot_nw();
  112.             boolean bot_ne = tileEntity.isBot_ne();
  113.             boolean bot_se = tileEntity.isBot_se();
  114.             boolean bot_sw = tileEntity.isBot_sw();
  115.             boolean top_nw = tileEntity.isTop_nw();
  116.             boolean top_ne = tileEntity.isTop_ne();
  117.             boolean top_se = tileEntity.isTop_se();
  118.             boolean top_sw = tileEntity.isTop_sw();
  119.  
  120.             return stateExt
  121.                     .withProperty(BOT_NW, bot_nw).withProperty(BOT_NE, bot_ne).withProperty(BOT_SE, bot_se) .withProperty(BOT_SW, bot_sw)
  122.                     .withProperty(TOP_NW, top_nw).withProperty(TOP_NE, top_ne).withProperty(TOP_SE, top_se) .withProperty(TOP_SW, top_sw);
  123.         }
  124.         return state;
  125.     }
  126.  
  127.     @Override
  128.     public boolean isReplaceable(World worldIn, BlockPos pos)
  129.     {
  130.         return true;
  131.     }
  132.        
  133.     @Override
  134.     public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List list, Entity collidingEntity)
  135.     {
  136.         TileEntityTinyDirt tileEntity = (TileEntityTinyDirt) worldIn.getTileEntity(pos);
  137.         boolean bot_nw = tileEntity.isBot_nw();
  138.         boolean bot_ne = tileEntity.isBot_ne();
  139.         boolean bot_se = tileEntity.isBot_se();
  140.         boolean bot_sw = tileEntity.isBot_sw();
  141.         boolean top_nw = tileEntity.isTop_nw();
  142.         boolean top_ne = tileEntity.isTop_ne();
  143.         boolean top_se = tileEntity.isTop_se();
  144.         boolean top_sw = tileEntity.isTop_sw();
  145.  
  146.                
  147.         if(bot_nw)
  148.         {
  149.             setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 0.5F, 0.5F);
  150.             super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
  151.         }
  152.         if(bot_ne)
  153.         {
  154.             setBlockBounds(0.5F, 0.0F, 0.0F, 1.0F, 0.5F, 0.5F);
  155.             super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
  156.         }
  157.         if(bot_se)
  158.         {
  159.             setBlockBounds(0.5F, 0.0F, 0.5F, 1.0F, 0.5F, 1.0F);
  160.             super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
  161.         }
  162.         if(bot_sw)
  163.         {
  164.             setBlockBounds(0.0F, 0.0F, 0.5F, 0.5F, 0.5F, 1.0F);
  165.             super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
  166.         }
  167.        
  168.         if(top_nw)
  169.         {
  170.             setBlockBounds(0.0F, 0.5F, 0.0F, 0.5F, 1.0F, 0.5F);
  171.             super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
  172.         }
  173.         if(top_ne)
  174.         {
  175.             setBlockBounds(0.5F, 0.5F, 0.0F, 1.0F, 1.0F, 0.5F);
  176.             super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
  177.         }
  178.         if(top_se)
  179.         {
  180.             setBlockBounds(0.5F, 0.5F, 0.5F, 1.0F, 1.0F, 1.0F);
  181.             super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
  182.         }
  183.         if(top_sw)
  184.         {
  185.             setBlockBounds(0.0F, 0.5F, 0.5F, 0.5F, 1.0F, 1.0F);
  186.             super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
  187.         }      
  188.     }
  189.    
  190.  
  191.  
  192.     public boolean isOpaqueCube()
  193.     {
  194.         return false;
  195.     }
  196.  
  197.     public boolean isFullCube()
  198.     {
  199.         return false;
  200.     }
  201.  
  202.     public int quantityDropped()
  203.     {
  204.         return 1;
  205.     }
  206.  
  207.     public Item getItemDropped(int par1, int par2)
  208.     {
  209.         return Item.getItemFromBlock(this);
  210.     }
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement