Jump to content

Recommended Posts

Posted

Edit:

 

So I figured out what line of code directly impacts this problem:

boolean flag = this.isInfusing();

 

If this boolean is set to this.isInfusing(), the furnace texturing works, as in, it lights up when stuff is infusing (smelting).

 

But for some reason if this is set to this.isInfusing() the gui progress bars don't work properly.

 

To have the gui work properly you have to change that line to:

boolean flag = this.hasPower();

 

But now, the textures don't work, as in, it doesn't light up when stuff is infusing (smelting).

 

It's kind of ironic because this is a boolean and two different values make two different things true / false all at the same time. There has to be something in my code that I'm doing wrong that can fix this. It also most likely has to do with the TE Class (updateEntity method specifically).

 

Here's the TE Code:

package com.mjj.colormod.tileentity;

import com.mjj.colormod.blocks.CrypticInfuser;
import com.mjj.colormod.crafting.CrypticInfuserRecipes;
import com.mjj.colormod.handler.BlockHandler;
import com.mjj.colormod.handler.ItemHandler;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;

public class TileEntityCrypticInfuser extends TileEntity implements ISidedInventory{

private ItemStack slots[];

public int dualPower;
public int dualCookTime;
public static final int maxPower = 10000;
public static final int infusingSpeed = 100;

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

private String customName;

public TileEntityCrypticInfuser(){
	slots = new ItemStack[4];
}
@Override
public int getSizeInventory() {
	return slots.length;
}
@Override
public ItemStack getStackInSlot(int i) {
	return slots[i];
}
@Override
public ItemStack getStackInSlotOnClosing(int i) {
	if(slots[i] != null){
		ItemStack itemstack = slots[i];
		slots[i] = null;
		return itemstack;
	}else{
		return null;
	}
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
	slots[i] = itemstack;
	if(itemstack != null && itemstack.stackSize > getInventoryStackLimit()){
		itemstack.stackSize = getInventoryStackLimit();
	}

}


//public static ItemStack getSmeltingResultForItem(ItemStack stack) { return FurnaceRecipes.instance().getSmeltingResult(stack); }

public void setGuiDisplayName(String name){
	this.customName = name;
}

@Override
public String getInventoryName() {
	return "container.crypticinfuser";
}
@Override
public boolean hasCustomInventoryName() {
	return this.customName != null && this.customName.length() > 0;
}

@Override
public int getInventoryStackLimit() {
	return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	if(worldObj.getTileEntity(xCoord, yCoord, zCoord) != this){
		return false;
	}else{
		return player.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64;
	}
}

public void openInventory() {}
public void closeInventory() {}

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

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

private static int getItemPower(ItemStack itemstack){
	if(itemstack == null){
		return 0; 
	}else{
		Item item = itemstack.getItem();

		if(item == ItemHandler.ebonite) return 50;

		return 0;
	}
}

public ItemStack decrStackSize(int i, int j){
	if(slots[i] != null){
		if(slots[i].stackSize <= j){
			ItemStack itemstack = slots[i];
			slots[i] = null;
			return itemstack;
		}
		ItemStack itemstack1 = slots[i].splitStack(j);

		if(slots[i].stackSize == 0){
			slots[i] = null;
		}
		return itemstack1;
	}else{
		return null;
	}
}

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

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

		if(b0 >= 0 && b0 < slots.length){
			slots[b0] = ItemStack.loadItemStackFromNBT(nbt1);
		}
	}
	dualPower = nbt.getShort("PowerTime");
	dualCookTime = nbt.getShort("CookTime");

}
public void writeToNBT(NBTTagCompound nbt){
	super.writeToNBT(nbt);
	nbt.setShort("PowerTime", (short)dualPower);
	nbt.setShort("CookTime", (short)dualCookTime);
	NBTTagList list = new NBTTagList();

	for(int i = 0; i < slots.length; i++){
		if(slots[i] != null){
			NBTTagCompound nbt1 = new NBTTagCompound();
			nbt1.setByte("Slot", (byte)i);
			slots[i].writeToNBT(nbt1);
			list.appendTag(nbt1);
		}
	}
	nbt.setTag("Items", list);
}

@Override
public int[] getAccessibleSlotsFromSide (int i){
	return i == 0 ? slots_bottom : (i == 1 ? slots_top : slots_side);
}
@Override
public boolean canInsertItem(int var1, ItemStack itemstack, int var3) {
	return this.isItemValidForSlot(var1, itemstack);
}
@Override
public boolean canExtractItem(int i, ItemStack itemstack, int j) {
	return j != 0 || i != 1 || itemstack.getItem() == Items.bucket;
}

