Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.chef.mod.blocks;
- import java.util.Random;
- import com.chef.mod.Chef;
- import com.chef.mod.Reference;
- import com.chef.mod.init.MyBlocks;
- import com.chef.mod.tileentity.TileEntityIceCreamMaker;
- import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockContainer;
- import net.minecraft.block.ITileEntityProvider;
- import net.minecraft.block.material.Material;
- import net.minecraft.client.renderer.texture.IIconRegister;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.IIcon;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- public class IceCreamMaker extends BlockContainer {
- private final boolean isActive;
- @SideOnly(Side.CLIENT)
- private IIcon[] iconFrontOff;
- @SideOnly(Side.CLIENT)
- private IIcon[] iconFrontActive;
- @SideOnly(Side.CLIENT)
- private IIcon iconTop;
- private static boolean keepInventory;
- private Random rand = new Random();
- public IceCreamMaker(boolean isActive) {
- super(Material.iron);
- this.setTickRandomly(false);
- this.isActive = isActive;
- this.setHarvestLevel("pickaxe", 1);
- this.setStepSound(soundTypeMetal);
- this.setHardness(5.0F);
- this.setResistance(10.0F);
- }
- @SideOnly(Side.CLIENT)
- public void registerBlockIcons(IIconRegister iconRegister) {
- this.blockIcon = iconRegister.registerIcon("minecraft:" + "iron_block");
- this.iconTop = iconRegister.registerIcon("minecraft:" + "iron_block");
- this.iconFrontOff = new IIcon[11];
- this.iconFrontActive = new IIcon[11];
- for (int i = 0; i < this.iconFrontActive.length; i++) {
- this.iconFrontActive[i] = iconRegister.registerIcon(Reference.MOD_ID + ":" + "IceCreamMaker/ice_cream_maker_front_on_ice" + i);
- }
- for (int i = 0; i < this.iconFrontOff.length; i++) {
- this.iconFrontOff[i] = iconRegister.registerIcon(Reference.MOD_ID + ":" + "IceCreamMaker/ice_cream_maker_front_ice" + i);
- }
- }
- @SideOnly(Side.CLIENT)
- public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
- int metadata = world.getBlockMetadata(x, y, z);
- if (side == 1) {
- return this.iconTop;
- } else if (side == 0) {
- return this.iconTop;
- }
- TileEntity tile = world.getTileEntity(x, y, z);
- int level = 0;
- if (tile instanceof TileEntityIceCreamMaker) {
- level = Math.round(((TileEntityIceCreamMaker) tile).scaledIceLevel);
- }
- if ((metadata == 0 && side == 3) || side == metadata) {
- if (this.isActive) {
- return this.iconFrontActive[level];
- } else {
- return this.iconFrontOff[level];
- }
- }
- return this.blockIcon;
- }
- public Item getItemDropped(int i, Random random, int j) {
- return Item.getItemFromBlock(MyBlocks.ice_cream_maker);
- }
- public static String getFurnaceName(int x, int y, int z) {
- return (x + "/" + y + "/" + z);
- }
- public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
- if (!world.isRemote) {
- FMLNetworkHandler.openGui(player, Chef.instance, MyBlocks.guiID_ice_cream_maker, world, x, y, z);
- }
- return true;
- }
- public TileEntity createNewTileEntity(World worldIn, int meta) {
- return new TileEntityIceCreamMaker();
- }
- @Override
- public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) {
- int metadata = world.getBlockMetadata(x, y, z);
- int angle = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
- int change = 0;
- switch (angle) {
- case 0:
- change = 3;
- break;
- case 1:
- change = 1;
- break;
- case 2:
- change = 2;
- break;
- case 3:
- change = 0;
- break;
- }
- world.setBlockMetadataWithNotify(x, y, z, (metadata & 12) + change, 3);
- }
- public static void updateBlockState(boolean isActive, World worldObj, int xCoord, int yCoord, int zCoord) {
- int metadata = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
- TileEntity tileentity = worldObj.getTileEntity(xCoord, yCoord, zCoord);
- keepInventory = true;
- if (isActive) {
- worldObj.setBlock(xCoord, yCoord, zCoord, MyBlocks.ice_cream_maker_on);
- } else {
- worldObj.setBlock(xCoord, yCoord, zCoord, MyBlocks.ice_cream_maker);
- }
- keepInventory = false;
- worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, metadata, 2);
- if (tileentity != null) {
- tileentity.validate();
- worldObj.setTileEntity(xCoord, yCoord, zCoord, tileentity);
- }
- }
- public void breakBlock(World world, int x, int y, int z, Block oldblock, int oldMetadata) {
- if (!keepInventory) {
- TileEntityIceCreamMaker tileentity = (TileEntityIceCreamMaker) world.getTileEntity(x, y, z);
- if (tileentity != null) {
- for (int i = 0; i < tileentity.getSizeInventory(); i++) {
- ItemStack itemstack = tileentity.getStackInSlot(i);
- 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 j = this.rand.nextInt(21) + 10;
- if (j > itemstack.stackSize) {
- j = itemstack.stackSize;
- }
- itemstack.stackSize -= j;
- EntityItem item = new EntityItem(world, (double) ((float) x + f), (double) ((float) y + f1), (double) ((float) z + f2),
- new ItemStack(itemstack.getItem(), j, itemstack.getItemDamage()));
- if (itemstack.hasTagCompound()) {
- item.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
- }
- world.spawnEntityInWorld(item);
- }
- }
- }
- world.func_147453_f(x, y, z, oldblock);
- }
- }
- super.breakBlock(world, x, y, z, oldblock, oldMetadata);
- }
- public Item getItem(World world, int x, int y, int z) {
- return Item.getItemFromBlock(MyBlocks.ice_cream_maker);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement