will0376
Токсичная личность
- 2,079
- 55
- 585
здрасте. попытался добавить свой тег(не один...) в nbt тайла блока, вроде получилось.... но теперь всё блоки имеют значение из этого блока...
Что не так делаю?
При этом мне надо на каждый блок получать своё значение переменной...
Java:
public class TestContainerTileEntity extends TileEntity {
public static final int SIZE = 56;
public static ArrayList<String> players = new ArrayList<>();
public static TestContainerTileEntity Instance;
public static boolean infinity;
private ItemStackHandler itemStackHandler = new ItemStackHandler(SIZE)
{
@Override
protected void onContentsChanged(int slot) {
TestContainerTileEntity.this.markDirty();
}
};
@Override
public void readFromNBT(NBTTagCompound compound) {
Instance = this;
super.readFromNBT(compound);
System.out.println(compound);
if (compound.hasKey("items"))
itemStackHandler.deserializeNBT((NBTTagCompound) compound.getTag("items"));
if(compound.hasKey("players"))
players = deserializePlayersNBT(compound);
if(compound.hasKey("Infinity"))
infinity = compound.getBoolean("Infinity");
}
public ArrayList deserializePlayersNBT(NBTTagCompound nbt)
{
ArrayList<String> tmp = new ArrayList<>();
NBTTagList tagList = nbt.getTagList("Players", 8);
for(int i = 0;i < tagList.tagCount();i++){
NBTTagCompound itemTags = tagList.getCompoundTagAt(i);
String player = itemTags.getString("Player");
tmp.add(player);
}
return tmp;
}
private NBTTagCompound playersToNbt(){
NBTTagList nbtTagList = new NBTTagList();
for (int i = 0; i < players.size(); i++)
{
NBTTagCompound player = new NBTTagCompound();
player.setString("Player", players.get(i));
//players.get(i).writeToNBT(itemTag);
nbtTagList.appendTag(player);
}
NBTTagCompound nbt = new NBTTagCompound();
nbt.setTag("Players", nbtTagList);
nbt.setInteger("Size", players.size());
System.out.println(nbt);
return nbt;
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
compound.setTag("items", itemStackHandler.serializeNBT());
compound.setTag("players", playersToNbt());
compound.setBoolean("Infinity",infinity);
return compound;
}
public boolean canInteractWith(EntityPlayer playerIn) {
// If we are too far away from this tile entity you cannot use it
return !isInvalid() && playerIn.getDistanceSq(pos.add(0.5D, 0.5D, 0.5D)) <= 64D;
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
return true;
}
return super.hasCapability(capability, facing);
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(itemStackHandler);
}
return super.getCapability(capability, facing);
}
}
При этом мне надо на каждый блок получать своё значение переменной...