public int getInfuserProgressScaled(int i){
	return (dualCookTime * i) /this.infusingSpeed;
}

public int getPowerRemainingScaled(int i){
	return (dualPower * i) / maxPower;
}

private boolean canInfuse() {

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

	ItemStack itemstack = CrypticInfuserRecipes.getInfusedResult(slots[0].getItem(), slots[1].getItem());

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

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

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

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

private void infuseItem() {
	if (canInfuse()) {
		ItemStack itemstack = CrypticInfuserRecipes.getInfusedResult(slots[0].getItem(), slots[1].getItem());

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

		for (int i = 0; i < 2; i++) {
			if (slots[i].stackSize <= 0) {
				slots[i] = new ItemStack(slots[i].getItem().setFull3D());
			}else{
				slots[i].stackSize--;
			}

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

public boolean hasPower(){
	return dualPower > 0;
}

public boolean isInfusing(){
	return this.dualCookTime > 0;
}

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

	if(hasPower() && this.isInfusing()) {
		this.dualPower--;
	}
		if (this.hasItemPower(this.slots[2]) && this.dualPower <= (this.maxPower - this.getItemPower(this.slots[2]))) {
			this.dualPower += getItemPower(this.slots[2]);

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

				this.slots[2].stackSize--;

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

		if (hasPower() && canInfuse()) {
			this.dualCookTime++;

			if (this.dualCookTime == this.infusingSpeed) {
				this.dualCookTime = 0;
				this.infuseItem();
				flag1 = true;
			}
		}else{
			dualCookTime = 0;
		}

		if (flag != this.isInfusing()) {
			flag1 = true;
			CrypticInfuser.updateFurnaceBlockState(this.isInfusing(), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}

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

 

Now that I've narrowed down the problem I just need to figure out what is going on.

 

Thanks

~vandy22

Posted

Changing what the flag is affects this line:

 

			if (flag != this.isInfusing()) { //essentially this line is "this.isInfusing() != this.isInfusing()"
			flag1 = true;
			CrypticInfuser.updateFurnaceBlockState(this.isInfusing(), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}

 

Sooo....

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I've been sitting here for 5 minutes trying to figure out how this actually makes the texture turn off and on, and work.

 

When you said this:

if (flag != this.isInfusing()) { //essentially this line is "this.isInfusing() != this.isInfusing()"

 

I knew that it meant that, but I never really thought about it deeply. I'm actually super confused right now.

 

Can you at least explain to me how this would make the textures work for the furnace?

 

If I were to make flag be static (either false or true), if it was false the texture wouldn't work. If it was true the texture would always stay on once starting the smelting.

 

Basically if I set the flag to anything else, rather than this.isInfusing() the gui will work.

 

Anything you can think of?

 

Thanks

Posted

Try recoding that line so it makes sense.  You're checking for "foo is not equal to foo" which will always be false.  When you change it to be bar instead, then you're checking "if bar is not equal to foo" which might be true and might be false.

 

What are the lines inside that statement doing?  When do you want them to happen?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

The lines inside the if statement are doing this:

 

flag1 = true;

When set true, is making sure that when your furnace is not in a loaded chunk, it will save items inside.

 

CrypticInfuser.updateFurnaceBlockState(this.isInfusing(), this.worldObj, this.xCoord, this.yCoord, this.zCoord);

Is changing the texture of the furnace when on/off.

 

Just for reference here is: updateFurnaceBlockState

public static void updateFurnaceBlockState(boolean isInfusing, World world, int xCoord, int yCoord, int zCoord) {
	int i = world.getBlockMetadata(xCoord, yCoord, zCoord);
	TileEntity entity = world.getTileEntity(xCoord, yCoord, zCoord);
	TileEntityCrypticInfuser infuser = new TileEntityCrypticInfuser();
	keepInventory = true;

	if(isInfusing){
		world.setBlock(xCoord, yCoord, zCoord, BlockHandler.blockCrypticInfuserActive);
	}else{
		world.setBlock(xCoord, yCoord, zCoord, BlockHandler.blockCrypticInfuserIdle);
	}

	keepInventory = false;
	world.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, i, 2);

	if(entity != null){
		entity.validate();
		world.setTileEntity(xCoord, yCoord, zCoord, entity);
	}
}

 

Draco, with what you said here:

Try recording that line so it makes sense.  You're checking for "foo is not equal to foo" which will always be false.

 

It doesn't make since to me, that this statement only works correctly when its set to false. When set to false, it can check for true or false. When set to true, it stays true. When set to true, the "active furnace texture" will stay on forever.

 

 

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



×
×
  • Create New...

Important Information

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