Jump to content

[1.7.10] Problem with custom furnace


The__Cow

Recommended Posts

Hello, I recently decided to create a sort of furnace for my mod named Ore Crusher. Every thing works very well except when I leave the save I am on, the items from the bottom and the output goes back into where the blocks smelt and I lose every thing that was into this slot. I hope it's clear.. But here is my classes: 

OreCrusher

package ca.thecow.morecontent.blocks;

import java.util.Random;

import ca.thecow.morecontent.MoreContent;
import ca.thecow.morecontent.Ref;
import ca.thecow.morecontent.init.Blocks;
import ca.thecow.morecontent.tile_entity.TileEntityOreCrusher;
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.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.World;

public class OreCrusher extends BlockContainer{
	
	@SideOnly(Side.CLIENT)
	private IIcon top;
	@SideOnly(Side.CLIENT)
	private IIcon front;
	
	private static boolean isBurning;
	private final boolean isBurning2;
	private final Random random = new Random();

	public OreCrusher(boolean isActive) {
		super(Material.rock);
		isBurning2 = isActive;
	}
	
	@SideOnly(Side.CLIENT)
	public void registerBlockIcons(IIconRegister iconregister){
		this.blockIcon = iconregister.registerIcon(Ref.MOD_ID + ":ore_crusher_side");
		this.front = iconregister.registerIcon(this.isBurning2 ? Ref.MOD_ID + ":ore_crusher_active" : Ref.MOD_ID + ":ore_crusher_inactive");
		this.top = iconregister.registerIcon(Ref.MOD_ID + ":ore_crusher_top");
	}
	
	public IIcon getIcon(int side, int meta){
		return meta == 0 && side == 3 ? this.front : (side == 1 ? this.top : (side == 0 ? this.top : (side == meta ? this.front : this.blockIcon)));
	}
	
	@Override
	public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
		player.openGui(MoreContent.modInstance, 0, world, x, y, z);
		return true;
		
	}
	
	public Item getItemDropped(int par1, Random random, int par3){
		return Item.getItemFromBlock(Blocks.ore_crusher);
	}
	
	public Item getItem(World world, int par2, int par3, int par4){
		return Item.getItemFromBlock(Blocks.ore_crusher);
	}
	
	@SideOnly(Side.CLIENT)
	public void onBlockAdded(World world, int x, int y, int z){
		super.onBlockAdded(world, x, y, z);
		this.direction(world, x, y, z);
	}
	
	private void direction(World world, int x, int y, int z){
		if(!world.isRemote){
			Block direction1 = world.getBlock(x, y, z - 1);
			Block direction2 = world.getBlock(x, y, z + 1);
			Block direction3 = world.getBlock(x - 1, y, z);
			Block direction4 = world.getBlock(x + 1, y, z);
			byte byte0 = 3;
			
			if(direction1.func_149730_j() && direction1.func_149730_j()){
				byte0 = 3;
			}
			if(direction2.func_149730_j() && direction2.func_149730_j()){
				byte0 = 2;
			}
			if(direction3.func_149730_j() && direction3.func_149730_j()){
				byte0 = 5;
			}
			if(direction4.func_149730_j() && direction4.func_149730_j()){
				byte0 = 4;
			}
			
			world.setBlockMetadataWithNotify(x, y, z, byte0, 2);
		}
	}
	
	public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemstack){
		int direction = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
		
		if(direction == 0){
			world.setBlockMetadataWithNotify(x, y, z, 2, 2);
		}
		if(direction == 1){
			world.setBlockMetadataWithNotify(x, y, z, 5, 2);
		}
		if(direction == 2){
			world.setBlockMetadataWithNotify(x, y, z, 3, 2);
		}
		if(direction == 3){
			world.setBlockMetadataWithNotify(x, y, z, 4, 2);
		}
		
		if(itemstack.hasDisplayName()){
			((TileEntityOreCrusher) world.getTileEntity(x, y, z)).oreCrusherName(itemstack.getDisplayName());
		}
	}
	
	public static void updateBlockState(boolean burning, World world, int x, int y, int z){
		int direction = world.getBlockMetadata(x, y, z);
		TileEntity tileentity = world.getTileEntity(x, y, z);
		isBurning = true;
		
		if(burning){
			world.setBlock(x, y, z, Blocks.ore_crusher_active);
		}else{
			world.setBlock(x, y, z, Blocks.ore_crusher);
		}
		
		isBurning = false;
		world.setBlockMetadataWithNotify(x, y, z, direction, 2);
		
		if(tileentity != null){
			tileentity.validate();
			world.setTileEntity(x, y, z, tileentity);
		}
	}
	
	public void breakBlock(World world, int x, int y, int z, Block block, int meta){
		if(!isBurning){
			TileEntityOreCrusher tileentityorecrusher = (TileEntityOreCrusher) world.getTileEntity(x, y, z);
			if(tileentityorecrusher != null){
				for(int i = 0; i < tileentityorecrusher.getSizeInventory(); ++i){
					ItemStack itemstack = tileentityorecrusher.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) x + f), (double) ((float) y + f1), (double) ((float) z + f2), new ItemStack(itemstack.getItem(), j, itemstack.getItemDamage()));
						
							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_147453_f(x, y, z, block);
			}
		}
		super.breakBlock(world, x, y, z, block, meta);
	}
	
	@SideOnly(Side.CLIENT)
	public void randomDisplayTick(World world, int x, int y, int z, Random random){
		if(this.isBurning2){
			int direction = world.getBlockMetadata(x, y, z);
			float xx = (float) x + 0.5F, yy = (float) y + random.nextFloat() * 6.0F / 16.0F, zz = (float) z + 0.5F, xx2 = random.nextFloat() * 0.3F, zz2 = 0.5F;
			
			if(direction == 4){
				world.spawnParticle("smoke", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
				world.spawnParticle("flame", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
			}else if(direction == 5){
				world.spawnParticle("smoke", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
				world.spawnParticle("flame", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
			}else if(direction == 3){
				world.spawnParticle("smoke", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
				world.spawnParticle("flame", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
			}else if(direction == 2){
				world.spawnParticle("smoke", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
				world.spawnParticle("flame", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
			}
		}
	}

	@Override
	public TileEntity createNewTileEntity(World world, int par2) {
		return new TileEntityOreCrusher();
	}


}

 

ContainerOreCrusher

package ca.thecow.morecontent.inventory;

import ca.thecow.morecontent.tile_entity.TileEntityOreCrusher;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnace;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;

public class ContainerOreCrusher extends Container{
	
	private TileEntityOreCrusher tileOreCrusher;
	private int lastCookTime;
	private int lastBurnTime;
	private int lastItemBurnTime;
	
	public ContainerOreCrusher(InventoryPlayer player, TileEntityOreCrusher tileEntityOreCrusher){
		this.tileOreCrusher = tileEntityOreCrusher;
		this.addSlotToContainer(new Slot(tileEntityOreCrusher, 0, 56, 17));
		this.addSlotToContainer(new Slot(tileEntityOreCrusher, 1, 56, 53));
		this.addSlotToContainer(new SlotFurnace(player.player, tileEntityOreCrusher, 2, 116, 35));
		int i;
		
		for(i = 0; i < 3; ++i){
			for(int j = 0; j < 9; ++j){
				this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
			}
		}
		
		for(i = 0; i < 9; ++i){
			this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142));
		}
		
	}
	
	public void addCraftingToCrafters(ICrafting craft){
		super.addCraftingToCrafters(craft);
		craft.sendProgressBarUpdate(this, 0, this.tileOreCrusher.oreCrusherCookTime);
		craft.sendProgressBarUpdate(this, 1, this.tileOreCrusher.oreCrusherBurnTime);
		craft.sendProgressBarUpdate(this, 2, this.tileOreCrusher.currentBurnTime);
	}
	
	public void detectAndSendChanges(){
		super.detectAndSendChanges();
		for(int i = 0; i < this.crafters.size(); ++i){
			ICrafting craft = (ICrafting) this.crafters.get(i);
			
			if(this.lastCookTime != this.tileOreCrusher.oreCrusherCookTime){
				craft.sendProgressBarUpdate(this, 0, this.tileOreCrusher.oreCrusherCookTime);
			}
			if(this.lastBurnTime != this.tileOreCrusher.oreCrusherBurnTime){
				craft.sendProgressBarUpdate(this, 1, this.tileOreCrusher.oreCrusherBurnTime);
			}
			if(this.lastItemBurnTime != this.tileOreCrusher.currentBurnTime){
				craft.sendProgressBarUpdate(this, 2, this.tileOreCrusher.currentBurnTime);
			}
		}
		
		this.lastBurnTime = this.tileOreCrusher.oreCrusherBurnTime;
		this.lastItemBurnTime = this.tileOreCrusher.currentBurnTime;
		this.lastCookTime = this.tileOreCrusher.oreCrusherCookTime;
	}
	
	@SideOnly(Side.CLIENT)
	public void updateProgressBar(int par1, int par2){
		if(par1 == 0){
			this.tileOreCrusher.oreCrusherCookTime = par2;
		}
		if(par1 == 1){
			this.tileOreCrusher.oreCrusherBurnTime = par2;
		}
		if(par1 == 2){
			this.tileOreCrusher.currentBurnTime = par2;
		}
	}
	
	@Override
	public boolean canInteractWith(EntityPlayer player) {
		return this.tileOreCrusher.isUseableByPlayer(player);
	}
	
	public ItemStack transferStackInSlot(EntityPlayer player, int par2){
		ItemStack itemStack = null;
		Slot slot = (Slot) this.inventorySlots.get(par2);
		
		if(slot != null && slot.getHasStack()){
			ItemStack itemStack1 = slot.getStack();
			itemStack = itemStack1.copy();
			
			if(par2 == 2){
				if(!this.mergeItemStack(itemStack1, 3, 39, true)){
					return null;
				}
				slot.onSlotChange(itemStack1, itemStack);
			}else if(par2 != 1 && par2 != 0){
				if(FurnaceRecipes.smelting().getSmeltingResult(itemStack1) != null){
					if(!this.mergeItemStack(itemStack1, 0, 1, false)){
						return null;
					}
				}else if(TileEntityOreCrusher.isItemFuel(itemStack1)){
					if(!this.mergeItemStack(itemStack1, 1, 2, false)){
						return null;
					}
				}else if(par2 >= 3 && par2 < 30){
					if(!this.mergeItemStack(itemStack1, 30, 39, false)){
						return null;
					}
				}else if(par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemStack1, 3, 30, false)){
					return null;
				}
			}else if(!this.mergeItemStack(itemStack1, 3, 39, false)){
				return null;
			}
			if(itemStack1.stackSize == 0){
				slot.putStack((ItemStack) null);
			}else{
				slot.onSlotChanged();
			}
			if(itemStack1.stackSize == itemStack.stackSize){
				return null;
			}
			slot.onPickupFromSlot(player, itemStack1);
		}
		return itemStack;
	}

}

 

GuiOreCrusher

package ca.thecow.morecontent.gui;

import org.lwjgl.opengl.GL11;

import ca.thecow.morecontent.Ref;
import ca.thecow.morecontent.inventory.ContainerOreCrusher;
import ca.thecow.morecontent.tile_entity.TileEntityOreCrusher;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;

@SideOnly(Side.CLIENT)
public class GuiOreCrusher extends GuiContainer{
	
	private static final ResourceLocation oreCrusherGuiTextures = new ResourceLocation(Ref.MOD_ID + ":textures/gui/container/orecrusher.png");
	private TileEntityOreCrusher tileOreCrusher;

	public GuiOreCrusher(InventoryPlayer invPlayer, TileEntityOreCrusher tile) {
		super(new ContainerOreCrusher(invPlayer, tile));
		this.tileOreCrusher = tile;
	}
	
	protected void drawGuiContainerForegroundLayer(int par1, int par2){
		String string = this.tileOreCrusher.hasCustomInventoryName() ? this.tileOreCrusher.getInventoryName() : I18n.format(this.tileOreCrusher.getInventoryName(), new Object[0]);
		this.fontRendererObj.drawString(string, this.xSize / 2 - this.fontRendererObj.getStringWidth(string), 6, 4210752);
		this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
	}

	@Override
	protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		this.mc.getTextureManager().bindTexture(oreCrusherGuiTextures);
		int k = (this.width - this.xSize) / 2;
		int l = (this.height - this.ySize) / 2;
		this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
		int il;
		if(this.tileOreCrusher.isBurning()){
			il = this.tileOreCrusher.getBurnTimeRemainingScaled(12);
			this.drawTexturedModalRect(k + 56, l + 36 + 12 - il, 176, 12 - il, 14, il + 1);
		}
		
		il = this.tileOreCrusher.getCookProgressScaled(24);
		this.drawTexturedModalRect(k + 79, l + 34, 176, 14, il + 1, 16);
	}

}

 

TileEntityOreCrusher

package ca.thecow.morecontent.tile_entity;

import ca.thecow.morecontent.blocks.OreCrusher;
import ca.thecow.morecontent.init.Items;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;

public class TileEntityOreCrusher extends TileEntity implements ISidedInventory{
	
	private static final int[] slotsTop = new int[]{ 0 };
	private static final int[] slotsBottom = new int[]{ 2, 1 };
	private static final int[] slotsSides = new int[]{ 1 };
	
	private ItemStack[] oreCrusherItemStacks = new ItemStack[3];
	
	public int oreCrusherBurnTime;
	public int currentBurnTime;
	public int oreCrusherCookTime;
	public int furnaceSpeed = 300;
	
	private String oreCrusherName;
	
	public void oreCrusherName(String string){
		this.oreCrusherName = string;
	}

	@Override
	public int getSizeInventory() {
		return this.oreCrusherItemStacks.length;
	}

	@Override
	public ItemStack getStackInSlot(int slot) {
		return this.oreCrusherItemStacks[slot];
	}

	@Override
	public ItemStack decrStackSize(int var1, int var2) {
		if(this.oreCrusherItemStacks[var1] != null){
			ItemStack itemStack;
			if(this.oreCrusherItemStacks[var1].stackSize <= var2){
				itemStack = this.oreCrusherItemStacks[var1];
				this.oreCrusherItemStacks[var1] = null;
				return itemStack;
			}else{
				itemStack = this.oreCrusherItemStacks[var1].splitStack(var2);
				
				if(this.oreCrusherItemStacks[var1].stackSize == 0){
					this.oreCrusherItemStacks[var1] = null;
				}
				return itemStack;
			}
		}else{
			return null;
		}
	}

	@Override
	public ItemStack getStackInSlotOnClosing(int slot) {
		if(this.oreCrusherItemStacks[slot] != null){
			ItemStack itemStack = this.oreCrusherItemStacks[slot];
			this.oreCrusherItemStacks[slot] = null;
			return itemStack;
		}else{
			return null;
		}
	}

	@Override
	public void setInventorySlotContents(int slot, ItemStack itemStack) {
		this.oreCrusherItemStacks[slot] = itemStack;
		
		if(itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()){
			itemStack.stackSize = this.getInventoryStackLimit();
			
		}
		
	}

	@Override
	public String getInventoryName() {
		return this.hasCustomInventoryName() ? this.oreCrusherName : "Ore Crusher";
	}

	@Override
	public boolean hasCustomInventoryName() {
		return this.oreCrusherName != null && this.oreCrusherName.length() > 0;
	}

	@Override
	public int getInventoryStackLimit() {
		return 64;
	}
	
	public void readFromNBT(NBTTagCompound tagCompound){
		super.readFromNBT(tagCompound);
		NBTTagList tagList = tagCompound.getTagList("Items", 10);
		this.oreCrusherItemStacks = new ItemStack[this.getSizeInventory()];
		
		for(int i = 0; i < tagList.tagCount(); i++){
			NBTTagCompound tagCompound1 = tagList.getCompoundTagAt(i);
			byte byte0 = tagCompound1.getByte("Slot");
			
			if(byte0 >= 0 && byte0 < this.oreCrusherItemStacks.length){
				this.oreCrusherItemStacks[byte0] = ItemStack.loadItemStackFromNBT(tagCompound1);
			}
		}
		
		this.oreCrusherBurnTime = (int)tagCompound.getShort("BurnTime");
		this.oreCrusherCookTime = (int)tagCompound.getShort("CookTime");
		this.currentBurnTime = getItemBurnTime(this.oreCrusherItemStacks[1]);
		
		if(tagCompound.hasKey("CustomName", 8)){
			this.oreCrusherName = tagCompound.getString("CustomName");
		}
	}
	
	public void writeToNBT(NBTTagCompound tagCompound){
		super.writeToNBT(tagCompound);
		
		tagCompound.setShort("BurnTime", (short) this.oreCrusherBurnTime);
		tagCompound.setShort("CookTime", (short) this.oreCrusherCookTime);
		NBTTagList tagList = new NBTTagList();
		
		for(int i = 0; i < this.oreCrusherItemStacks.length; ++i){
			if(this.oreCrusherItemStacks[i] != null){
				NBTTagCompound tagCompound1 = new NBTTagCompound();
				tagCompound1.setByte("slot", (byte) i);
				this.oreCrusherItemStacks[i].writeToNBT(tagCompound1);
				tagList.appendTag(tagCompound1);
			}
		}
		
		tagCompound.setTag("Items", tagList);
		
		if(this.hasCustomInventoryName()){
			tagCompound.setString("CustomName", this.oreCrusherName);
		}
	}
	
	@SideOnly(Side.CLIENT)
	public int getCookProgressScaled(int par1){
		return this.oreCrusherCookTime * par1 / this.furnaceSpeed;
	}
	
	@SideOnly(Side.CLIENT)
	public int getBurnTimeRemainingScaled(int par1){
		if(this.currentBurnTime == 0){
			this.currentBurnTime = 200;
		}
		return this.oreCrusherBurnTime * par1 / this.currentBurnTime;
	}
	
	public boolean isBurning(){
		return this.oreCrusherBurnTime > 0;
	}
	
	public void updateEntity(){
		boolean flag = this.oreCrusherBurnTime > 0;
		boolean flag1 = false;
		
		if(this.oreCrusherBurnTime > 0){
			--this.oreCrusherBurnTime;
		}
		
		if(!this.worldObj.isRemote){
			if(this.oreCrusherBurnTime != 0 || this.oreCrusherItemStacks[1] != null && this.oreCrusherItemStacks[0] != null){
			if(this.oreCrusherBurnTime == 0 && this.canSmelt()){
				this.currentBurnTime = this.oreCrusherBurnTime = getItemBurnTime(this.oreCrusherItemStacks[1]);
				
				if(this.oreCrusherBurnTime > 0){
					flag1 = true;
					if(this.oreCrusherItemStacks[1] != null){
						--this.oreCrusherItemStacks[1].stackSize;
						
						if(this.oreCrusherItemStacks[1].stackSize == 0){
							this.oreCrusherItemStacks[1] = oreCrusherItemStacks[1].getItem().getContainerItem(this.oreCrusherItemStacks[1]);
						}
					}
				}
			}
			
			if(this.isBurning() && this.canSmelt()){
				++this.oreCrusherCookTime;
				if(this.oreCrusherCookTime == 200){
					this.oreCrusherCookTime = 0;
					this.smeltItem();
					flag1 = true;
				}
			}else{
				this.oreCrusherCookTime = 0;
			}
		}
		
		if(flag != this.oreCrusherBurnTime > 0){
			flag1 = true;
			OreCrusher.updateBlockState(this.oreCrusherBurnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}
		
		if(flag1){
			this.markDirty();
		}
		}
	}
	
	private boolean canSmelt(){
		if(this.oreCrusherItemStacks[0] == null){
			return false;
		}else{
			ItemStack itemStack = FurnaceRecipes.smelting().getSmeltingResult(this.oreCrusherItemStacks[0]);
			if(itemStack == null) return false;
			if(this.oreCrusherItemStacks[2] == null) return true;
			if(!this.oreCrusherItemStacks[2].isItemEqual(itemStack)) return false;
			int result = oreCrusherItemStacks[2].stackSize + itemStack.stackSize;
			return result <= getInventoryStackLimit() && result <= this.oreCrusherItemStacks[2].getMaxStackSize();
		}
	}
	
	public void smeltItem(){
		if(this.canSmelt()){
			ItemStack itemStack = FurnaceRecipes.smelting().getSmeltingResult(this.oreCrusherItemStacks[0]);
			
			if(this.oreCrusherItemStacks[2] == null){
				this.oreCrusherItemStacks[2] = itemStack.copy();
			}else if(this.oreCrusherItemStacks[2].getItem() == itemStack.getItem()){
				this.oreCrusherItemStacks[2].stackSize += itemStack.stackSize;
			}
			
			--this.oreCrusherItemStacks[0].stackSize;
			
			if(this.oreCrusherItemStacks[0].stackSize <= 0){
				this.oreCrusherItemStacks[0] = null;
			}
		}
	}
	
	public static int getItemBurnTime(ItemStack itemStack){
		if(itemStack == null){
			return 0;
		}else{
			Item item = itemStack.getItem();
			
			if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air){
				Block block = Block.getBlockFromItem(item);
				
				if(block == ca.thecow.morecontent.init.Blocks.copper_block){
					return 14400;
				}
			}
			
			if(item == Items.copper_ingot){
				return 1600;
			}
			
			return 0;
		}
	}
	
	public static boolean isItemFuel(ItemStack itemStack){
		return getItemBurnTime(itemStack) > 0;
	}

	@Override
	public boolean isUseableByPlayer(EntityPlayer player) {
		return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D;
	}

	@Override
	public void openInventory() {
		
	}

	@Override
	public void closeInventory() {
		
	}

	@Override
	public boolean isItemValidForSlot(int par1, ItemStack itemStack) {
		return par1 == 2 ? false : (par1 == 1 ? isItemFuel(itemStack) : true);
	}

	@Override
	public int[] getAccessibleSlotsFromSide(int par1) {
		return par1 == 0 ? slotsBottom : (par1 == 1) ? slotsTop : slotsSides;
	}

	@Override
	public boolean canInsertItem(int par1, ItemStack itemStack, int par3) {
		// TODO Auto-generated method stub
		return this.isItemValidForSlot(par1, itemStack);
	}

	@Override
	public boolean canExtractItem(int par1, ItemStack itemStack, int par3) {
		// TODO Auto-generated method stub
		return par3 != 0 || par1 != 1 || itemStack.getItem() == net.minecraft.init.Items.bucket;
	}

}

 

GuiHandler

package ca.thecow.morecontent.handler;

import ca.thecow.morecontent.gui.GuiOreCrusher;
import ca.thecow.morecontent.inventory.ContainerOreCrusher;
import ca.thecow.morecontent.tile_entity.TileEntityOreCrusher;
import cpw.mods.fml.common.network.IGuiHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;

public class GuiHandler implements IGuiHandler{

	@Override
	public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
		if(ID == 0){
			TileEntityOreCrusher tileEntityOreCrusher = (TileEntityOreCrusher) world.getTileEntity(x, y, z);
			return new ContainerOreCrusher(player.inventory, tileEntityOreCrusher);
		}
		return null;
	}

	@Override
	public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
		if(ID == 0){
			TileEntityOreCrusher tileEntityOreCrusher = (TileEntityOreCrusher) world.getTileEntity(x, y, z);
			return new GuiOreCrusher(player.inventory, tileEntityOreCrusher);
		}
		return null;
	}

}

 

Link to comment
Share on other sites

1.7.10 is not supported on this forum please update if you wish to receive help. This thread will later be locked by a moderator.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.