Jump to content

Recommended Posts

Posted

I'm doing a mod called Scoutcraft, and I am finishing my campfire, but is missing just one detail that I am not able to do, do spend the fuel without having items to be processed, please help me ...

 

My TileEntity:

 

package mike.scoutcraft.tileentity;

import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mike.scoutcraft.blocks.Fogueira;
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.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemTool;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;

public class TileEntityFogueira extends TileEntity implements ISidedInventory {

private String localizeName;

private static final int[] slots_top = new int[] {0,};
private static final int[] slots_bottom = new int[] {2, 1};
private static final int[] slots_sides = new int[] {1};


private ItemStack[] slots = new ItemStack[3];


public int fogueiraSpeed = 300;	
public int power;	
public int maxPower = 51200;	
public int cookTime;

@SideOnly(Side.CLIENT)
public int getFogueiraProgressScaled(int i) {
	return this.cookTime * i / this.fogueiraSpeed;
}

@SideOnly(Side.CLIENT)
public int getpowerRemainingScaled(int i) {		
	return this.power * i / this.maxPower;
}


public int getSizeInventory(){
	return this.slots.length;
}


public String getInventoryName(){
	return this.hasCustomInventoryName() ? this.localizeName : "container.Fogueira";
}

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


public void setGuiDisplayName(String displayName) {
	this.localizeName = displayName;
}


@Override
public void closeInventory() {

}


@Override
public ItemStack decrStackSize(int i, int j) {
	if(this.slots[i] != null){
		ItemStack itemstack;

		if(this.slots[i].stackSize <= j){
			itemstack = this.slots[i];				
			this.slots[i] = null;				
			return itemstack;
			}else{
				itemstack = this.slots[i].splitStack(j);

				if(this.slots[i].stackSize == 0){
					this.slots[i] = null;
				}

				return itemstack;
			}

		}	

		return null;			
	}


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


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


@Override
public ItemStack getStackInSlotOnClosing(int i) {
	if(this.slots[i] != null){
		ItemStack itemstack = this.slots[i];
		this.slots[i] = null;
		return itemstack;
	}

	return null;
}

public void readFromNBT(NBTTagCompound nbt){
	super.readFromNBT(nbt);
    	NBTTagList nbttaglist = nbt.getTagList("Items", 10);
    	this.slots = new ItemStack[this.getSizeInventory()];

    	for (int i = 0; i < nbttaglist.tagCount(); ++i)
    	{
        		NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.getCompoundTagAt(i);
        		byte b0 = nbttagcompound1.getByte("Slot");

        		if (b0 >= 0 && b0 < this.slots.length)
        		{
            		this.slots[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
        		}
    	}

    	this.power = nbt.getShort("power");
    	this.cookTime = nbt.getShort("CookTime");

    	if (nbt.hasKey("CustomName"))
    	{
        	this.localizeName = nbt.getString("CustomName");
    	}
}

public void writeToNBT(NBTTagCompound nbt){
	super.writeToNBT(nbt);
    	nbt.setShort("power", (short)this.power);
    	nbt.setShort("CookTime", (short)this.cookTime);
    	NBTTagList nbttaglist = new NBTTagList();

    	for (int i = 0; i < this.slots.length; ++i)
    	{	
        		if (this.slots[i] != null)
        		{
            		NBTTagCompound nbttagcompound1 = new NBTTagCompound();
            		nbttagcompound1.setByte("Slot", (byte)i);
            		this.slots[i].writeToNBT(nbttagcompound1);
            		nbttaglist.appendTag(nbttagcompound1);
        		}
    	}

    	nbt.setTag("Items", nbttaglist);

    	if (this.hasCustomInventoryName())
    	{
        		nbt.setString("CustomName", this.localizeName);
    	}
}


public boolean hasPower(){
	return this.power > 0;
}

public boolean isFogueira(){
	return this.cookTime > 0;
}

public void updateEntity(){
	boolean flag = this.hasPower();
	boolean flag1= false;

	if(hasPower() && this.isFogueira()) {
		this.power--;
	}

	if(!worldObj.isRemote) {
		if (this.hasItemPower(this.slots[1]) && this.power < (this.maxPower - this.getItempower(this.slots[1]))) {
			this.power += getItempower(this.slots[1]);

			if(this.slots[1] != null) {
				flag1 = true;

				this.slots[1].stackSize--;

				if(this.slots[1].stackSize == 0) {
					this.slots[1] = this.slots[1].getItem().getContainerItem(this.slots[1]);
				}
			}
		}

		if (hasPower() && canSmelt()) {
			cookTime++;

			if (this.cookTime == this.fogueiraSpeed) {
				this.cookTime = 0;
				this.smeltItem();
				flag1 = true;
			}
		}else{
			cookTime = 0;
		}

		if (flag != this.isFogueira()) {
			flag1 = true;
			Fogueira.updateFogueiraBlockState(this.isFogueira(), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}
		if(this.cookTime > 0){
			flag1 = true;
			Fogueira.updateFogueiraBlockState(this.isFogueira(), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}else{
			flag1 = true;
			Fogueira.updateFogueiraBlockState(this.isFogueira(), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}
	}

	if (flag1) {
		this.markDirty();
	}
    }

private boolean canSmelt(){

	if (slots[0] == null) {
		return false;
	}

	ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);

	if (itemstack == null) {
		return false;
	}

	if (slots[2] == null) {
		return true;
	}

	if (!slots[2].isItemEqual(itemstack)) {
		return false;
	}

	if (slots[2].stackSize < getInventoryStackLimit() && slots[2].stackSize < slots[2].getMaxStackSize()) {
		return true;
	}else{
		return slots[2].stackSize < itemstack.getMaxStackSize();
	}
}

public void smeltItem(){
	if(this.canSmelt()){
		ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);

		if(this.slots[2] == null){
			this.slots[2] = itemstack.copy();
		}else if(this.slots[2].isItemEqual(itemstack)){
			this.slots[2].stackSize += itemstack.stackSize;
		}

		this.slots[0].stackSize--;

		if(this.slots[0].stackSize <= 0){	
			this.slots[0] = null;
		}
	}
}


public static int getItempower(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 == Blocks.sapling) return 100;
				if(block == Blocks.coal_block) return 14400;
				if(block == Blocks.log) return 200;
				if(block == Blocks.log2) return 200;
				if(block == Blocks.planks) return 50;
				if(block == Blocks.wooden_slab)return 150;
				if(block == Blocks.wooden_pressure_plate)return 150;
				if(block == Blocks.wooden_door)return 150;
				if(block == Blocks.wooden_button)return 150;

		}

		if(item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("WOOD")) return 200;
		if(item instanceof ItemSword && ((ItemSword) item).getToolMaterialName().equals("WOOD")) return 200;
		if(item instanceof ItemHoe && ((ItemHoe) item).getToolMaterialName().equals("WOOD")) return 200;
		if(itemstack.getItem() == Items.coal) return 1600;
		if(item == Items.stick) return 100;
		if(item == Items.lava_bucket) return 20000;
		if(item == Items.blaze_rod) return 2400;

		return GameRegistry.getFuelValue(itemstack);
	}
}


public static boolean hasItemPower(ItemStack itemstack){
	return getItempower(itemstack) > 0;
}


@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
	return i == 2 ? false : (i == 1 ? hasItemPower(itemstack) : true);
}


@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
	return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : entityplayer.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 setInventorySlotContents(int i, ItemStack itemstack) {
	this.slots[i] = itemstack;

	if(itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()){
		itemstack.stackSize = this.getInventoryStackLimit();
	}
}


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


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


@Override
public int[] getAccessibleSlotsFromSide(int arg0) {
	return arg0 == 0 ? slots_bottom : (arg0 == 1 ? slots_top :  slots_sides);
}

}

 

Posted

I tried some things but none worked, could you +/- tell  me about what to add or remove?

 

My updateEntity:

 

public void updateEntity(){
	boolean flag = this.hasPower();
	boolean flag1= false;

	if(hasPower() && this.isFogueira()) {
		this.power--;

	}

	if(!worldObj.isRemote) {
		if (this.hasItemPower(this.slots[1]) && this.power < (this.maxPower - this.getItempower(this.slots[1]))) {
			this.power += getItempower(this.slots[1]);

			if(this.slots[1] != null) {
				flag1 = true;

				this.slots[1].stackSize--;

				if(this.slots[1].stackSize == 0) {
					this.slots[1] = this.slots[1].getItem().getContainerItem(this.slots[1]);
				}
			}
		}

		if (hasPower() && canSmelt()) {
			cookTime++;

			if (this.cookTime == this.fogueiraSpeed) {
				this.cookTime = 0;
				this.smeltItem();
				flag1 = true;
			}
		}else{
			cookTime = 0;
		}

		if (flag != this.isFogueira()) {
			flag1 = true;
			Fogueira.updateFogueiraBlockState(this.isFogueira(), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}
		if(this.cookTime > 0){
			flag1 = true;
			Fogueira.updateFogueiraBlockState(this.isFogueira(), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}else{
			flag1 = true;
			Fogueira.updateFogueiraBlockState(this.isFogueira(), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}
	}

	if (flag1) {
		this.markDirty();

	}
    }

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I want to create block with entity, that will have height of 3 or more(configurable) and I tried to change first VoxelShape by increasing collision box on height I want and for changing block height on visual side i tried to configure BlockModelBuilder:  base.element() .from(0, 0, 0) .to(16f, 48f, 16f) .face(Direction.UP).texture("#top").end() .face(Direction.DOWN).texture("#bottom").end() .face(Direction.NORTH).texture("#side").end() .face(Direction.SOUTH).texture("#side").end() .face(Direction.WEST).texture("#side").end() .face(Direction.EAST).texture("#side").end() .end(); but, getting crash with next error: Position y out of range, must be within [-16, 32]. Found: %d [48.0]; Looks like game wont to block height modified by more than 32. Is there any way to fix that problem?
    • As long as the packets you are sending aren't lost, there's nothing wrong with what you're currently doing. Although, this sounds like something that would benefit from you making your own datapack registry instead of trying to arbitrarily sync static maps. Check out `DataPackRegistryEvent.NewRegistry`.
    • Hey all, I've been working a lot with datapacks lately, and I'm wondering what the most efficient way to get said data from server to client is.  I'm currently using packets, but given that a lot of the data I'm storing involves maps along the lines of Map<ResourceLocation, CustomDataType>, it can easily start to get messy if I need to transmit a lot of that data all at once. Recently I started looking into the ReloadableServerResources class, which is where Minecraft stores its built-ins.  I see you can access it via the server from the server's resources.managers, and it seems like this can be done even from the client to appropriately retrieve data from the server, unless I'm misunderstanding.  However, from what I can tell, this only works via built-in methods such as getRecipeManager() or getLootTables(), etc.  These are all SimpleJsonResourceReloadListeners, just like my datapack entries are, so it seems like it could be possible for me to access my datapack entries similarly?  But I don't see anywhere in ReloadableServerResources that stores loaded modded entries, so either I'm looking in the wrong place or it doesn't seem to be a thing. Are packets really the best way of doing this, or am I missing a method that would let me use ReloadableServerResources or something similar?
    • Hi, everyone! I'm new to minecraft modding stuff and want ask you some questions. 1. I checked forge references and saw there com.mojang and net.minecraft (not net.minecraftforge) and as I understand it's original game packages with all minecraft logic inside including renderers and so on, right? 2. Does it mean that forge has a limited set of instruments which doesn't cover all the aspects of the game? If make my question more specific then does forge provide such instruments that allow me totally change minecraft itself, like base mechanics and etc.? Or I have to use "original game packages" to implement such things? 3. I actively learning basic concepts with forge documentation and tutorials. So in my plans make different inventory system like in diabloids. Is that possible with forge? 4. It is last question related to the second one. So how deeply I can change minecraft with forge? I guess all my questions above because of that I haven't globally understanding what forge is and how it works inside and how it works with minecraft. It would be great if you provide some links or topics about it or explain it by yourself but I guess it's to big to be explained in that post at once. Anyway, thank you all for any help!
    • Im trying add to block a hole in center, just a usual block and in center of it on up side, there is should be a hole. I tried to add it via BlockModelBuilder, but its not working. Problem is that it only can change block size outside. I tried it to do with VoxelShape and its working, but its has been on server side and looks like its just changed collision shape, but for client, there is a texture covering this hole. I tried to use: base.renderType("cutout"); and removed some pixels from texture. I thought its should work, but game optimization makes block inside looks transparent. So, only custom model?
  • Topics

×
×
  • Create New...

Important Information

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