Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.github.wolfiewaffle.tanspit.blocks;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import com.github.wolfiewaffle.tanspit.tileentity.TileEntitySpit;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockContainer;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.inventory.InventoryHelper;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.BlockRenderLayer;
- import net.minecraft.util.EnumBlockRenderType;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.math.AxisAlignedBB;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import net.minecraftforge.items.IItemHandler;
- import toughasnails.api.TANBlocks;
- public class BlockSpit extends BlockContainer {
- public BlockSpit(String name) {
- super(Material.ANVIL);
- this.setTickRandomly(true);
- this.setRegistryName(name);
- this.setUnlocalizedName(name);
- this.setLightOpacity(0);
- this.fullBlock = false;
- }
- @Override
- public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
- return new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 0.25, 1.0);
- }
- @Override
- public AxisAlignedBB getCollisionBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
- return NULL_AABB;
- }
- @Override
- public boolean isOpaqueCube(IBlockState state) {
- return false;
- }
- @Override
- public boolean isFullCube(IBlockState state) {
- return false;
- }
- @Override
- public BlockRenderLayer getBlockLayer() {
- return BlockRenderLayer.CUTOUT_MIPPED;
- }
- @Override
- public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side) {
- if (side != EnumFacing.UP || worldIn.getBlockState(pos.down()).getBlock() != TANBlocks.campfire) {
- return false;
- }
- return super.canPlaceBlockOnSide(worldIn, pos, side);
- }
- @Override
- public void observedNeighborChange(IBlockState observerState, World world, BlockPos observerPos, Block changedBlock,
- BlockPos changedBlockPos) {
- super.observedNeighborChange(observerState, world, observerPos, changedBlock, changedBlockPos);
- this.checkAndDropBlock(world, observerPos, world.getBlockState(observerPos));
- System.out.println("CHANGE");
- }
- @Override
- public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
- this.checkAndDropBlock(worldIn, pos, state);
- System.out.println("BLOCk");
- }
- protected void checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state) {
- if (!this.canBlockStay(worldIn, pos, state)) {
- this.dropBlockAsItem(worldIn, pos, state, 0);
- worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
- }
- }
- public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) {
- System.out.println("CAN STAY?");
- if (worldIn.getBlockState(pos.down()).getBlock() != TANBlocks.campfire) {
- return false;
- }
- return true;
- }
- @Override
- public TileEntity createNewTileEntity(World worldIn, int meta) {
- return new TileEntitySpit();
- }
- @Override
- public EnumBlockRenderType getRenderType(IBlockState state) {
- return EnumBlockRenderType.MODEL;
- }
- /*============================FORGE START=====================================*/
- // Make sure block drops are correct
- @Override
- public java.util.List<ItemStack> getDrops(IBlockAccess worldIn, BlockPos pos, IBlockState state, int fortune) {
- // Create drop list
- ArrayList<ItemStack> drop = new ArrayList<ItemStack>();
- // Get TileEntity
- TileEntitySpit te = (TileEntitySpit) worldIn.getTileEntity(pos);
- if (te != null) {
- drop.add(new ItemStack(Blocks.LIT_REDSTONE_LAMP)); //Test item
- }
- return drop;
- }
- // Makes sure the TE isn't deleted before the block
- @Override
- public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
- if (willHarvest) return true; //If it will harvest, delay deletion of the block until after getDrops
- return super.removedByPlayer(state, world, pos, player, willHarvest);
- }
- // Makes sure the block is deleted correctly
- @Override
- public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, ItemStack stack) {
- super.harvestBlock(worldIn, player, pos, state, te, stack);
- }
- /**
- * Get a list of the {@link IItemHandler}'s contents with the stacks randomly split.
- * <p>
- * Adapted from {@link InventoryHelper#dropInventoryItems}.
- *
- * @param itemHandler The inventory
- * @param random The Random object
- * @return The drops list
- */
- public static List<ItemStack> dropItemHandlerContents(IItemHandler itemHandler, Random random) {
- final List<ItemStack> drops = new ArrayList<ItemStack>();
- drops.add(new ItemStack(Blocks.ACACIA_STAIRS)); //Test item
- return drops;
- }
- /*===========================FORGE END==========================================*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement