Jump to content

[1.11.2] NBT is not read correctly


Minebot1708
 Share

Recommended Posts

There is a switch in the GUI of the block. When switching, a packet is sent to the server with the switch values and the block position. When the server receives the packet, it sets the value in TileEntity by position and synchronizes it with the world.notifyBlockUpdate. NBT is normally written and read from the server and client, I checked using system.out.println in update. But if I re-enter the world, then NBT is considered a different meaning. While trying to understand why this is, I noticed that in the game pause sometimes writeToNBT from TileEntity is not called. When writeToNBT is called when paused, when you re-enter the world, NBT is read out normally. (If something is not clear, then ask me, because my English is at the level of a google translator)
 

GUI (The method of clicking on the switch is onMouseClicked in framePrivate):

Spoiler

public class FcGui extends GuiContainer{
    private ArrayList<Button> buttons = new ArrayList<Button>();
    private Slider slider;
    private FrameOfModules frame;
    private PrivateFrame framePrivate;
    private EnergyProgressBar bar;
    private FieldIndicator indicator;
    private IInventory playerInv;
    private TileEntityFC te;

    public FcGui(IInventory playerInv, final TileEntityFC te) {
        super(new FcContainer(playerInv, te));

        this.playerInv = playerInv;
        this.te = te;

        this.xSize = 196;
        this.ySize = 200;

        frame = new FrameOfModules(3, Module.getLocalizedNames(te.getAcceptedModules()));
        framePrivate = new PrivateFrame() {
            @Override
            public void onMouseClicked(boolean isPublic) {
                if (isPublic)
                    te.setPublic();
                else
                    te.setPrivate();
                NetworkHandler.sendToServer(new PacketPublicPrivate(te.getPos(), isPublic));
                ((FcContainer)inventorySlots).changeSlots(isPublic);
            }
        };
        bar = new EnergyProgressBar(true);
        slider = new Slider(7, 83, 20) {
            @Override
            public void onSliderPosChanged(int sliderPos) {
                if (te.getFrequency() != sliderPos) {
                    NetworkHandler.sendToServer(new PacketFrequency(te.getPos(), sliderPos));
                    te.setFrequency(sliderPos);
                }
            }
        };

        ResourceLocation b_r = new ResourceLocation("meem:textures/gui/buttons/left_right/button_right.png");
        ResourceLocation b_r_h = new ResourceLocation("meem:textures/gui/buttons/left_right/button_right_hover.png");
        ResourceLocation b_r_c = new ResourceLocation("meem:textures/gui/buttons/left_right/button_right_click.png");
        ResourceLocation b_l = new ResourceLocation("meem:textures/gui/buttons/left_right/button_left.png");
        ResourceLocation b_l_h = new ResourceLocation("meem:textures/gui/buttons/left_right/button_left_hover.png");
        ResourceLocation b_l_c = new ResourceLocation("meem:textures/gui/buttons/left_right/button_left_click.png");

        buttons.add(new Button(9, 16, 66, 35, b_r, b_r_h, b_r_c) {
            @Override
            public void onButtonClicked() {
                int radius = te.getRadius() + (isShiftKeyDown() ? 10 : 1);
                if (radius > te.getMaxRadius())
                    te.setRadius(te.getMaxRadius());
                else
                    te.setRadius(radius);
                NetworkHandler.sendToServer(new PacketFieldCreator(te.getPos(), te.getVoltage(), te.getRadius()));
            }
        });
        buttons.add(new Button(9, 16, 17, 35, b_l, b_l_h, b_l_c) {
            @Override
            public void onButtonClicked() {
                int radius = te.getRadius() - (isShiftKeyDown() ? 10 : 1);
                if (radius < 1)
                    te.setRadius(1);
                else
                    te.setRadius(radius);
                NetworkHandler.sendToServer(new PacketFieldCreator(te.getPos(), te.getVoltage(), te.getRadius()));
            }
        });
        indicator = new FieldIndicator(7, 6);
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
        GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
        this.mc.getTextureManager().bindTexture(new ResourceLocation("meem:textures/gui/fcgui.png"));
        this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize-20, this.ySize);
        frame.draw(mc, 177 + guiLeft, guiTop, mouseX, mouseY);
        framePrivate.drawFrame(mc, guiLeft - 26, guiTop, te.isPublic());
    }

    @Override
    protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
        super.mouseClicked(mouseX, mouseY, mouseButton);
        for (int i = 0; i < buttons.size(); i++)
            buttons.get(i).mouseDown(mouseX - getGuiLeft(), mouseY - getGuiTop());
        slider.mouseDown(mouseX - getGuiLeft(), mouseY - getGuiTop());
        framePrivate.mouseDown();
    }

    @Override
    protected void mouseReleased(int mouseX, int mouseY, int state) {
        super.mouseReleased(mouseX, mouseY, state);
        for (int i = 0; i < buttons.size(); i++)
            buttons.get(i).mouseUp(mouseX - getGuiLeft(), mouseY - getGuiTop());
    }

    @Override
    protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
        super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
        slider.mousePressed(mouseX - getGuiLeft(), mouseY - getGuiTop());
    }

    @Override
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
        this.fontRendererObj.drawString("Field Converter", 88 - this.fontRendererObj.getStringWidth("Field Converter") / 2, 6, 4210752);            //#404040

        fontRendererObj.drawString("Information:", 85, 20, 4210752);
        String[] info = te.getModuleInfo();
        if (info != null)
            for (int i = 0; i < info.length; i++)
                fontRendererObj.drawString(info[i], 85, 30 + i * 10, 4210752);
        else {
            fontRendererObj.drawString("No functional", 85, 30, 4210752);
            fontRendererObj.drawString("module", 85, 40, 4210752);
        }

        fontRendererObj.drawString("Radius", 30, 27, 4210752);
        fontRendererObj.drawString(te.getRadius()+"", 46 - fontRendererObj.getStringWidth(te.getRadius()+"")/2, 40,4210752);

        fontRendererObj.drawString("Frequency", 88 - this.fontRendererObj.getStringWidth("Frequency") / 2, 65, 4210752);
        fontRendererObj.drawString((float)te.getFrequency()/2f+" Hz", 120, 80, 4210752);

        for (int i = 0; i < buttons.size(); i++)
            buttons.get(i).draw(mc, mouseX - getGuiLeft(), mouseY - getGuiTop());
        slider.draw(mc, te.getFrequency());
        indicator.draw(mc, te.hasField());
        bar.draw(mc, 7, 99, mouseX - guiLeft, mouseY - guiTop, te.getVoltage(), te.getMaxVoltage());
        framePrivate.draw(mc, -26, 0, mouseX - guiLeft, mouseY - guiTop, te.isPublic());
    }

    @Override
    public boolean doesGuiPauseGame() {
        return false;
    }
}

 

 

Packet Class:

Spoiler

public class PacketPublicPrivate extends AbstractPacket<PacketPublicPrivate> {
    protected BlockPos pos;
    protected boolean isPublic;

    public PacketPublicPrivate(){}

    public PacketPublicPrivate(BlockPos pos, boolean isPublic){
        this.pos = pos;
        this.isPublic = isPublic;
    }

    @Override
    public void toBytes(final ByteBuf buf) {
        buf.writeBoolean(isPublic);
        buf.writeInt(pos.getX());
        buf.writeInt(pos.getY());
        buf.writeInt(pos.getZ());
    }

    @Override
    public void fromBytes(final ByteBuf buf) {
        isPublic = buf.readBoolean();
        int m, n, b;
        m = buf.readInt();
        n = buf.readInt();
        b = buf.readInt();
        pos = new BlockPos(m, n, b);
    }

    @Override
    public void handleClientSide(PacketPublicPrivate message, EntityPlayer player) {
    }

    @Override
    public void handleServerSide(PacketPublicPrivate message, EntityPlayer player) {
        IPublicPrivateHandler te = (IPublicPrivateHandler) player.world.getTileEntity(message.pos);
        if (message.isPublic)
            te.setPublic();
        else
            te.setPrivate();
    }
}

public abstract class AbstractPacket<REQ extends IMessage> implements IMessage, IMessageHandler<REQ, REQ>
{
    @Override
    public REQ onMessage(final REQ message, final MessageContext ctx)
    {
        if(ctx.side == Side.SERVER)
        {
            System.out.println("PacketToServer");
            handleServerSide(message, ctx.getServerHandler().playerEntity);
        }
        else
        {
            System.out.println("PacketToClient");
            handleClientSide(message, FMLClientHandler.instance().getClientPlayerEntity());
        }
        return null;
    }

    public abstract void handleClientSide(final REQ message, final EntityPlayer player);
    public abstract void handleServerSide(final REQ message, final EntityPlayer player);
}

 

 

TileEntity:

Spoiler

public class TileEntityFC extends FieldReceiverEnergyStandart implements IInventory, IModuleProvider, IFieldCreator, IPublicPrivateHandler, ITickable {

    protected boolean active;
    protected ItemStack[] inventory;
    protected String customName;
    protected int radius;
    protected int maxRadius;
    protected int lossReduce;
    protected int[] ids;

    public TileEntityFC(){
        this.maxVoltage = 150;
        this.maxRadius = 10;
        radius = 1;
        this.frequency = 0;
        inventory = new ItemStack[]{ItemStack.EMPTY, ItemStack.EMPTY, ItemStack.EMPTY, ItemStack.EMPTY, ItemStack.EMPTY, ItemStack.EMPTY,ItemStack.EMPTY, ItemStack.EMPTY};
        active = true;
    }
    @Override
    public void update(){
        System.out.println("isPublic: " + isPublic());
    }

    @Override
    public boolean isWork() {
        return active && hasFuncModule();
    }

    @Override
    public void onField(){
        ItemStack stack = getFuncModule();
        if (!stack.isEmpty())
            ((ModuleFunctional)stack.getItem()).firstUpdate(new FuncArgs(world, getPos(), radius, voltage, lossReduce, isPublic(), ids));
        createField();
    }

    @Override
    public int getSizeInventory() {
        return 8;
    }

    @Override
    public boolean isEmpty(){
        boolean result = true;
        for (int i = 0; i < inventory.length; i++)
            if (inventory[i] != ItemStack.EMPTY) {
                result = false;
                break;
            }
        return result;
    }

    @Override
    public ItemStack getStackInSlot(int index) {
        if (index < 0 || index >= this.getSizeInventory())
            return ItemStack.EMPTY;
        return this.inventory[index];
    }

    @Override
    public ItemStack decrStackSize(int index, int count) {
        if (!this.getStackInSlot(index).isEmpty()) {
            ItemStack itemstack;

            if (this.getStackInSlot(index).getCount() <= count) {
                itemstack = this.getStackInSlot(index);
                this.setInventorySlotContents(index, ItemStack.EMPTY);
                this.markDirty();
                return itemstack;
            } else {
                itemstack = this.getStackInSlot(index).splitStack(count);

                if (this.getStackInSlot(index).getCount() <= 0) {
                    this.setInventorySlotContents(index, ItemStack.EMPTY);
                } else {
                    //Just to show that changes happened
                    this.setInventorySlotContents(index, this.getStackInSlot(index));
                }

                this.markDirty();
                return itemstack;
            }
        } else {
            return ItemStack.EMPTY;
        }
    }

    @Override
    public ItemStack removeStackFromSlot(int index) {
        ItemStack result = inventory[index].copy();
        if (inventory[index].getItem() instanceof ModuleFunctional)
            ((ModuleFunctional)inventory[index].getItem()).removeModule(new FuncArgs(world, getPos(), radius, voltage, lossReduce, isPublic(), ids));
        inventory[index] = ItemStack.EMPTY;
        this.markDirty();
        return result;
    }

    @Override
    public void setInventorySlotContents(int index, ItemStack stack) {
        if (index < 0 || index >= this.getSizeInventory())
            return;

        if (!stack.isEmpty() && stack.getCount() > this.getInventoryStackLimit())
            stack.setCount(this.getInventoryStackLimit());

        if (!isEmpty() && stack.getCount() == 0)
            stack = ItemStack.EMPTY;

        this.inventory[index] = stack;
        this.markDirty();
        if (stack.getItem() instanceof ModuleFunctional)
            ((ModuleFunctional)stack.getItem()).putModule(new FuncArgs(world, getPos(), radius, voltage, lossReduce, isPublic(), ids));
    }

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

    @Override
    public boolean isUsableByPlayer(EntityPlayer player) {
        return this.world.getTileEntity(this.getPos()) == this && player.getDistanceSq(this.pos.add(0.5, 0.5, 0.5)) <= 64;
    }

    @Override
    public void openInventory(EntityPlayer player) {
        markUpdate();
        ItemStack stack = getFuncModule();
        if (!stack.isEmpty())
            ((ModuleFunctional)stack.getItem()).openInventory(new FuncArgs(world, getPos(), radius, voltage, lossReduce, isPublic(), ids));
    }

    @Override
    public void closeInventory(EntityPlayer player) {
        markUpdate();
        ItemStack stack = getFuncModule();
        if (!stack.isEmpty())
            ((ModuleFunctional)stack.getItem()).closeInventory(new FuncArgs(world, getPos(), radius, voltage, lossReduce, isPublic(), ids));
    }

    @Override
    public boolean isItemValidForSlot(int index, ItemStack stack) {
        return isAccepted(stack.getItem()) && (stack.getItem() instanceof ModuleFunctional ? !hasFuncModule() : true);
    }

    @Override
    public int getField(int id) {
        return 0;
    }

    @Override
    public void setField(int id, int value) {

    }

    @Override
    public int getFieldCount() {
        return 0;
    }

    @Override
    public void clear() {
        for (int i = 0; i < inventory.length; i++)
            inventory[i] = ItemStack.EMPTY;
        this.markDirty();
    }

    @Override
    public String getName() {
        return this.hasCustomName() ? this.customName : "container.tile_entity_FC";
    }

    @Override
    public boolean hasCustomName() {
        return this.customName != null && !this.customName.equals("");
    }

    public String getCustomName() {
        return this.customName;
    }

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

    @Override
    public NBTTagCompound getUpdateTag() {
        return writeToNBT(new NBTTagCompound());
    }

    @Override
    @Nullable
    public SPacketUpdateTileEntity getUpdatePacket() {
        return new SPacketUpdateTileEntity(getPos(), 4, getUpdateTag());
    }

    @Override
    public void onDataPacket(net.minecraft.network.NetworkManager net, net.minecraft.network.play.server.SPacketUpdateTileEntity pkt) {
        readFromNBT(pkt.getNbtCompound());
    }

    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
        super.writeToNBT(nbt);


        if (ids != null){
            nbt.setBoolean("isPublic", false);
            nbt.setIntArray("ids", ids);
        }
        else
            nbt.setBoolean("isPublic", true);

        nbt.setBoolean("isActive", active);
        nbt.setInteger("FieldMaxRadius", maxRadius);
        nbt.setInteger("FieldRadius", radius);
        nbt = writeToNBTFieldStats(nbt);

        NBTTagList list = new NBTTagList();
        for (int i = 0; i < this.getSizeInventory(); ++i) {
            if (!this.getStackInSlot(i).isEmpty()) {
                NBTTagCompound stackTag = new NBTTagCompound();
                stackTag.setByte("Slot", (byte) i);
                this.getStackInSlot(i).writeToNBT(stackTag);
                list.appendTag(stackTag);
            }
        }
        nbt.setTag("Items", list);

        if (this.hasCustomName()) {
            nbt.setString("CustomName", this.getCustomName());
        }
        return nbt;
    }

    @Override
    public void readFromNBT(NBTTagCompound nbt) {
        super.readFromNBT(nbt);

        if (!nbt.getBoolean("isPublic")) {
            ids = nbt.getIntArray("ids");
        }
        else
            ids = null;

        active = nbt.getBoolean("isActive");
        maxRadius = nbt.getInteger("FieldMaxRadius");
        radius = nbt.getInteger("FieldRadius");
        readFromNBTFieldStats(nbt);

        NBTTagList list = nbt.getTagList("Items", 10);
        for (int i = 0; i < list.tagCount(); ++i) {
            NBTTagCompound stackTag = list.getCompoundTagAt(i);
            int slot = stackTag.getByte("Slot") & 255;
            //this.setInventorySlotContents(slot, new ItemStack(stackTag));
            inventory[slot] = new ItemStack(stackTag);
        }
        if (nbt.hasKey("CustomName", 8)) {
            this.setCustomName(nbt.getString("CustomName"));
        }
    }

    @Override
    public void updateValueModules(){
        int cVoltage = 0;
        int cRadius = 0;
        int cLossReduction = 0;

        for (int i = 1; i < inventory.length; i++)
            if (inventory[i] != ItemStack.EMPTY){
                if (inventory[i].getItem() instanceof ItemVoltageModule)
                    cVoltage += inventory[i].getCount();
                else if (inventory[i].getItem() instanceof ItemRadiusModule)
                    cRadius += inventory[i].getCount();
                else if (inventory[i].getItem() instanceof ItemLossReductionModule)
                    cLossReduction += inventory[i].getCount();
            }

        maxVoltage = 150 + 150 * cVoltage;
        maxRadius = 10 + 5 * cRadius;
        lossReduce = cLossReduction;
        try {
            if (voltage > maxVoltage)
                setVoltage(maxVoltage);
            if (radius > maxRadius)
                setRadius(maxRadius);
        }
        catch (NullPointerException e){System.out.println("Try to save, when world did not loaded");}
    }

    @Override
    public boolean isAccepted(Item item) {
        Item[] items = getAcceptedModules();
        for (int i = 0; i < items.length; i++)
            if (items[i].equals(item))
                return true;
        return false;
    }

    @Override
    public Item[] getAcceptedModules() {
        return new Item[]{
            ModItems.voltageModule,
            ModItems.lossReduceModule,
            ModItems.radiusModule,
            ModItems.lifeModule,
            ModItems.electricalModule,
            ModItems.aggressiveModule,
            ModItems.strangeModule,
            ModItems.luckModule
        };
    }

    @Override
    public int getModuleCount() {
        return 3;
    }

    public boolean hasFuncModule(){
        for (int i = 0; i < inventory.length; i++)
            if (inventory[i].getItem() instanceof ModuleFunctional)
                return true;
        return false;
    }

    public ItemStack getFuncModule(){
        for (int i = 0; i < inventory.length; i++)
            if (inventory[i].getItem() instanceof ModuleFunctional)
                return inventory[i];
        return ItemStack.EMPTY;
    }

    @Override
    public void createField() {
        ItemStack stack = getFuncModule();
        if (!stack.isEmpty())
            ((ModuleFunctional)stack.getItem()).lastUpdate(new FuncArgs(world, getPos(), radius, voltage, lossReduce, isPublic(), ids));
    }

    @Override
    public int getMaxRadius() {
        return maxRadius;
    }

    @Override
    public int getRadius() {
        return radius;
    }

    @Override
    public void setRadius(int radius) {
        this.radius = radius;
        ItemStack stack = getFuncModule();
        if (!stack.isEmpty())
            ((ModuleFunctional)stack.getItem()).changeRadius(new FuncArgs(world, getPos(), radius, voltage, lossReduce, isPublic(), ids));
    }

    public void setActive(boolean active) {
        this.active = active;
        ItemStack stack = getFuncModule();
        if (!stack.isEmpty())
            ((ModuleFunctional)stack.getItem()).changeActive(new FuncArgs(world, getPos(), radius, voltage, lossReduce, isPublic(), ids), active);
    }

    public boolean getActive(){
        return active;
    }

    public String[] getModuleInfo(){
        ItemStack stack = getFuncModule();
        if (!stack.isEmpty())
            return ((ModuleFunctional)stack.getItem()).getInfo();
        return null;
    }

    @Override
    public void cardsChanged() {
        if (!isPublic())
            setPrivate();
    }

    @Override
    public void setPrivate() {
        int[] toArray = new int[5];
        for (int i = 0; i < 5; i++)
            if (!inventory[i].isEmpty()) {
                try { toArray[i] = inventory[i].getTagCompound().getInteger("id"); }
                catch (NullPointerException e){ toArray[i] = 0; }
            }
        ids = toArray;
        markUpdate();
    }

    @Override
    public void setPublic() {
        ids = null;
        markUpdate();
    }

    @Override
    public boolean isPublic() {
        return ids == null;
    }
}

 

TileEntity parent:

Spoiler

public abstract class FieldReceiverEnergyStandart extends TileEntity implements IFieldReceiverEnergy {

    protected BlockPos link;
    protected int voltage;
    protected int maxVoltage;
    protected int frequency;

    @Override
    public void applyStats(int voltage) {
        this.voltage = voltage;
        if (voltage > maxVoltage)
            exceedingVoltage(voltage);
        markUpdate();
    }

    @Override
    public void applyCreatorsAround(){
        List<TileEntity> tes = EventsHandler.radiusFilter(getPos(), world.loadedTileEntityList, 100);
        for (int i = 0; i < tes.size(); i++) {
            if (tes.get(i) instanceof IFieldCreatorEnergy)
                ((IFieldCreatorEnergy) tes.get(i)).applyLinkedBlocks();
        }
    }

    @Override
    public abstract boolean isWork();

    @Override
    public abstract void onField();

    @Override
    public int getVoltage(){ return voltage; }

    @Override
    public int getMaxVoltage() {
        return maxVoltage;
    }

    @Override
    public int getFrequency(){ return frequency;}

    @Override
    public BlockPos getLink(){
        return link;
    }

    @Override
    public void setLink(BlockPos pos){
        if (pos == null)
            voltage = 0;
        link = pos;
        markUpdate();
    }

    @Override
    public boolean hasField(){
        return link != null;
    }

    @Override
    public void setFrequency(int frequency){
        this.frequency = frequency;
        applyCreatorsAround();
        markUpdate();
    }

    @Override
    public void setVoltage(int voltage){
        this.voltage = voltage;
        markUpdate();
    }

    public void exceedingVoltage(int voltage){
        if (link != null)
            ((IFieldCreatorEnergy)world.getTileEntity(link)).brokeLink(getPos());
        world.createExplosion(new EntityEgg(world, getPos().getX(), getPos().getY(), getPos().getZ()), getPos().getX(), getPos().getY(), getPos().getZ(), voltage/maxVoltage, true);
    }

    protected void markUpdate(){
        world.notifyBlockUpdate(getPos(), getBlockType().getDefaultState(), getBlockType().getDefaultState(), 0);
    }

    public NBTTagCompound writeToNBTFieldStats(NBTTagCompound nbt){
        if (hasField()) {
            nbt.setBoolean("HasLink", true);
            nbt.setInteger("LinkX", link.getX());
            nbt.setInteger("LinkY", link.getY());
            nbt.setInteger("LinkZ", link.getZ());
        }
        else
            nbt.setBoolean("HasLink", false);

        nbt.setInteger("FieldVoltage", voltage);
        nbt.setInteger("FieldMaxVoltage", maxVoltage);
        nbt.setInteger("FieldFrequency", frequency);
        return  nbt;
    }

    public void readFromNBTFieldStats(NBTTagCompound nbt){
        if (nbt.getBoolean("HasLink")){
            link = new BlockPos(nbt.getInteger("LinkX"), nbt.getInteger("LinkY"), nbt.getInteger("LinkZ"));
        }
        else
            link = null;
        voltage = nbt.getInteger("FieldVoltage");
        maxVoltage = nbt.getInteger("FieldMaxVoltage");
        frequency = nbt.getInteger("FieldFrequency");
    }
}

 

Link to comment
Share on other sites

I can't see what's wrong.

I don't like the way you've constructed your packet class (or its name), but it looks like it's doing safe things and as far as I can tell the TE is correctly saving its data to disk and reading it back again. So I'm not really sure what's up.

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.

Link to comment
Share on other sites

14 minutes ago, Draco18s said:

I can't see what's wrong.

I don't like the way you've constructed your packet class (or its name), but it looks like it's doing safe things and as far as I can tell the TE is correctly saving its data to disk and reading it back again. So I'm not really sure what's up.

The most interesting thing is that only "isPublic" is reset. All other values are perfectly readable when you re-enter the world

Link to comment
Share on other sites

Ah!

 

        if (!nbt.getBoolean("isPublic")) {
            ids = nbt.getIntArray("ids");
        }
        else
            ids = null;

 

You never set the isPublic field. You read the bool from the nbt and do the right thing reading more data,  but you never set the field. 

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.

Link to comment
Share on other sites

4 hours ago, Draco18s said:

Ah!

 


        if (!nbt.getBoolean("isPublic")) {
            ids = nbt.getIntArray("ids");
        }
        else
            ids = null;

 

You never set the isPublic field. You read the bool from the nbt and do the right thing reading more data,  but you never set the field. 

I do not have an isPublic field. IsPublic is used as a key to understand whether ids are null or not. Therefore, everything should work.  And I just realized that my NBT has stopped working on all the blocks. There are no exceptions. Because of what it can happen?

Edited by Minebot1708
Link to comment
Share on other sites

1 hour ago, Jay Avery said:

There's no isPublic field, so what do you mean by this?

 

This is key in NBTTagCompound. In any case, I further wrote that NBT generally ceased to work everywhere. Something is wrong with my code :)

Edited by Minebot1708
Link to comment
Share on other sites

7 hours ago, Jay Avery said:

What exactly do you mean by NBT stopped working? What do you find in the debugger? Are the read/write methods being called? Are the values null or incorrect? What was the last thing you changed before the problem started?

I will give an example of a bug. I go into the world, in the GUI of the blocks I change the variables. These variables are normally synchronized between the client and the server. If I get out of the world, and then come back, then those changes to the variables that I did will not happen. That is, the readFromNBT method will load those values of the variables that were during the  the last login in world, without taking my changes into account. But sometimes all the same readFromNBT loads the correct data when entering the world. In the debugger, I realized that when data is not synchronized during a restart, then when write-out of the world, writeToNBT is not called. When there is no bug, then before the last exit from the world, writeToNBT is called.
Null is nowhere to be found. Before the advent of this problem, I made that switch and added two variables to read / write. And I'll add that can not be called writeToNBT only for my TileEntity. When a bug occurs, TileEntity of vanilla does not suffer. At least in the chests things are save

Link to comment
Share on other sites

8 hours ago, Minebot1708 said:

The problem was that I did not call markDirty

markDirty is still around in 1.11.2? I thought we were supposed to change to some other method name about an update, or am I misremembering a different class?

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

18 minutes ago, jeffryfisher said:

markDirty is still around in 1.11.2?

TileEntity::markDirty is indeed still around, even in 1.12(and I checked - it does the same thing). It marks the chunk it is in as "dirty(1.12 name)/modified(1.11.x name)" aka "needs to be saved to disk as there were changes" and updates the comparator output for the block.

Edited by V0idWa1k3r
Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

Guest
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.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I tried to install forge, i got an error saying failed to download libraries com.google.code.findbugs:jsr305:3.0.2commons-io:commons-io:2.4 So i reinstalled Java on my computer, but now im getting a different error: Failed to run processor: java.net.ConnectException:Connection refused: connect How do I fix this? Log: JVM info: Oracle Corporation - 1.8.0_361 - 25.361-b09 java.net.preferIPv4Stack=true Found java version 1.8.0_361 Extracting json Considering minecraft client jar Downloading libraries Found 0 additional library directories Considering library cpw.mods:securejarhandler:2.1.4   File exists: Checksum validated. Considering library org.ow2.asm:asm:9.3   File exists: Checksum validated. Considering library org.ow2.asm:asm-commons:9.3   File exists: Checksum validated. Considering library org.ow2.asm:asm-tree:9.3   File exists: Checksum validated. Considering library org.ow2.asm:asm-util:9.3   File exists: Checksum validated. Considering library org.ow2.asm:asm-analysis:9.3   File exists: Checksum validated. Considering library net.minecraftforge:accesstransformers:8.0.4   File exists: Checksum validated. Considering library org.antlr:antlr4-runtime:4.9.1   File exists: Checksum validated. Considering library net.minecraftforge:eventbus:6.0.3   File exists: Checksum validated. Considering library net.minecraftforge:forgespi:6.0.0   File exists: Checksum validated. Considering library net.minecraftforge:coremods:5.0.1   File exists: Checksum validated. Considering library cpw.mods:modlauncher:10.0.8   File exists: Checksum validated. Considering library net.minecraftforge:unsafe:0.2.0   File exists: Checksum validated. Considering library com.electronwill.night-config:core:3.6.4   File exists: Checksum validated. Considering library com.electronwill.night-config:toml:3.6.4   File exists: Checksum validated. Considering library org.apache.maven:maven-artifact:3.8.5   File exists: Checksum validated. Considering library net.jodah:typetools:0.8.3   File exists: Checksum validated. Considering library net.minecrell:terminalconsoleappender:1.2.0   File exists: Checksum validated. Considering library org.jline:jline-reader:3.12.1   File exists: Checksum validated. Considering library org.jline:jline-terminal:3.12.1   File exists: Checksum validated. Considering library org.spongepowered:mixin:0.8.5   File exists: Checksum validated. Considering library org.openjdk.nashorn:nashorn-core:15.3   File exists: Checksum validated. Considering library net.minecraftforge:JarJarSelector:0.3.19   File exists: Checksum validated. Considering library net.minecraftforge:JarJarMetadata:0.3.19   File exists: Checksum validated. Considering library cpw.mods:bootstraplauncher:1.1.2   File exists: Checksum validated. Considering library net.minecraftforge:JarJarFileSystems:0.3.19   File exists: Checksum validated. Considering library net.minecraftforge:fmlloader:1.19.3-44.1.0   File exists: Checksum validated. Considering library com.github.jponge:lzma-java:1.3   File exists: Checksum validated. Considering library com.google.code.findbugs:jsr305:3.0.2   File exists: Checksum validated. Considering library com.google.code.gson:gson:2.8.7   File exists: Checksum validated. Considering library com.google.errorprone:error_prone_annotations:2.1.3   File exists: Checksum validated. Considering library com.google.guava:guava:20.0   File exists: Checksum validated. Considering library com.google.guava:guava:25.1-jre   File exists: Checksum validated. Considering library com.google.j2objc:j2objc-annotations:1.1   File exists: Checksum validated. Considering library com.nothome:javaxdelta:2.0.1   File exists: Checksum validated. Considering library com.opencsv:opencsv:4.4   File exists: Checksum validated. Considering library commons-beanutils:commons-beanutils:1.9.3   File exists: Checksum validated. Considering library commons-collections:commons-collections:3.2.2   File exists: Checksum validated. Considering library commons-io:commons-io:2.4   File exists: Checksum validated. Considering library commons-logging:commons-logging:1.2   File exists: Checksum validated. Considering library de.oceanlabs.mcp:mcp_config:1.19.3-20221207.122022@zip   File exists: Checksum validated. Considering library de.siegmar:fastcsv:2.0.0   File exists: Checksum validated. Considering library net.md-5:SpecialSource:1.11.0   File exists: Checksum validated. Considering library net.minecraftforge:ForgeAutoRenamingTool:0.1.22:all   File exists: Checksum validated. Considering library net.minecraftforge:binarypatcher:1.1.1   File exists: Checksum validated. Considering library net.minecraftforge:fmlcore:1.19.3-44.1.0   File exists: Checksum validated. Considering library net.minecraftforge:fmlloader:1.19.3-44.1.0   File exists: Checksum validated. Considering library net.minecraftforge:forge:1.19.3-44.1.0:universal   File exists: Checksum validated. Considering library net.minecraftforge:installertools:1.3.0   File exists: Checksum validated. Considering library net.minecraftforge:jarsplitter:1.1.4   File exists: Checksum validated. Considering library net.minecraftforge:javafmllanguage:1.19.3-44.1.0   File exists: Checksum validated. Considering library net.minecraftforge:lowcodelanguage:1.19.3-44.1.0   File exists: Checksum validated. Considering library net.minecraftforge:mclanguage:1.19.3-44.1.0   File exists: Checksum validated. Considering library net.minecraftforge:srgutils:0.4.11   File exists: Checksum validated. Considering library net.minecraftforge:srgutils:0.4.3   File exists: Checksum validated. Considering library net.minecraftforge:srgutils:0.4.9   File exists: Checksum validated. Considering library net.sf.jopt-simple:jopt-simple:5.0.4   File exists: Checksum validated. Considering library net.sf.jopt-simple:jopt-simple:6.0-alpha-3   File exists: Checksum validated. Considering library org.apache.commons:commons-collections4:4.2   File exists: Checksum validated. Considering library org.apache.commons:commons-lang3:3.8.1   File exists: Checksum validated. Considering library org.apache.commons:commons-text:1.3   File exists: Checksum validated. Considering library org.checkerframework:checker-qual:2.0.0   File exists: Checksum validated. Considering library org.codehaus.mojo:animal-sniffer-annotations:1.14   File exists: Checksum validated. Considering library org.ow2.asm:asm-analysis:9.2   File exists: Checksum validated. Considering library org.ow2.asm:asm-analysis:9.3   File exists: Checksum validated. Considering library org.ow2.asm:asm-commons:9.2   File exists: Checksum validated. Considering library org.ow2.asm:asm-commons:9.3   File exists: Checksum validated. Considering library org.ow2.asm:asm-tree:9.2   File exists: Checksum validated. Considering library org.ow2.asm:asm-tree:9.3   File exists: Checksum validated. Considering library org.ow2.asm:asm:9.2   File exists: Checksum validated. Considering library org.ow2.asm:asm:9.3   File exists: Checksum validated. Considering library trove:trove:1.0.2   File exists: Checksum validated. Created Temporary Directory: C:\Users\*\AppData\Local\Temp\forge_installer4970719337943492025   Extracting: /data/client.lzma Building Processors ===============================================================================   MainClass: net.minecraftforge.installertools.ConsoleTool   Classpath:     C:\Users\*\AppData\Roaming\.minecraft\libraries\net\minecraftforge\installertools\1.3.0\installertools-1.3.0.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\net\md-5\SpecialSource\1.11.0\SpecialSource-1.11.0.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\net\sf\jopt-simple\jopt-simple\5.0.4\jopt-simple-5.0.4.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\com\google\code\gson\gson\2.8.7\gson-2.8.7.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\de\siegmar\fastcsv\2.0.0\fastcsv-2.0.0.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\net\minecraftforge\srgutils\0.4.11\srgutils-0.4.11.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\org\ow2\asm\asm-commons\9.3\asm-commons-9.3.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\com\google\guava\guava\20.0\guava-20.0.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\com\opencsv\opencsv\4.4\opencsv-4.4.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\org\ow2\asm\asm-analysis\9.3\asm-analysis-9.3.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\org\ow2\asm\asm-tree\9.3\asm-tree-9.3.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\org\ow2\asm\asm\9.3\asm-9.3.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\org\apache\commons\commons-text\1.3\commons-text-1.3.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\org\apache\commons\commons-lang3\3.8.1\commons-lang3-3.8.1.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\commons-beanutils\commons-beanutils\1.9.3\commons-beanutils-1.9.3.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\org\apache\commons\commons-collections4\4.2\commons-collections4-4.2.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\commons-logging\commons-logging\1.2\commons-logging-1.2.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar   Args: --task, MCP_DATA, --input, C:\Users\*\AppData\Roaming\.minecraft\libraries\de\oceanlabs\mcp\mcp_config\1.19.3-20221207.122022\mcp_config-1.19.3-20221207.122022.zip, --output, C:\Users\*\AppData\Roaming\.minecraft\libraries\de\oceanlabs\mcp\mcp_config\1.19.3-20221207.122022\mcp_config-1.19.3-20221207.122022-mappings.txt, --key, mappings Task: MCP_DATA Input:  C:\Users\*\AppData\Roaming\.minecraft\libraries\de\oceanlabs\mcp\mcp_config\1.19.3-20221207.122022\mcp_config-1.19.3-20221207.122022.zip Output: C:\Users\*\AppData\Roaming\.minecraft\libraries\de\oceanlabs\mcp\mcp_config\1.19.3-20221207.122022\mcp_config-1.19.3-20221207.122022-mappings.txt Key:    mappings Extracting: config/joined.tsrg ===============================================================================   MainClass: net.minecraftforge.installertools.ConsoleTool   Classpath:     C:\Users\*\AppData\Roaming\.minecraft\libraries\net\minecraftforge\installertools\1.3.0\installertools-1.3.0.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\net\md-5\SpecialSource\1.11.0\SpecialSource-1.11.0.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\net\sf\jopt-simple\jopt-simple\5.0.4\jopt-simple-5.0.4.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\com\google\code\gson\gson\2.8.7\gson-2.8.7.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\de\siegmar\fastcsv\2.0.0\fastcsv-2.0.0.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\net\minecraftforge\srgutils\0.4.11\srgutils-0.4.11.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\org\ow2\asm\asm-commons\9.3\asm-commons-9.3.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\com\google\guava\guava\20.0\guava-20.0.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\com\opencsv\opencsv\4.4\opencsv-4.4.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\org\ow2\asm\asm-analysis\9.3\asm-analysis-9.3.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\org\ow2\asm\asm-tree\9.3\asm-tree-9.3.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\org\ow2\asm\asm\9.3\asm-9.3.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\org\apache\commons\commons-text\1.3\commons-text-1.3.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\org\apache\commons\commons-lang3\3.8.1\commons-lang3-3.8.1.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\commons-beanutils\commons-beanutils\1.9.3\commons-beanutils-1.9.3.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\org\apache\commons\commons-collections4\4.2\commons-collections4-4.2.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\commons-logging\commons-logging\1.2\commons-logging-1.2.jar     C:\Users\*\AppData\Roaming\.minecraft\libraries\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar   Args: --task, DOWNLOAD_MOJMAPS, --version, 1.19.3, --side, client, --output, C:\Users\*\AppData\Roaming\.minecraft\libraries\net\minecraft\client\1.19.3-20221207.122022\client-1.19.3-20221207.122022-mappings.txt Task: DOWNLOAD_MOJMAPS MC Version: 1.19.3 Side:       client Output:     C:\Users\*\AppData\Roaming\.minecraft\libraries\net\minecraft\client\1.19.3-20221207.122022\client-1.19.3-20221207.122022-mappings.txt java.net.ConnectException: Connection refused: connect     at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)     at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)     at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)     at java.net.AbstractPlainSocketImpl.connect(Unknown Source)     at java.net.PlainSocketImpl.connect(Unknown Source)     at java.net.SocksSocketImpl.connect(Unknown Source)     at java.net.Socket.connect(Unknown Source)     at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)     at sun.security.ssl.BaseSSLSocketImpl.connect(Unknown Source)     at sun.net.NetworkClient.doConnect(Unknown Source)     at sun.net.www.http.HttpClient.openServer(Unknown Source)     at sun.net.www.http.HttpClient.openServer(Unknown Source)     at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)     at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)     at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)     at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)     at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)     at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)     at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)     at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)     at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)     at java.net.URL.openStream(Unknown Source)     at net.minecraftforge.installertools.DownloadMojmaps.process(DownloadMojmaps.java:65)     at net.minecraftforge.installertools.ConsoleTool.main(ConsoleTool.java:55)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)     at java.lang.reflect.Method.invoke(Unknown Source)     at net.minecraftforge.installer.actions.PostProcessors.process(PostProcessors.java:226)     at net.minecraftforge.installer.actions.ClientInstall.run(ClientInstall.java:144)     at net.minecraftforge.installer.InstallerPanel.run(InstallerPanel.java:423)     at net.minecraftforge.installer.SimpleInstaller.launchGui(SimpleInstaller.java:175)     at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:147) Failed to run processor: java.net.ConnectException:Connection refused: connect See log for more details.  
    • I can get Player Mod Name by use this code. ImmutableList<String> mods = NetworkHooks.getConnectionData(p.connection.netManager) .getModList(); That code just getting the mod name. but I want to get mod version. How can I get Player Mod Version ? in 1.16.5 Please help me.  
    • As a result of the popularity of NFTs, today, the best crypto games are available in almost every market you can think of. To give you an idea, we discuss some of the types of blockchain games that might interest you below. 1. Virtual world games 2. Fantasy sports 3. Fighting games 4. Development games. The following two are currently popular Cryptokitties is a casual virtual cat game traded in Ethereum crypto-currency, which was launched and operated on November 28, 2017. FairyCat: Fairy Cat, a new blockchain game launching in 2023, has one of the highest returns of any blockchain game and will be the most popular virtual coin game in 2023.   One of the main reasons why most investors choose to play P2E crypto games is to make money. However, you may have noticed that many top crypto games offer rewards in the form of NFTs. However, the NFTs in the games are unique and transparent. In other words, when you buy assets in the game, you become the owner. Depending on the game, the NFTs you collect can be player avatars, characters, creatures, special items, or any other artifact. These NFTs can be traded or sold on other platforms, allowing you to receive cash or other crypto-currencies in return. In addition, you can keep these rewards until you find the right time to cash them in.
    • As a result of the popularity of NFTs, today, the best crypto games are available in almost every market you can think of. To give you an idea, we discuss some of the types of blockchain games that might interest you below. 1. Virtual world games 2. Fantasy sports 3. Fighting games 4. Development games. The following two are currently popular Cryptokitties is a casual virtual cat game traded in Ethereum crypto-currency, which was launched and operated on November 28, 2017. FairyCat: Fairy Cat, a new blockchain game launching in 2023, has one of the highest returns of any blockchain game and will be the most popular virtual coin game in 2023.   One of the main reasons why most investors choose to play P2E crypto games is to make money. However, you may have noticed that many top crypto games offer rewards in the form of NFTs. However, the NFTs in the games are unique and transparent. In other words, when you buy assets in the game, you become the owner. Depending on the game, the NFTs you collect can be player avatars, characters, creatures, special items, or any other artifact. These NFTs can be traded or sold on other platforms, allowing you to receive cash or other crypto-currencies in return. In addition, you can keep these rewards until you find the right time to cash them in.
    • As a result of the popularity of NFTs, today, the best crypto games are available in almost every market you can think of. To give you an idea, we discuss some of the types of blockchain games that might interest you below. 1. Virtual world games 2. Fantasy sports 3. Fighting games 4. Development games. The following two are currently popular   Cryptokitties is a casual virtual cat game traded in Ethereum crypto-currency, which was launched and operated on November 28, 2017. FairyCat: Fairy Cat, a new blockchain game launching in 2023, has one of the highest returns of any blockchain game and will be the most popular virtual coin game in 2023.   One of the main reasons why most investors choose to play P2E crypto games is to make money. However, you may have noticed that many top crypto games offer rewards in the form of NFTs. However, the NFTs in the games are unique and transparent. In other words, when you buy assets in the game, you become the owner. Depending on the game, the NFTs you collect can be player avatars, characters, creatures, special items, or any other artifact. These NFTs can be traded or sold on other platforms, allowing you to receive cash or other crypto-currencies in return. In addition, you can keep these rewards until you find the right time to cash them in.
  • Topics

×
×
  • Create New...

Important Information

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