Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package minefantasy.mf2.block.crafting;
- import java.util.ArrayList;
- import java.util.Random;
- import minefantasy.mf2.MineFantasyII;
- import minefantasy.mf2.api.crafting.BaseRecipeMF;
- import minefantasy.mf2.api.crafting.CarpenterRecipes;
- import minefantasy.mf2.api.helpers.ToolHelper;
- import minefantasy.mf2.block.tileentity.TileEntityCarpenter;
- import minefantasy.mf2.item.list.CreativeTabMF;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockContainer;
- import net.minecraft.block.material.Material;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.IIcon;
- import net.minecraft.world.World;
- import cpw.mods.fml.common.registry.GameRegistry;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- public class BlockCarpenterBench extends BlockContainer
- {
- private int tier = 0;
- private Random rand = new Random();
- public BlockCarpenterBench(String name)
- {
- super(Material.wood);
- GameRegistry.registerBlock(this, name);
- setBlockName(name);
- setBlockTextureName("minefantasy2:crafters/"+name);
- if(tier == 0)
- {
- this.setBlockBounds(0F, 0F, 0F, 1F, 0.5F, 1F);
- }
- this.setLightOpacity(0);
- this.setCreativeTab(CreativeTabMF.tabUtil);
- }
- @Override
- @SideOnly(Side.CLIENT)
- public IIcon getIcon(int side, int meta)
- {
- return Blocks.crafting_table.getIcon(side, meta);
- }
- /**
- * Called upon block activation (right click on the block.)
- */
- @Override
- public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float xOffset, float yOffset, float zOffset)
- {
- TileEntityCarpenter tile = getTile(world, x, y, z);
- ItemStack tool = player.getHeldItem();
- String tooltype = ToolHelper.getCrafterTool(tool);
- int toolTier = ToolHelper.getCrafterTier(tool);
- if(!world.isRemote && tile != null)
- {
- System.out.println(tile.toString());
- if (tile == null || player.isSneaking()) {
- return false;
- }
- player.openGui(MineFantasyII.instance, 0, world, x, y, z);
- }
- return true;
- }
- private void tryAdd(TileEntityCarpenter tile, String tab, String key)
- {
- if(tile.hasProject())
- {
- return;
- }
- ArrayList<BaseRecipeMF> list = CarpenterRecipes.getRecipeList(tab, key);
- if(list != null && !list.isEmpty())
- {
- BaseRecipeMF recipe = list.get(rand.nextInt(list.size()));
- if(recipe != null)
- {
- tile.setProject(recipe);
- }
- }
- }
- @Override
- public TileEntity createNewTileEntity(World world, int meta)
- {
- return new TileEntityCarpenter(tier);
- }
- private TileEntityCarpenter getTile(World world, int x, int y, int z)
- {
- return (TileEntityCarpenter)world.getTileEntity(x, y, z);
- }
- @Override
- public boolean isOpaqueCube()
- {
- return false;
- }
- @Override
- public void breakBlock(World world, int x, int y, int z, Block block, int meta)
- {
- TileEntityCarpenter tile = getTile(world, x, y, z);
- if (tile != null)
- {
- tile.clearProject(true);
- for (int i1 = 0; i1 < tile.getSizeInventory(); ++i1)
- {
- ItemStack itemstack = tile.getStackInSlot(i1);
- if (itemstack != null)
- {
- float f = this.rand .nextFloat() * 0.8F + 0.1F;
- float f1 = this.rand.nextFloat() * 0.8F + 0.1F;
- float f2 = this.rand.nextFloat() * 0.8F + 0.1F;
- while (itemstack.stackSize > 0)
- {
- int j1 = this.rand.nextInt(21) + 10;
- if (j1 > itemstack.stackSize)
- {
- j1 = itemstack.stackSize;
- }
- itemstack.stackSize -= j1;
- EntityItem entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
- if (itemstack.hasTagCompound())
- {
- entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
- }
- float f3 = 0.05F;
- entityitem.motionX = (double)((float)this.rand.nextGaussian() * f3);
- entityitem.motionY = (double)((float)this.rand.nextGaussian() * f3 + 0.2F);
- entityitem.motionZ = (double)((float)this.rand.nextGaussian() * f3);
- world.spawnEntityInWorld(entityitem);
- }
- }
- }
- world.func_147453_f(x, y, z, block);
- }
- super.breakBlock(world, x, y, z, block, meta);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement