Jump to content

Recommended Posts

Posted

Alright, so I have a chest. And the NBT (I believe) is wrong. I put an item in, close the world, go back in, and nothing is in there.

 

My TileEntity

	@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
	super.writeToNBT(compound);
	compound.setTag("inputSlot", inputSlot.serializeNBT());

	return compound;
}


@Override
public void readFromNBT(NBTTagCompound compound) {
	inputSlot.deserializeNBT(compound.getCompoundTag("inputSlot"));
}

 

I am not sure why this doesn't work, but that's why there is a forums, right?

Thanks in advance!

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Posted

Your

readFromNBT

needs to call super.

 

I added super, now making it

	@Override
public void readFromNBT(NBTTagCompound compound) {
	inputSlot.deserializeNBT(compound.getCompoundTag("inputSlot"));
	super.readFromNBT(compound);
}

 

but it still does not work.

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Posted

If you look here https://github.com/EscapeMC/Things-Mod-1.10.2/tree/master/src/main/java/com/github/escapemc/thingsmod

 

This is my github. Do note, I cannot edit anything on my github right now (not on the correct account on my computer and I cannot access that account until later today)

 

Just look to my TileEntityTestChest https://github.com/EscapeMC/Things-Mod-1.10.2/blob/master/src/main/java/com/github/escapemc/thingsmod/tileentity/TileEntityTestChest.java

 

It has the same code (minus a few things) as my BlackHole one.

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Posted

This is a joke, right? You cannot be serious...

 

No, it is not a joke. I just did that because in case I wanted to do anything else with it.

Also I like it more.

 

https://sendvid.com/za5vqhbv

 

A few problems, 1) with the chest (thw first block opened) as you might have seen, when I shift-right clicked a block in there it became 2. Any ideas on this?

 

2) I have the same NBT with both TEs for BlackHole (the huge gui) and the chest (smaller one). You saw the chest worked. the Black Hole didn't.  I then copy-pasta my TE for the chest into my black hole TE, and change the 1 thing to fix the names, but the NBT doesn't work. (I did this off the video)

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Posted

 

package com.github.escapemc.thingsmod.tileentity;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;

public class TileEntityBlackHole extends TileEntity {


private String customName;
protected ItemStackHandler inputSlot;

public TileEntityBlackHole() {
	inputSlot = new ItemStackHandler(171);
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
	super.writeToNBT(compound);
	compound.setTag("inputSlot", inputSlot.serializeNBT());

	return compound;
}


@Override
public void readFromNBT(NBTTagCompound compound) {
	inputSlot.deserializeNBT(compound.getCompoundTag("inputSlot"));
	super.readFromNBT(compound);
}

@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
	if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
		this.markDirty();
		if(worldObj != null && worldObj.getBlockState(pos).getBlock() != getBlockType()) {
			return (T) inputSlot;
		}
		if(facing == null) {
			return (T) inputSlot;
		}
		if(facing == EnumFacing.UP) {
			return (T) inputSlot;
		}
		if(facing == EnumFacing.DOWN) {
			return (T) inputSlot;
		}
		if(facing == EnumFacing.NORTH) {
			return (T) inputSlot;
		}
		if(facing == EnumFacing.EAST) {
			return (T) inputSlot;
		}
		if(facing == EnumFacing.WEST) {
			return (T) inputSlot;
		}
		if(facing == EnumFacing.SOUTH) {
			return (T) inputSlot;
		}
	}
	return super.getCapability(capability, facing);
}	

@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
	return this.getCapability(capability, facing) != null;
}

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



}

package com.github.escapemc.thingsmod.hardlib.api.internal;

import javax.annotation.Nullable;

import com.github.escapemc.thingsmod.tileentity.TileEntityTestChest;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

public class CommonContainerBlackHole extends Container {


    private final int numRows;
    TileEntityTestChest tileEntity;

    public CommonContainerBlackHole(IInventory playerInventory, IInventory chestInventory, EntityPlayer player)
    {
        this.numRows = chestInventory.getSizeInventory() / 9;
        chestInventory.openInventory(player);
        int i = (this.numRows - 5) * 18;

        
	//Player Inventory
	for (int k = 0; k < 3; ++k) {
		for (int j = 0; j < 9; ++j) {
		this.addSlotToContainer(new Slot(playerInventory, j + k * 9 + 9, 129 + j * 18, 185 + k * 18));
		}

        //Player Hotbar
        for (int i1 = 0; i1 < 9; ++i1)
        {
            this.addSlotToContainer(new Slot(playerInventory, i1, 129 + i1 * 18, 261 + i));
        }
    }
}
@Override
    @Nullable
    public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
    {
        ItemStack itemstack = null;
        Slot slot = (Slot)this.inventorySlots.get(index);

        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();

            if (index < this.numRows * 9)
            {
                if (!this.mergeItemStack(itemstack1, this.numRows * 9, this.inventorySlots.size(), true))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 0, this.numRows * 9, false))
            {
                return null;
            }

            if (itemstack1.stackSize == 0)
            {
                slot.putStack((ItemStack)null);
            }
            else
            {
                slot.onSlotChanged();
            }
        }

        return itemstack;
    }

