Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.2] Syncing TE form GUI
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 1
ZigTheHedge

[1.12.2] Syncing TE form GUI

By ZigTheHedge, February 20 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

ZigTheHedge    2

ZigTheHedge

ZigTheHedge    2

  • Tree Puncher
  • ZigTheHedge
  • Members
  • 2
  • 42 posts
Posted February 20

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! :(

 

  • Quote

Share this post


Link to post
Share on other sites

RoyalReject    0

RoyalReject

RoyalReject    0

  • Tree Puncher
  • RoyalReject
  • Members
  • 0
  • 33 posts
Posted February 20 (edited)
@Override
    public SPacketUpdateTileEntity getUpdatePacket() {
        ModMain.logger.warning("getUpdatePacket()");
        NBTTagCompound nbtTag = new NBTTagCompound();
        this.writeToNBT(nbtTag);
        return new SPacketUpdateTileEntity(getPos(), 1, nbtTag);
    }

Try setting return statement to return new SPacketUpdateTileEntity(this.pos, 3, this.getUpdateTag());

or just change 1 to 3

Edited February 20 by RoyalReject
fixes
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45590 posts
Posted February 20
4 minutes ago, RoyalReject said:

Try setting return statement to return new SPacketUpdateTileEntity(this.pos, 3, this.getUpdateTag());

or just change 1 to 3

This int is completely irrelevant for modded tile entities.

 

@ZigTheHedge:

Your sendUpdates method is stupid, don't blindly call random methods without knowing what they do.

  • Call World#notifyBlockUpdate on the server to send the update packet to the client.
  • Call World#notifyBlockUpdate on the client to re-render the block. If your update packet needs the block to be re-rendered you need to call this from onDataPacket.
  • You must call TileEntity#markDirty when any data that's serialized to NBT (writeToNbt) has changed. This is not related to networking.
  • Thanks 2
  • Quote

Share this post


Link to post
Share on other sites

ZigTheHedge    2

ZigTheHedge

ZigTheHedge    2

  • Tree Puncher
  • ZigTheHedge
  • Members
  • 2
  • 42 posts
Posted February 21

@diesieben07, you're savior! Everything is working properly now!

 

P.S: sendUpdates was the "last resort", when I tried everything else :) It's copied from somewhere in these forums :)

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • matt1999rd
      [1.14-newer] how to keep value when closing minecraft

      By matt1999rd · Posted 1 minute ago

      hello, In my mod I want to keep the value of a variable when closing minecraft and I don't know how to do it . It is three integer from a BlockPos...  
    • matt1999rd
      [1.14-newer] deprecated method onBlockActivated

      By matt1999rd · Posted 3 minutes ago

      okay so how can I replace it if I cannot use blockState ? I saw on other post that people in 1.14 are using onBlockActivated too and nothing is suggest to replace it in the Block class unfortunately...
    • DragonITA
      [1.14.4] Why minecraft with mod dont want start?

      By DragonITA · Posted 4 minutes ago

      i try with delete the entier Config Folder but it still dont work and the Folder come back.
    • plugsmustard
      on/off button for custom furnace

      By plugsmustard · Posted 5 minutes ago

      what exactly is wrong with them. i was told to return a new packet?
    • JetCobblestone
      [1.14] moving item assignment to a separate function

      By JetCobblestone · Posted 7 minutes ago

      Hey everyone,   I'm trying to move my item assignment into a new class. I've stuck in into the same package as my main and called it ItemsLoader.   package jetcobblestone.firstmod; import jetcobblestone.firstmod.lists.itemList; import net.minecraft.item.Foods; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.util.ResourceLocation; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; public class ItemsLoader { public static final String modid = "first_mod"; public static void Items() { @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public static class RegistryEvents { @SubscribeEvent public static void registerItems(final RegistryEvent.Register<Item> event) { event.getRegistry().registerAll ( itemList.hair_fibre = new Item(new Item.Properties().food(Foods.COOKIE).group(ItemGroup.FOOD).maxStackSize(1)).setRegistryName(location("hair_fibre")) ); } } private static ResourceLocation location(String name) { return new ResourceLocation(modid, name); } } }   This is the new class, however I'm running into an issue with the new Items function. It's giving me an error saying that it's expecting a volatile at the void token. Why is it trying to force me to do this? I don't want to send this to main memory? If I do replace void with volatile, it tells me there's a syntax error on the 'void' token, despite the fact there is no void. Any help would be much appreciated, thank you!
  • Topics

    • matt1999rd
      0
      [1.14-newer] how to keep value when closing minecraft

      By matt1999rd
      Started 1 minute ago

    • matt1999rd
      9
      [1.14-newer] deprecated method onBlockActivated

      By matt1999rd
      Started November 1

    • DragonITA
      1
      [1.14.4] Why minecraft with mod dont want start?

      By DragonITA
      Started 1 hour ago

    • plugsmustard
      43
      on/off button for custom furnace

      By plugsmustard
      Started Wednesday at 09:11 AM

    • JetCobblestone
      0
      [1.14] moving item assignment to a separate function

      By JetCobblestone
      Started 8 minutes ago

  • Who's Online (See full list)

    • plugsmustard
    • matt1999rd
    • Lea9ue
    • LexManos
    • FaxeeK
    • Vorquel
    • DragonITA
    • xVoidZx
    • Silverpool64
    • Hendoor64
    • JetCobblestone
    • Atila1091
    • maycool12
    • vaartis
    • Draco18s
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.2] Syncing TE form GUI
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community