Reygok

TinyDirt

Jun 27th, 2015
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.49 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 =
  38.         new Properties.PropertyAdapter<Boolean>(PropertyBool.create("bottom_north_west"));
  39.     public static final IUnlistedProperty<Boolean> BOT_NE =
  40.         new Properties.PropertyAdapter<Boolean>(PropertyBool.create("bottom_north_east"));
  41.     public static final IUnlistedProperty<Boolean> BOT_SE =
  42.         new Properties.PropertyAdapter<Boolean>(PropertyBool.create("bottom_south_east"));
  43.     public static final IUnlistedProperty<Boolean> BOT_SW =
  44.         new Properties.PropertyAdapter<Boolean>(PropertyBool.create("bottom_south_west"));
  45.     public static final IUnlistedProperty<Boolean> TOP_NW =
  46.         new Properties.PropertyAdapter<Boolean>(PropertyBool.create("top_north_west"));
  47.     public static final IUnlistedProperty<Boolean> TOP_NE =
  48.         new Properties.PropertyAdapter<Boolean>(PropertyBool.create("top_north_east"));
  49.     public static final IUnlistedProperty<Boolean> TOP_SE =
  50.         new Properties.PropertyAdapter<Boolean>(PropertyBool.create("top_south_east"));
  51.     public static final IUnlistedProperty<Boolean> TOP_SW =
  52.         new Properties.PropertyAdapter<Boolean>(PropertyBool.create("top_south_west"));
  53.  
  54.     //public static final PropertyBool isFull = PropertyBool.create("isFull");
  55.  
  56.     private final String name = "tinyDirt";
  57.  
  58.     public TinyDirt()
  59.     {
  60.         super(Material.ground);
  61.         setUnlocalizedName(OctablocksMod.MODID + "_" + name);
  62.         setCreativeTab(CreativeTabs.tabBlock);
  63.         setHarvestLevel("shovel", 0);
  64.         setHardness(0.5F);
  65.         setStepSound(soundTypeGravel); 
  66.             this.isBlockContainer = true;
  67.     }
  68.  
  69.     @SideOnly(Side.CLIENT)
  70.     public EnumWorldBlockLayer getBlockLayer()
  71.     {
  72.         return EnumWorldBlockLayer.SOLID;
  73.     }
  74.  
  75.     public String getName()
  76.     {
  77.         return name;
  78.     }
  79.    
  80.  
  81.     public Object getVariant(ItemStack stack)
  82.     {
  83.         return BlockDirt.DirtType.byMetadata(stack.getMetadata() & 7);
  84.     }
  85.  
  86.     @Override
  87.     public TileEntity createNewTileEntity(World worldIn, int meta)
  88.     {
  89.         return new TileEntityTinyDirt();
  90.     }
  91.    
  92.     @Override
  93.         public void breakBlock(World world, BlockPos pos, IBlockState state) {
  94.             super.breakBlock(world, pos, state);
  95.             world.removeTileEntity(pos);
  96.     }
  97.  
  98.     @Override
  99.     public boolean onBlockEventReceived(World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam) {
  100.         super.onBlockEventReceived(worldIn, pos, state, eventID, eventParam);
  101.         TileEntity tileentity = worldIn.getTileEntity(pos);
  102.         return tileentity == null ? false : tileentity.receiveClientEvent(eventID, eventParam);
  103.     }
  104.  
  105.  
  106.     @Override
  107.     protected BlockState createBlockState() {
  108.         IProperty [] listedProperties = new IProperty[] {}; // no listed properties
  109.         IUnlistedProperty [] unlistedProperties =
  110.             new IUnlistedProperty[] {BOT_NW, BOT_NE, BOT_SE, BOT_SW, TOP_NW, TOP_NE, TOP_SE, TOP_SW};
  111.         return new ExtendedBlockState(this, listedProperties, unlistedProperties);
  112.     }
  113.  
  114.     @Override
  115.     public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
  116.         if (state instanceof IExtendedBlockState) {  // avoid crash in case of mismatch
  117.             IExtendedBlockState stateExt = (IExtendedBlockState)state;
  118.             TileEntityTinyDirt tileEntity = (TileEntityTinyDirt) world.getTileEntity(pos);
  119.  
  120.             boolean bot_nw = tileEntity.isBot_nw();
  121.             boolean bot_ne = tileEntity.isBot_ne();
  122.             boolean bot_se = tileEntity.isBot_se();
  123.             boolean bot_sw = tileEntity.isBot_sw();
  124.             boolean top_nw = tileEntity.isTop_nw();
  125.             boolean top_ne = tileEntity.isTop_ne();
  126.             boolean top_se = tileEntity.isTop_se();
  127.             boolean top_sw = tileEntity.isTop_sw();
  128.  
  129.             return stateExt
  130.                     .withProperty(BOT_NW, bot_nw).withProperty(BOT_NE, bot_ne)
  131.                     .withProperty(BOT_SE, bot_se).withProperty(BOT_SW, bot_sw)
  132.                     .withProperty(TOP_NW, top_nw).withProperty(TOP_NE, top_ne)
  133.                     .withProperty(TOP_SE,top_se).withProperty(TOP_SW, top_sw);
  134.         }
  135.         return state;
  136.     }
  137.  
  138.     @Override
  139.     public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
  140.     {
  141.         return new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
  142.     }
  143.    
  144.     @Override
  145.     public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state,
  146.                         AxisAlignedBB mask, List list, Entity collidingEntity)
  147.     {
  148.         TileEntityTinyDirt tileEntity = (TileEntityTinyDirt) worldIn.getTileEntity(pos);
  149.         boolean bot_nw = tileEntity.isBot_nw();
  150.         boolean bot_ne = tileEntity.isBot_ne();
  151.         boolean bot_se = tileEntity.isBot_se();
  152.         boolean bot_sw = tileEntity.isBot_sw();
  153.         boolean top_nw = tileEntity.isTop_nw();
  154.         boolean top_ne = tileEntity.isTop_ne();
  155.         boolean top_se = tileEntity.isTop_se();
  156.         boolean top_sw = tileEntity.isTop_sw();
  157.  
  158.         if(bot_nw)
  159.         {
  160.             AxisAlignedBB box = new AxisAlignedBB(0.0, 0.0, 0.0, 0.5, 0.5, 0.5);
  161.             addCollisionBox(box, list, mask);
  162.         }
  163.         if(bot_ne)
  164.         {
  165.             AxisAlignedBB box = new AxisAlignedBB(0.5F, 0.0F, 0.0F, 1.0F, 0.5F, 0.5F);
  166.             addCollisionBox(box, list, mask);
  167.         }
  168.         if(bot_se)
  169.         {
  170.             AxisAlignedBB box = new AxisAlignedBB(0.5F, 0.0F, 0.5F, 1.0F, 0.5F, 1.0F);
  171.             addCollisionBox(box, list, mask);
  172.         }
  173.         if(bot_sw)
  174.         {
  175.             AxisAlignedBB box = new AxisAlignedBB(0.0F, 0.0F, 0.5F, 0.5F, 0.5F, 1.0F);
  176.             addCollisionBox(box, list, mask);
  177.         }
  178.        
  179.         if(top_nw)
  180.         {
  181.             AxisAlignedBB box = new AxisAlignedBB(0.0F, 0.5F, 0.0F, 0.5F, 1.0F, 0.5F);
  182.             addCollisionBox(box, list, mask);
  183.         }
  184.         if(top_ne)
  185.         {
  186.             AxisAlignedBB box = new AxisAlignedBB(0.5F, 0.5F, 0.0F, 1.0F, 1.0F, 0.5F);
  187.             addCollisionBox(box, list, mask);
  188.         }
  189.         if(top_se)
  190.         {
  191.             AxisAlignedBB box = new AxisAlignedBB(0.5F, 0.5F, 0.5F, 1.0F, 1.0F, 1.0F);
  192.             addCollisionBox(box, list, mask);
  193.         }
  194.         if(top_sw)
  195.         {
  196.             AxisAlignedBB box = new AxisAlignedBB(0.0F, 0.5F, 0.5F, 0.5F, 1.0F, 1.0F);
  197.             addCollisionBox(box, list, mask);
  198.         }
  199.     }
  200.  
  201.     public void addCollisionBox(AxisAlignedBB box, List list, AxisAlignedBB mask)
  202.     {
  203.             if (box != null && mask.intersectsWith(box))
  204.             {
  205.                     list.add(box);
  206.                 }
  207.     }
  208.  
  209.  
  210.     public boolean isOpaqueCube()
  211.     {
  212.         return false;
  213.     }
  214.  
  215.     public boolean isFullCube()
  216.     {
  217.         return false;
  218.     }
  219.  
  220.     public int quantityDropped()
  221.     {
  222.         return 1;
  223.     }
  224.  
  225.     public Item getItemDropped(int par1, int par2)
  226.     {
  227.         return Item.getItemFromBlock(this);
  228.     }
  229. }
Advertisement
Add Comment
Please, Sign In to add comment