@Override
protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection){
	boolean flag = false;
	int i = startIndex;
	if (reverseDirection) i = endIndex - 1;

	if (stack.isStackable()){
		while (stack.stackSize > 0 && (!reverseDirection && i < endIndex || reverseDirection && i >= startIndex)){
			Slot slot = (Slot)this.inventorySlots.get(i);
			ItemStack itemstack = slot.getStack();
			int maxLimit = Math.min(stack.getMaxStackSize(), slot.getSlotStackLimit());

			if (itemstack != null && areItemStacksEqual(stack, itemstack)){
				int j = itemstack.stackSize + stack.stackSize;
				if (j <= maxLimit){
					stack.stackSize = 0;
					itemstack.stackSize = j;
					slot.onSlotChanged();
					flag = true;

				}else if (itemstack.stackSize < maxLimit){
					stack.stackSize -= maxLimit - itemstack.stackSize;
					itemstack.stackSize = maxLimit;
					slot.onSlotChanged();
					flag = true;
				}
			}
			if (reverseDirection){ 
				--i;
			}else ++i;
		}
	}
	if (stack.stackSize > 0){
		if (reverseDirection){
			i = endIndex - 1;
		}else i = startIndex;

		while (!reverseDirection && i < endIndex || reverseDirection && i >= startIndex){
			Slot slot1 = (Slot)this.inventorySlots.get(i);
			ItemStack itemstack1 = slot1.getStack();

			if (itemstack1 == null && slot1.isItemValid(stack)){ // Forge: Make sure to respect isItemValid in the slot.
				if(stack.stackSize <= slot1.getSlotStackLimit()){
					slot1.putStack(stack.copy());
					slot1.onSlotChanged();
					stack.stackSize = 0;
					flag = true;
					break;
				}else{
					itemstack1 = stack.copy();
					stack.stackSize -= slot1.getSlotStackLimit();
					itemstack1.stackSize = slot1.getSlotStackLimit();
					slot1.putStack(itemstack1);
					slot1.onSlotChanged();
					flag = true;
				}					
			}
			if (reverseDirection){
				--i;
			}else ++i;
		}
	}
	return flag;
}

private static boolean areItemStacksEqual(ItemStack stackA, ItemStack stackB)
{
	return stackB.getItem() == stackA.getItem() && (!stackA.getHasSubtypes() || stackA.getMetadata() == stackB.getMetadata()) && ItemStack.areItemStackTagsEqual(stackA, stackB);
}

@Override
public boolean canInteractWith(EntityPlayer playerIn) {
	return true;
}
}

package com.github.escapemc.thingsmod.container;

import com.github.escapemc.thingsmod.hardlib.api.internal.CommonContainerBlackHole;
import com.github.escapemc.thingsmod.hardlib.api.inventory.SlotItem;
import com.github.escapemc.thingsmod.tileentity.TileEntityBlackHole;

import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;

public class ContainerBlackHole extends CommonContainerBlackHole {
TileEntityBlackHole tileEntity;
    private int numRows = 9;


public ContainerBlackHole(InventoryPlayer inventory, TileEntityBlackHole te) {
	super(inventory, inventory, null);
	tileEntity = te;
	IItemHandler inven = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

        for (int j = 0; j < this.numRows; ++j)
        {
            for (int k = 0; k < 18; ++k)
            {
                this.addSlotToContainer(new SlotItem(inven, k + j * 18, 8 + k * 18, 12 + j * 18));
            }
        }


	}
}

 

 

 

This is my TE, Container, and CommonContainer for my black hole. I cannot post my black hole stuff to my git hub right now. In 2 hours I can.

 

EDIT: Also, while looking through, I noticed my CommonContainerBlackHole was using TETestChest. I just changed it.

 

A few problems, 1) with the chest (thw first block opened) as you might have seen, when I shift-right clicked a block in there it became 2. Any ideas on this?
This has something to do with
transferStackInSlot

and

mergeItemStack

in

CommonContainer9x5

. Why are you overriding both? Only

transferStackInSlot

should be needed. But in all honesty I hate shift-clicking with a passion... Implementing it that is.

 

So with this are you saying I only need to keep transferStackInSlot, and I can get rid of mergeItemStack?

 

EDIT: I noticed, the only time it doubles the item, is when the item is/was in the hotbar

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Posted

Your parameters and fields are all over the place...

  • Why does
    CommonContainerBlackHole

    have a field called

    tileEntity

    of type

    TileEntityTestChest

    that is never used?

  • Why does the
    CommonContainerBlackHole

    constructor take two

    IInventory

    instances as input? Why pass inventory and player separately? Just pass in the player if you are just going to add their inventory anyways. Oh right, you don't even pass the player, you pass

    null

    . Why? And then you pass in the player's inventory for the

    chestInventory

    parameter as well. This is all completely nonsensical.

 

It's hard to see what's wrong from just the code, so I will wait until you can get this code up on a working Git repo so I can test it in a development environment.

 

I will get back to you (on this thread) when I am ready and my git repo loaded and everything

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Posted

Well I solved my own problem!

 

#When you forget to register the tile entity in the main class so that is why it didn't work

 

GitHub is also updated too.

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

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.