Jump to content

Recommended Posts

Posted

Hi, when I try to take an item from inventory repositions it in the same slot not let me move. Where did I go wrong? I think there is a mistake in decrStackSize but can not find it.

 

public class TileEntitySuperGlueFurnace extends TileEntity implements IInventory {

private ItemStack slots[];

public int dualPower;
public int dualCookTime;
public static final int maxPower = 10000;
public static final int mashingSpeed = 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 TileEntitySuperGlueFurnace() {
	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 int[] getAccessibleSlotsFromSide(int i) {
	return i == 0 ? slots_bottom : (i == 1 ? slots_top : slots_side);
}




@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 == Megakron.tackyTyre) return 500;

		return 0;
	}
}

@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;
            }
        }
        else
        {
            return null;
        }
}
}

Posted

You're going to need to post your GUI and Container class as well.

 

By the way,

if (worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) {

That will never be true and you can remove it.

 

You may also want to add the writeToNBT and readFromNBT methods, along with getDescriptionPacket and handleDescriptionPacket (if I spelled those correctly).

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

Grazie, ho rimosso quella stringa, riposto il TileEntity completo e la Gui e Contaire class.

 

TileEntity

 

public class TileEntitySuperGlueFurnace extends TileEntity implements IInventory {

private ItemStack slots[];

public int dualPower;
public int dualCookTime;
public static final int maxPower = 10000;
public static final int mashingSpeed = 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 TileEntitySuperGlueFurnace() {
	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 int[] getAccessibleSlotsFromSide(int i) {
	return i == 0 ? slots_bottom : (i == 1 ? slots_top : slots_side);
}




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

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
		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 == Megakron.tackyTyre) return 500;

		return 0;
	}
}

@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;
            }
        }
        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 String getInventoryName() {
	return "";
}

public boolean canInsertItem(int var1, ItemStack itemstack, int var3) {
	return this.isItemValidForSlot(var1, itemstack);
}

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

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

public int getMasherProgressScaled(int i) {
	return (dualCookTime * i) / this.mashingSpeed;
}

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

private boolean canMash() {

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

	ItemStack itemstack = SuperGlueFurnaceRecipes.getMashingResult(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 mashItem() {
	if (canMash()) {
		ItemStack itemstack = SuperGlueFurnaceRecipes.getMashingResult(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 isMashing() {
	return this.dualCookTime > 0;
}

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

	if(hasPower() && this.isMashing()) {
		this.dualPower--;
	}

	if(!worldObj.isRemote) {
		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() && canMash()) {
			dualCookTime++;

			if (this.dualCookTime == this.mashingSpeed) {
				this.dualCookTime = 0;
				this.mashItem();
				flag1 = true;
			}
		}else{
			dualCookTime = 0;
		}

		if (flag != this.isMashing()) {
			flag1 = true;
			SuperGlueFurnace.updateBlockState(this.isMashing(), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}
	}

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

}

 

Gui

 

public class GuiSuperGlueFurnace extends GuiContainer {

private ResourceLocation texture = new ResourceLocation("megakron:textures/gui/superGlueFurnace.png");
private TileEntitySuperGlueFurnace superGlueFurnace;

public GuiSuperGlueFurnace(InventoryPlayer invPlayer, TileEntitySuperGlueFurnace teSuperGlueFurnace) {
	super(new ContainerSuperGlueFurnace(invPlayer, teSuperGlueFurnace));

	superGlueFurnace = teSuperGlueFurnace;
}

protected void drawGuiContainerForegroundLayer(int i, int j) {

	String name = this.superGlueFurnace.hasCustomInventoryName() ? this.superGlueFurnace.getInventoryName() : I18n.format(this.superGlueFurnace.getInventoryName());

	this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
	this.fontRendererObj.drawString(I18n.format(""), 8, this.ySize - 96 + 5, 4210752);

}

@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {

	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
	drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);

	if (superGlueFurnace.hasPower())
        {
            int i1 = superGlueFurnace.getPowerRemainingScaled(45);
            drawTexturedModalRect(guiLeft + 8, guiTop + 56 - i1, 176, 50 - i1, 2, i1);
        }

        int i1 = superGlueFurnace.getMasherProgressScaled(24);
        drawTexturedModalRect(guiLeft + 77, guiTop + 16, 176, 52, i1 + 1, 54);

}

}

 

ontainer

 

public class ContainerSuperGlueFurnace extends Container {

private TileEntitySuperGlueFurnace superGlue;
private int dualCookTime;
private int dualPower;
private int lastItemBurn;

public ContainerSuperGlueFurnace(InventoryPlayer invPlayer, TileEntitySuperGlueFurnace teSuperGlueFurnace) {

	dualCookTime = 0;
	dualPower = 0;
	lastItemBurn = 0;

	superGlue = teSuperGlueFurnace;

	this.addSlotToContainer(new Slot(teSuperGlueFurnace, 0, 56, 17));
	this.addSlotToContainer(new Slot(teSuperGlueFurnace, 1, 56, 53));
	this.addSlotToContainer(new Slot(teSuperGlueFurnace, 2, 8, 61));
	this.addSlotToContainer(new SlotSuperGlueFurnace(invPlayer.player, teSuperGlueFurnace, 3, 116, 35));

	for(int i = 0; i < 3; i++) {
		for(int j = 0; j < 9; j++) {
			this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
		}
	}

	for(int i = 0; i < 9; i++) {
		this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 142));
	}
}

public void addCraftingToCrafters(ICrafting crafting) {
	super.addCraftingToCrafters(crafting);
	crafting.sendProgressBarUpdate(this, 0, this.superGlue.dualCookTime);
	crafting.sendProgressBarUpdate(this, 1, this.superGlue.dualPower);
}

public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, 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 (TileEntityFurnace.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(par1EntityPlayer, itemstack1);
        }

        return itemstack;
    }	

@Override
public boolean canInteractWith(EntityPlayer player) {
	// TODO Auto-generated method stub
	return superGlue.isUseableByPlayer(player);
}

public void detectAndSendChanges()
    {
        super.detectAndSendChanges();

        for (int i = 0; i < this.crafters.size(); ++i)
        {
            ICrafting icrafting = (ICrafting)this.crafters.get(i);

            if (this.dualCookTime != this.superGlue.dualCookTime)
            {
                icrafting.sendProgressBarUpdate(this, 0, this.superGlue.dualCookTime);
            }

            if (this.dualPower != this.superGlue.dualPower)
            {
                icrafting.sendProgressBarUpdate(this, 1, this.superGlue.dualPower);
            }
        }

        this.dualCookTime = this.superGlue.dualCookTime;
        this.dualPower = this.superGlue.dualPower;
    }

    @SideOnly(Side.CLIENT)
    public void updateProgressBar(int par1, int par2)
    {
        if (par1 == 0)
        {
            this.superGlue.dualCookTime = par2;
        }

        if (par1 == 1)
        {
            this.superGlue.dualPower = par2;
        }
    }
}

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

    • wait, i just did that. why didn't it work? also it's the same. help me!!!!
    • Culprit has been located! It was Tough As Nails + (plus) which was among one of the mods *added* before re-entering, in an attempt to improve compatibility. It, for some reason or another, did not want to work!
    • "You can either try to load it with only the vanilla data pack ("safe mode"), or go back to the title screen and fix it manually." Hello! I encountered this error just now while attempting to re-enter my world for the first time. Notably, no mods were removed before encountering this error and, while being able to find this error elsewhere on the internet, in my scenario it is seemingly caused by a specific mod, of which I cannot isolate. Things I have tried: - Enter "Safe Mode" (fails) - Remove datapacks (no change) - Reverted to old save data (no change) Here is the server log: https://mclo.gs/9vJQEfN I use Modrinth mod loader so please let me know how to share my mod list, and if it is needed.
    • So, i'm hosting (or attempting to host) a port-forwarded modded server for 1.12.2. There's quite a few mods in this pack, but they all run and have no compatibility issues (besides something causing the game to crash if you go fullscreen, a problem ive given up trying to identify or fix). It can run on 6gb of ram or less, and works fine in singleplayer. All of my friends that want to join have the exact same mod/config/game setup as I do (I personally helped them set everything up). Just to be safe, we've all allocated 12 gigabytes of RAM to the installation, and I've also allocated 12GB to the server itself. I am able to join with no issue and it runs fine. However, when they try to join, it gets stuck in the 'logging in' screen before their game becomes unresponsive. When they close it, it gives them the exit code 805306369, which usually means not enough RAM, but this cant be the case. On my screen, in the server, it shows them joining, and then disconnecting, so I dont think its a port-forwarding issue. They can all run it just fine in singleplayer as well. The annoying bit about this particular issue is that it generates no crash log. Does anyone have any suggestions? Thanks! Here is my debug log, and his, starting from the same place. MINE: [132647] [Netty Client IO #5INFO] [FML] Attempting connection with missing mods [ctm, fusion] at SERVER 132653.817 [132653] [Client threadINFO] [minecraftGuiConnecting] Connecting to 0, 25565 132654.682 [132654] [Netty Client IO #9INFO] [STDOUT] [xaero.common.core.transformer.ClassNodeTransformertransform29] Transforming class brz net.minecraft.client.network.NetHandlerPlayClient 132654.684 [132654] [Netty Client IO #9INFO] [STDOUT] [xaero.map.core.transformer.ClassNodeTransformertransform29] Transforming class net.minecraft.client.network.NetHandlerPlayClient 132654.764 [132654] [Netty Client IO #9INFO] [FML] Server protocol version 2 132654.777 [132654] [Netty Client IO #9INFO] [FML] Attempting connection with missing mods [ctm, fusion] at SERVER 132656.193 [132656] [Client threadINFO] [FML] Injecting existing registry data into this client instance 132659.081 [132659] [Client threadINFO] [FML] Applying holder lookups 132659.082 [132659] [Client threadINFO] [FML] Holder lookups applied 132659.092 [132659] [Netty Client IO #9INFO] [FML] [Netty Client IO #9] Client side modded connection established HIS: [13:12:16] [Netty Client IO #0/INFO] [FML]: Attempting connection with missing mods [ctm, fusion] at SERVER 13:12:25.597 [13:12:25] [Client thread/INFO] [minecraft/GuiConnecting]: Connecting to (my IP address and the server port 25565) 13:12:26.805 [13:12:26] [Netty Client IO #1/INFO] [STDOUT]: [xaero.common.core.transformer.ClassNodeTransformer:transform:29]: Transforming class brz net.minecraft.client.network.NetHandlerPlayClient 13:12:26.808 [13:12:26] [Netty Client IO #1/INFO] [STDOUT]: [xaero.map.core.transformer.ClassNodeTransformer:transform:29]: Transforming class net.minecraft.client.network.NetHandlerPlayClient 13:12:26.936 [13:12:26] [Netty Client IO #1/INFO] [FML]: Server protocol version 2 13:12:27.114 [13:12:27] [Netty Client IO #1/INFO] [FML]: Attempting connection with missing mods [ctm, fusion] at SERVER 13:12:27.480 [13:12:27] [Client thread/INFO] [FML]: Injecting existing registry data into this client instance 13:12:30.669 [13:12:30] [Client thread/INFO] [FML]: Applying holder lookups 13:12:30.671 [13:12:30] [Client thread/INFO] [FML]: Holder lookups applied 13:13:04.700 Process crashed with exit code -805306369 P.S - Both mods "CTM" and "FUSION" are present in both our folders so idk what that's about.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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