Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

This is the code:

package com.SY031.tile_entity;

import com.SY031.block.TMBlock;
import com.SY031.block.washingmachine;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
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;
import net.minecraft.util.WeightedRandom.Item;

public class TileEntitywashingmachine 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[] furnaceItemStacks = new ItemStack[3];
	
	public int furnaceBurnTime;
	public int currentBurnTime;
	public int furnaceCookTime;
	
	private String furnaceName;
	
	public void furnaceName(String string){
	this.furnaceName = string;
	}
	@Override
	public int getSizeInventory() {
		return this.furnaceItemStacks.length;
	}

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

	@Override
	public ItemStack decrStackSize(int par1, int par2) {
		if(this.furnaceItemStacks[par1] != null){
			ItemStack itemstack;
			if(this.furnaceItemStacks[par1].stackSize <= par2){
				itemstack = this.furnaceItemStacks[par1];
						this.furnaceItemStacks[par1] = null;
						return itemstack;
		}else{
			itemstack = this.furnaceItemStacks[par1].splitStack(par2);
			
			if(this.furnaceItemStacks[par1].stackSize == 0){
				this.furnaceItemStacks[par1] = null;
				
			
			}
					return itemstack;
		}
		}else {
			return null;
		}
	}

	@Override
	public ItemStack getStackInSlotOnClosing(int slot){
		if(this.furnaceItemStacks[slot] != null){
			ItemStack itemstack = this.furnaceItemStacks[slot];
			this.furnaceItemStacks[slot] = null;
			return itemstack;
	}else{
		return null;
	}
	}
	@Override
	public void setInventorySlotContents(int slot,ItemStack itemstack) {
		this.furnaceItemStacks[slot] = itemstack;
		
		if(itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()){
			itemstack.stackSize = this.getInventoryStackLimit();
	
		}
		
	}

	@Override
	public String getInventoryName() {
		return this.hasCustomInventoryName() ? this.furnaceName : "세탁기";
	}

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

	@Override
	public int getInventoryStackLimit() {
		return 64;
	}

	public void readFromNBT(NBTTagCompound tagCompound){
		super.readFromNBT(tagCompound);
		NBTTagList tagList = tagCompound.getTagList("Items", 10);
		this.furnaceItemStacks = 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.furnaceItemStacks.length){
				this.furnaceItemStacks[byte0] = ItemStack.loadItemStackFromNBT(tagCompound1);
				
			}
		}
		this.furnaceBurnTime = tagCompound.getShort("BurnTime");
		this.furnaceCookTime = tagCompound.getShort("CookTime");
		this.currentBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
		
		if(tagCompound.hasKey("CustomName" , 8)){
			this.furnaceName = tagCompound.getString("CustomName");
		}
		}
	
	public void writeToNBT(NBTTagCompound tagCompound){
		super.writeToNBT(tagCompound);
		
		tagCompound.setShort("BurnTime", (short) this.furnaceBurnTime);
		tagCompound.setShort("CookTime", (short) this.furnaceBurnTime);
		NBTTagList taglist =  new NBTTagList();
		
		for(int i = 0; i < this.furnaceItemStacks.length; ++i)
		{
			if(this.furnaceItemStacks[i] != null){
				NBTTagCompound tagCompound1 = new NBTTagCompound();
				tagCompound1.setByte("Slot",(byte) i);
				this.furnaceItemStacks[i].writeToNBT(tagCompound1);
				taglist.appendTag(tagCompound1);
			}
			
		}
		
		tagCompound.setTag("Items", taglist);
		
		if(this.hasCustomInventoryName()){
			tagCompound.setString("CustomName", this.furnaceName);
		}
	}
	
	@SideOnly(Side.CLIENT)
	public int getCookProgressScaled(int par1){
		return this.furnaceCookTime * par1 / 200;
	}
	@SideOnly(Side.CLIENT)
	public int getBurnTimeRemainingScaled(int par1){
		if(this.currentBurnTime == 0){
			this.currentBurnTime = 200;
		}
		
		return this.furnaceBurnTime * par1 / this.currentBurnTime;
	}
	
	public boolean isBurning(){
		return this.furnaceBurnTime > 0;
	}
	public void updateEntity(){
		boolean flag = this.furnaceBurnTime > 0;
		boolean flag1 = false;
		
		if(this.furnaceBurnTime > 0){
			--this.furnaceBurnTime;
		}
		
		if(!this.worldObj.isRemote){
			if(this.isBurning() && this.canSmelt()){
				this.currentBurnTime = this.furnaceBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
				
				if(this.furnaceBurnTime > 0){
					flag1 = true;
					if(this.furnaceItemStacks[1] != null){
						--this.furnaceItemStacks[1].stackSize;
						
						if(this.furnaceItemStacks[1].stackSize == 0){
							this.furnaceItemStacks[1] = furnaceItemStacks[1].getItem().getContainerItem(this.furnaceItemStacks[1]);
							
						}
					}

				}
			}
			
			if(this.isBurning() && this.canSmelt()){
				++this.furnaceCookTime;
				if(this.furnaceCookTime == 200){
					this.furnaceCookTime = 0;
					this.smeltItem();
					flag1 = true;
				}
			}else{
				this.furnaceCookTime = 0;
			}
		}
		
		if(flag != this.furnaceBurnTime > 0){
			flag1 =true;
					washingmachine.updateBlockState(this.furnaceBurnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}
		if(flag1){
			this.markDirty();
		}
	}
	
	private boolean canSmelt(){
		if(this.furnaceItemStacks[0] == null){
			return false;
		}else{
			ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.furnaceItemStacks[0]);
			if(itemstack ==null) return false;
			if(this.furnaceItemStacks[2] == null) return true;
			if(!this.furnaceItemStacks[2].isItemEqual(itemstack)) return false;
			int result = furnaceItemStacks[2].stackSize + itemstack.stackSize;
			return result <= getInventoryStackLimit() && result <= this.furnaceItemStacks[2].getMaxStackSize();
		}
	}
	
	public void smeltItem(){
		if(this.canSmelt()){
			ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.furnaceItemStacks[0]);
			
			if(this.furnaceItemStacks[2] == null){
				this.furnaceItemStacks[2]= itemstack.copy();
			}else if(this.furnaceItemStacks[2].getItem() == itemstack.getItem()){
				this.furnaceItemStacks[2].stackSize += itemstack.stackSize;
			}
			
			--this.furnaceItemStacks[0].stackSize;
			
			if(this.furnaceItemStacks[0].stackSize >= 0);
				this.furnaceItemStacks[0] = null;
		}
	}
	public static int getItemBurnTime(ItemStack itemstack){
		if(itemstack == null){
			return 0;
			
		}else{
	net.minecraft.item.Item item = itemstack.getItem();
			
	if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air){
		Block block = Block.getBlockFromItem(item);
	}
		}
					}
		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 boolean isItemValidForSlot(int par1, ItemStack itemstack){
		
		return par1 == 2 ? false : (par1 == 1 ? isItemFuel(itemstack): true);
	}

	@Override
	public void closeInventory() {
		// TODO Auto-generated method stub
		
	}

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

	@Override
	public boolean canInsertItem(int par1, ItemStack itemstack, int par3) {
		return this.isItemValidForSlot(par1, itemstack);
	}

	@Override
	public boolean canExtractItem(int par1, ItemStack itemstack, int par3) {
		return par3 != 0 || par1 != 1 || itemstack.getItem() == Items.bucket;
	}

}

Everything works fine except the 'getItemburntime ' one.... could someone hlep me?
 

eclipse.PNG

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.