I must be blind, but I can't find why my block doesn't get re-rendered with new data from TE...
CommonTE.class
//Base TE class
public class CommonTE extends TileEntity {
@Override
public NBTTagCompound getUpdateTag() {
ModMain.logger.warning("getUpdateTag()");
return writeToNBT(new NBTTagCompound());
}
@Override
public SPacketUpdateTileEntity getUpdatePacket() {
ModMain.logger.warning("getUpdatePacket()");
NBTTagCompound nbtTag = new NBTTagCompound();
this.writeToNBT(nbtTag);
return new SPacketUpdateTileEntity(getPos(), 1, nbtTag);
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
ModMain.logger.warning("onDataPacket()");
this.readFromNBT(packet.getNbtCompound());
}
public void sendUpdates()
{
world.markBlockRangeForRenderUpdate(pos, pos);
world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 3);
world.scheduleBlockUpdate(pos, this.getBlockType(),0,0);
markDirty();
}
}
BlockSliderTE.class
//Actial TE
public class BlockSliderTE extends CommonTE implements ITickable {
public int FACING;
public int STATE;
public int BLOCKSEXTENDED;
public EnumHoleTypes HOLE_TYPE;
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
if(compound.hasKey("facing"))
FACING = compound.getInteger("facing");
if(compound.hasKey("state"))
STATE = compound.getInteger("state");
if(compound.hasKey("blocksextended"))
BLOCKSEXTENDED = compound.getInteger("blocksextended");
if(compound.hasKey("holetype"))
HOLE_TYPE = EnumHoleTypes.values()[compound.getInteger("holetype")];
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
compound.setInteger("facing", FACING);
compound.setInteger("state", STATE);
compound.setInteger("blocksextended", BLOCKSEXTENDED);
compound.setInteger("holetype", HOLE_TYPE.getIndex());
return compound;
}
}
GUI:
public class BlockSliderGUIContainer<TE extends CommonTE, CNT extends CommonContainer> extends GuiContainer {
private TE te;
private List<GuiButton> holeTypeButtons = Lists.<GuiButton>newArrayList();
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
for (int i = 0; i < holeTypeButtons.size(); i++)
if (holeTypeButtons.get(i).mousePressed(mc, mouseX, mouseY)) {
int rem = i % 3;
if(rem == 0) ((BlockSliderTE)te).HOLE_TYPE = EnumHoleTypes.ROUND;
if(rem == 1) ((BlockSliderTE)te).HOLE_TYPE = EnumHoleTypes.SQUARE;
if(rem == 2) ((BlockSliderTE)te).HOLE_TYPE = EnumHoleTypes.CROSS;
}
SliderGUISync.send((BlockSliderTE)te);
}
}
Network stuff:
public class SliderGUISync implements IMessageHandler<SliderGUISync.Packet, IMessage> {
@Override
public IMessage onMessage(SliderGUISync.Packet message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().player;
player.getServerWorld().addScheduledTask(() -> {
World world = player.world;
BlockSliderTE te = (BlockSliderTE) world.getTileEntity(message.tePos);
te.HOLE_TYPE = message.holeType;
te.sendUpdates();
ModMain.logger.warning("TE synced. Data follows: X: "+message.tePos.getX() + ", Y: "+message.tePos.getY()+", Z: "+message.tePos.getZ()+", HOLE_TYPE:"+message.holeType);
});
return null;
}
public static void send(BlockSliderTE te)
{
ModMain.network.sendToServer(new Packet(te));
}
public static class Packet implements IMessage {
public BlockPos tePos;
public EnumHoleTypes holeType;
public Packet(BlockSliderTE te) {
tePos = te.getPos();
holeType = te.HOLE_TYPE;
}
public Packet(){}
@Override
public void fromBytes(ByteBuf buf) {
tePos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
holeType = EnumHoleTypes.values()[buf.readInt()];
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(tePos.getX());
buf.writeInt(tePos.getY());
buf.writeInt(tePos.getZ());
buf.writeInt(holeType.getIndex());
}
}
}
Well, it doesn't sync. When I click button to change EnumHoleType, message successfully sending to server, server receives it (logger.warning is perfectly fine with data), but block just don't seem to care. It updates only when forcing blockupdate by placing block next to it or something, or GUI is reopened. Data in TE is fine.
Help!