Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.xenocorpse.wulfenite.blocks;
- import java.util.Random;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockContainer;
- import net.minecraft.block.BlockWorkbench;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.state.BlockState;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.ContainerFurnace;
- import net.minecraft.inventory.ContainerWorkbench;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.BlockPos;
- import net.minecraft.util.ChatComponentTranslation;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.IChatComponent;
- import net.minecraft.world.IInteractionObject;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- import com.xenocorpse.wulfenite.Wulfenite;
- import com.xenocorpse.wulfenite.init.wulfeniteBlocks;
- import com.xenocorpse.wulfenite.inventory.ContainerGrinder;
- import com.xenocorpse.wulfenite.tileentities.TileEntityGrinder;
- public class BlockGrinder extends BlockContainer{
- private static boolean isBurning;
- private final Random random = new Random();
- private World world;
- private BlockPos pos;
- public BlockGrinder(Material material) {
- super(material);
- }
- @Override
- public TileEntityGrinder createNewTileEntity(World worldIn, int meta) {
- return new TileEntityGrinder();
- }
- public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
- {
- if (worldIn.isRemote)
- {
- return true;
- }
- else
- {
- playerIn.displayGui(new BlockGrinder.InterfaceGrinder(worldIn, pos));
- return true;
- }
- }
- public static class InterfaceGrinder implements IInteractionObject
- {
- private final World world;
- private final BlockPos position;
- private static final String __OBFID = "CL_00002127";
- public InterfaceGrinder(World worldIn, BlockPos pos)
- {
- this.world = worldIn;
- this.position = pos;
- }
- public String getName()
- {
- return null;
- }
- public boolean hasCustomName()
- {
- return false;
- }
- public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
- {
- return new ContainerGrinder(playerInventory, this.world, this.position);
- }
- public String getGuiID()
- {
- return "minecraft:crafting_table";
- }
- @Override
- public IChatComponent getDisplayName() {
- return new ChatComponentTranslation(wulfeniteBlocks.grinder.getUnlocalizedName() + ".name", new Object[0]);
- }
- }
- public Item getItemDropped(int par1, Random random, int par3){
- return Item.getItemFromBlock(wulfeniteBlocks.grinder);
- }
- public Item getItem(World world, int par2, int par3, int par4){
- return Item.getItemFromBlock(wulfeniteBlocks.grinder);
- }
- @SideOnly(Side.CLIENT)
- public void onBlockAdded(World world, BlockPos blockPos, BlockState blockState){
- super.onBlockAdded(world, blockPos, (IBlockState) blockState);
- }
- public static void updateBlockState(boolean burning, BlockPos pos, World world){
- TileEntity tileentity = world.getTileEntity(pos);
- if(tileentity != null){
- tileentity.validate();
- world.setTileEntity(pos, tileentity);
- }
- }
- public void breakBlock(World world, BlockPos pos, Block block, IBlockState meta){
- if(!isBurning(world, pos)){
- TileEntityGrinder tileentitygrinder = (TileEntityGrinder) world.getTileEntity(pos);
- if(tileentitygrinder != null){
- for(int i = 0; i < tileentitygrinder.getInventoryStackLimit(); ++i){
- ItemStack itemstack = tileentitygrinder.getStackInSlot(i);
- if(itemstack != null){
- float f = this.random.nextFloat() * 0.6f + 0.1f;
- float f1 = this.random.nextFloat() * 0.6f + 0.1f;
- float f2 = this.random.nextFloat() * 0.6f + 0.1f;
- while(itemstack.stackSize > 0){
- int j = this.random.nextInt(21) + 10;
- if(j > itemstack.stackSize){
- j = itemstack.stackSize;
- }
- itemstack.stackSize -= j;
- EntityItem entityitem = new EntityItem(world, (double) ((float) pos.getX() + f), (double) ((float) pos.getY() + f1), (double) ((float) pos.getZ() + f2), itemstack);
- if(itemstack.hasTagCompound()){
- entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
- }
- float f3 = 0.025f;
- entityitem.motionX = (double) ((float) this.random.nextGaussian() * f3);
- entityitem.motionY = (double) ((float) this.random.nextGaussian() * f3 + 0.1f);
- entityitem.motionZ = (double) ((float) this.random.nextGaussian() * f3);
- world.spawnEntityInWorld(entityitem);
- }
- }
- }
- world.func_175665_u(pos);
- }
- }
- super.breakBlock(world, pos, meta);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment