Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package greatblitz.testmod.blocks;
- import java.util.List;
- import com.google.common.collect.Lists;
- import greatblitz.testmod.TestMod;
- import greatblitz.testmod.common.GuiHandler;
- import greatblitz.testmod.tileentity.TileEntityTestBlock;
- import net.minecraft.block.BlockContainer;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.InventoryHelper;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.EnumBlockRenderType;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.EnumHand;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import net.minecraftforge.items.CapabilityItemHandler;
- import net.minecraftforge.items.ItemStackHandler;
- public class TestBlock extends BlockContainer {
- public TestBlock() {
- super(Material.GLASS);
- setUnlocalizedName("testblock");
- setRegistryName("testblock");
- }
- @Override
- public void breakBlock(World world, BlockPos pos, IBlockState blockstate) {
- TileEntityTestBlock te = (TileEntityTestBlock) world.getTileEntity(pos);
- if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
- ItemStackHandler cap = (ItemStackHandler) te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
- for (int i = 0; i < cap.getSlots(); ++i)
- {
- ItemStack itemstack = cap.getStackInSlot(i);
- if (itemstack != null)
- {
- InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemstack);
- }
- }
- }
- super.breakBlock(world, pos, blockstate);
- }
- @Override
- public EnumBlockRenderType getRenderType(IBlockState state) {
- return EnumBlockRenderType.MODEL;
- }
- @Override
- public boolean isOpaqueCube(IBlockState state) {
- return false;
- }
- @Override
- public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
- EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
- if (!worldIn.isRemote) {
- TileEntityTestBlock te = (TileEntityTestBlock) worldIn.getTileEntity(pos);
- if (te == null) System.out.println("not null");
- System.out.println("Hello!");
- System.out.println("Energy: " + te.getEnergyStored(null) + "/" + te.getMaxEnergyStored(null));
- playerIn.openGui(TestMod.testmod, GuiHandler.GUI_TILE_ENTITY_TEST_BLOCK, worldIn, pos.getX(), pos.getY(), pos.getZ());
- }
- return true;
- }
- @Override
- public TileEntity createNewTileEntity(World worldIn, int meta) {
- return new TileEntityTestBlock();
- }
- @Override
- public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
- {
- return willHarvest || super.removedByPlayer(state, world, pos, player, false);
- }
- @Override
- public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
- {
- List<ItemStack> drops = Lists.newArrayList();
- TileEntityTestBlock te = (TileEntityTestBlock) world.getTileEntity(pos);
- if (te != null && te instanceof TileEntityTestBlock) {
- ItemStack i = new ItemStack(ModBlocks.testblock);
- NBTTagCompound compound = new NBTTagCompound();
- te.writeToNBT(compound);
- i.setTagCompound(compound);
- drops.add(i);
- }
- return drops;
- }
- @Override
- public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer,
- ItemStack stack) {
- TileEntity te = world.getTileEntity(pos);
- if (te != null && te instanceof TileEntityTestBlock) {
- if (!world.isRemote) {
- System.out.print("entered onBlockPlacedBy");
- TileEntityTestBlock ter = (TileEntityTestBlock) te;
- if (stack.hasTagCompound()) ter.readFromNBT(stack.getTagCompound());
- }
- }
- }
- @Override
- public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, ItemStack tool)
- {
- super.harvestBlock(world, player, pos, state, te, tool);
- world.setBlockToAir(pos);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement