Advertisement
Guest User

Untitled

a guest
May 10th, 2017
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.15 KB | None | 0 0
  1. package com.github.wolfiewaffle.tanspit.blocks;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import com.github.wolfiewaffle.tanspit.tileentity.TileEntitySpit;
  8.  
  9. import net.minecraft.block.Block;
  10. import net.minecraft.block.BlockContainer;
  11. import net.minecraft.block.material.Material;
  12. import net.minecraft.block.state.IBlockState;
  13. import net.minecraft.entity.player.EntityPlayer;
  14. import net.minecraft.init.Blocks;
  15. import net.minecraft.inventory.InventoryHelper;
  16. import net.minecraft.item.ItemStack;
  17. import net.minecraft.tileentity.TileEntity;
  18. import net.minecraft.util.BlockRenderLayer;
  19. import net.minecraft.util.EnumBlockRenderType;
  20. import net.minecraft.util.EnumFacing;
  21. import net.minecraft.util.math.AxisAlignedBB;
  22. import net.minecraft.util.math.BlockPos;
  23. import net.minecraft.world.IBlockAccess;
  24. import net.minecraft.world.World;
  25. import net.minecraftforge.items.IItemHandler;
  26. import toughasnails.api.TANBlocks;
  27.  
  28. public class BlockSpit extends BlockContainer {
  29.  
  30.     public BlockSpit(String name) {
  31.         super(Material.ANVIL);
  32.         this.setTickRandomly(true);
  33.         this.setRegistryName(name);
  34.         this.setUnlocalizedName(name);
  35.         this.setLightOpacity(0);
  36.         this.fullBlock = false;
  37.     }
  38.  
  39.     @Override
  40.     public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
  41.         return new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 0.25, 1.0);
  42.     }
  43.  
  44.     @Override
  45.     public AxisAlignedBB getCollisionBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
  46.         return NULL_AABB;
  47.     }
  48.  
  49.     @Override
  50.     public boolean isOpaqueCube(IBlockState state) {
  51.         return false;
  52.     }
  53.  
  54.     @Override
  55.     public boolean isFullCube(IBlockState state) {
  56.         return false;
  57.     }
  58.  
  59.     @Override
  60.     public BlockRenderLayer getBlockLayer() {
  61.         return BlockRenderLayer.CUTOUT_MIPPED;
  62.     }
  63.  
  64.     @Override
  65.     public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side) {
  66.         if (side != EnumFacing.UP || worldIn.getBlockState(pos.down()).getBlock() != TANBlocks.campfire) {
  67.             return false;
  68.         }
  69.         return super.canPlaceBlockOnSide(worldIn, pos, side);
  70.     }
  71.  
  72.     @Override
  73.     public void observedNeighborChange(IBlockState observerState, World world, BlockPos observerPos, Block changedBlock,
  74.             BlockPos changedBlockPos) {
  75.         super.observedNeighborChange(observerState, world, observerPos, changedBlock, changedBlockPos);
  76.         this.checkAndDropBlock(world, observerPos, world.getBlockState(observerPos));
  77.         System.out.println("CHANGE");
  78.     }
  79.  
  80.     @Override
  81.     public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
  82.         this.checkAndDropBlock(worldIn, pos, state);
  83.         System.out.println("BLOCk");
  84.     }
  85.  
  86.     protected void checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state) {
  87.         if (!this.canBlockStay(worldIn, pos, state)) {
  88.             this.dropBlockAsItem(worldIn, pos, state, 0);
  89.             worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
  90.         }
  91.     }
  92.  
  93.     public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) {
  94.         System.out.println("CAN STAY?");
  95.         if (worldIn.getBlockState(pos.down()).getBlock() != TANBlocks.campfire) {
  96.             return false;
  97.         }
  98.         return true;
  99.     }
  100.  
  101.     @Override
  102.     public TileEntity createNewTileEntity(World worldIn, int meta) {
  103.         return new TileEntitySpit();
  104.     }
  105.  
  106.     @Override
  107.     public EnumBlockRenderType getRenderType(IBlockState state) {
  108.         return EnumBlockRenderType.MODEL;
  109.     }
  110.  
  111.     /*============================FORGE START=====================================*/
  112.     // Make sure block drops are correct
  113.     @Override
  114.     public java.util.List<ItemStack> getDrops(IBlockAccess worldIn, BlockPos pos, IBlockState state, int fortune) {
  115.  
  116.         // Create drop list
  117.         ArrayList<ItemStack> drop = new ArrayList<ItemStack>();
  118.  
  119.         // Get TileEntity
  120.         TileEntitySpit te = (TileEntitySpit) worldIn.getTileEntity(pos);
  121.  
  122.         if (te != null) {
  123.             drop.add(new ItemStack(Blocks.LIT_REDSTONE_LAMP)); //Test item
  124.         }
  125.  
  126.         return drop;
  127.     }
  128.  
  129.     // Makes sure the TE isn't deleted before the block
  130.     @Override
  131.     public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
  132.         if (willHarvest) return true; //If it will harvest, delay deletion of the block until after getDrops
  133.         return super.removedByPlayer(state, world, pos, player, willHarvest);
  134.     }
  135.  
  136.     // Makes sure the block is deleted correctly
  137.     @Override
  138.     public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, ItemStack stack) {
  139.         super.harvestBlock(worldIn, player, pos, state, te, stack);
  140.     }
  141.  
  142.     /**
  143.      * Get a list of the {@link IItemHandler}'s contents with the stacks randomly split.
  144.      * <p>
  145.      * Adapted from {@link InventoryHelper#dropInventoryItems}.
  146.      *
  147.      * @param itemHandler The inventory
  148.      * @param random      The Random object
  149.      * @return The drops list
  150.      */
  151.     public static List<ItemStack> dropItemHandlerContents(IItemHandler itemHandler, Random random) {
  152.         final List<ItemStack> drops = new ArrayList<ItemStack>();
  153.  
  154.         drops.add(new ItemStack(Blocks.ACACIA_STAIRS)); //Test item
  155.  
  156.         return drops;
  157.     }
  158.     /*===========================FORGE END==========================================*/
  159.  
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement