Jump to content

[1.15] Changes to player and to tile entity from screen gui not saving.


Recommended Posts

Posted

So I'm trying to have my block store experience. and using buttons in the gui of the block you should be able to deposit levels to the block or take them out. while the buttons work and will alter both the players xp levels and the xp stored in the block, if you close the gui it reverts to what it was before using the buttons and if the players xp was changed via the buttons in the gui, upon saving and reloading the world it will be set back to what it was before. I'm really confused because the block can also "gain" xp by placing items in its slot, and this works fine. and the button code i took from that. and i use methods in the EntityPlayer class to alter the xp values. My guess is its something to do with the server not getting the memo things have changed, but i dont know why using the fuel to xp mechanic works then because they both use similar means. Id really appreciate some help here.

 

My Screen

package com.mekelaina.gramarye.gui.screens;

import com.mekelaina.gramarye.Gramarye;
import com.mekelaina.gramarye.gui.containers.ObeliskContainer;
import com.mekelaina.gramarye.blocks.tiles.ObeliskTile;
import com.mekelaina.gramarye.gui.element.CustomButton;
import com.mekelaina.gramarye.gui.element.WidgetWrapper;
import com.mekelaina.gramarye.util.XPMathUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;

import java.awt.*;

public class ObeliskScreen extends ContainerScreen<ObeliskContainer> {

    private ResourceLocation GUI ;
    private ObeliskTile obeliskTile;
    private Rectangle xp;

    private CustomButton depositLvl;
    private CustomButton retrieveLvl;

    public ObeliskScreen(ObeliskContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
        super(screenContainer, inv, titleIn);
        this.obeliskTile = screenContainer.getTileEntity();
        xp = new Rectangle(135, 5, 36, 68);

    }

    @Override
    public void render(int mouseX, int mouseY, float partialTicks) {
        super.render(mouseX, mouseY, partialTicks);
        this.renderHoveredToolTip(mouseX, mouseY);
    }

    @Override
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
       // this.font.drawString(this.title.getFormattedText(), 8.0f, 6.0f, 4210752);
        //this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 8.0f, (float)(this.ySize - 94), 4210752);
       // drawString(Minecraft.getInstance().fontRenderer, "Energy: " + container.getEnergy(), this.xSize - (this.xSize / 2), 6, 0x4AEDD9);
        //renderHoveredToolTip(mouseX - this.xSize - (this.xSize / 2), mouseY);

        String toDraw = "Xp: " + this.container.getEnergy() + " Lvl: " + XPMathUtils.getClosestLevelByXp(this.container.getEnergy());

       // Gramarye.LOGGER.debug(font.getStringWidth(toDraw));
        this.font.drawString(toDraw, (float)(this.xSize - (font.getStringWidth(toDraw) + 4)), (float)(this.ySize - 92), 0xF5FF8F);

        /*//Gramarye.LOGGER.debug("mouse x: " + mouseX + "mouse y: " + mouseY);
        if(isOverXpBar(mouseX, mouseY)) {
            blit(mouseX, mouseY, 129, 166, 32, 20);
            drawString(Minecraft.getInstance().fontRenderer, toDraw, mouseX , mouseY, 0x4AEDD9);
        }*/
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
       // GlStateManager.color4f(1f, 1f, 1f, 1f);

        this.minecraft.getTextureManager().bindTexture(GUI);
        int relX = (this.width - this.xSize) / 2;
        int relY = (this.height - this.ySize) / 2;
        this.blit(relX, relY, 0, 0, this.xSize, this.ySize);



        int k = this.getExperienceStoredScaled(64);
       // Gramarye.LOGGER.debug(64);
        //k += (k-64) ;
        blit(this.guiLeft + 71, this.guiTop + 7 + (64-k), 176, 1+(64-k), 32, k);
    }

    private int getExperienceStoredScaled(int pixels) {
        int i = this.container.getEnergy();
        int j = this.obeliskTile.getCapacity();
        return i != 0 && j != 0 ? i * pixels / j : 0;
    }

    private boolean isOverXpBar(int mouseX, int mouseY) {
        return mouseX >= this.guiLeft + this.xp.x && mouseY >= this.guiTop + xp.y && mouseX < xp.x + xp.width && mouseY < xp.y + xp.height;
    }

    @Override
    protected void init() {
        super.init();
        GUI = new ResourceLocation(Gramarye.MODID, "textures/gui/test_gui2.png");
        WidgetWrapper[] temp = new WidgetWrapper[] {new WidgetWrapper(176, 65, 20, 20), new WidgetWrapper(176, 85, 20, 20),
                new WidgetWrapper(176, 105, 20, 20), new WidgetWrapper(176, 125, 20, 20)};
        depositLvl = new CustomButton(this.guiLeft + 118, this.guiTop + 5, 20, 20, temp, p_onPress_1_ -> insertOneLevel());
        depositLvl.setTexture(GUI);
        this.addButton(depositLvl);
        temp = new WidgetWrapper[] {new WidgetWrapper(176, 65, 20, 20), new WidgetWrapper(176, 85, 20, 20),
                new WidgetWrapper(176, 105, 20, 20), new WidgetWrapper(176, 145, 20, 20)};
        retrieveLvl = depositLvl = new CustomButton(this.guiLeft + 145, this.guiTop + 5, 20, 20, temp, p_onPress_1_ -> retrieveOneLevel());
        retrieveLvl.setTexture(GUI);
        this.addButton(retrieveLvl);
    }

    private void initButtons() {



        //this.addButton(new Button(this.guiLeft + 84, this.guiTop + 5, 20, 20, "Boop", p_onPress_1_ -> sendMessage()));
    }

    private void sendMessage(){
        this.container.getPlayer().sendStatusMessage(new StringTextComponent("test"), false);
        //this.container.getPlayer().e
    }

    private void insertOneLevel(){
        PlayerEntity player = container.getPlayer();
        Gramarye.LOGGER.debug("player");
        if(!player.isCreative()) {
            int playerLvl = player.experienceLevel;
            int playerTotal = player.experienceTotal;
            if(playerTotal > 0 && playerLvl > 0) {
                int currentLvlsWorth = XPMathUtils.getXpToLevelUp(playerLvl-1);
               this.obeliskTile.insertXp(currentLvlsWorth);
               player.giveExperiencePoints(-currentLvlsWorth);
            } else if(playerTotal > 0 && playerLvl <= 0) {

                this.obeliskTile.insertXp(playerTotal);
                player.giveExperiencePoints(-playerTotal);
            }
        } else {
            int currentLvl = XPMathUtils.getClosestLevelByXp(this.obeliskTile.getEnergy());
            int toAdd = XPMathUtils.totalXpByLevel(currentLvl+1) - this.obeliskTile.getEnergy();
            this.obeliskTile.insertXp(toAdd);
        }
    }
    public void retrieveOneLevel() {
        PlayerEntity player = container.getPlayer();
        Gramarye.LOGGER.debug("player");
        if(!player.isCreative()) {
            int obeliskTotal = this.container.getEnergy();
            int obeliskLvl = XPMathUtils.getClosestLevelByXp(obeliskTotal);
            if(obeliskTotal > 0 && obeliskLvl > 0) {
                int currentLvlsWorth = XPMathUtils.getXpToLevelUp(obeliskLvl-1);
                this.obeliskTile.removeXp(currentLvlsWorth);
                player.giveExperiencePoints(currentLvlsWorth);
            } else if(obeliskTotal > 0 && obeliskLvl <= 0) {

                this.obeliskTile.removeXp(obeliskTotal);
                player.giveExperiencePoints(obeliskTotal);
            }
        } else {
            int currentLvl = XPMathUtils.getClosestLevelByXp(this.obeliskTile.getEnergy());
            int toRemove =  this.obeliskTile.getEnergy() - XPMathUtils.totalXpByLevel(currentLvl-1);
            this.obeliskTile.removeXp(toRemove);
        }
    }
}

 

container

package com.mekelaina.gramarye.gui.containers;

import com.mekelaina.gramarye.Gramarye;
import com.mekelaina.gramarye.blocks.ModBlocks;
import com.mekelaina.gramarye.blocks.tiles.ObeliskTile;
import com.mekelaina.gramarye.items.ModItems;
import com.mekelaina.gramarye.util.CustomEnergyStorage;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.IWorldPosCallable;
import net.minecraft.util.IntReferenceHolder;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.SlotItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;

public class ObeliskContainer extends ExtendedContainer {

    public ObeliskContainer(int windowId, World world, BlockPos pos, PlayerInventory playerInventory, PlayerEntity player) {
        super(ModContainers.OBELISK_CONTAINER.get(), windowId);
        tileEntity = world.getTileEntity(pos);
        this.playerEntity = player;
        this.playerInventory = new InvWrapper(playerInventory);

        tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(handler -> {
            addSlot(new SlotItemHandler(handler, 0, 24, 45));
        });
        layoutPlayerInventorySlots(8, 84);

        trackInt(new IntReferenceHolder() {
            @Override
            public int get() {
                return getEnergy();
            }

            @Override
            public void set(int value) {
                tileEntity.getCapability(CapabilityEnergy.ENERGY).ifPresent(h -> ((CustomEnergyStorage)h).setEnergy(value));
            }
        });
    }

    public int getEnergy() {
        return tileEntity.getCapability(CapabilityEnergy.ENERGY).map(IEnergyStorage::getEnergyStored).orElse(0);
    }

    @Override
    public boolean canInteractWith(PlayerEntity playerIn) {
        return isWithinUsableDistance(IWorldPosCallable.of(tileEntity.getWorld(), tileEntity.getPos()), playerIn, ModBlocks.OBELISK.get());
    }

    @Override
    public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
        ItemStack itemStack = ItemStack.EMPTY;
        Slot slot = this.inventorySlots.get(index);
        if(slot != null && slot.getHasStack()) {
            ItemStack stack = slot.getStack();
            itemStack = stack.copy();
            if(index == 0) {
                if(!this.mergeItemStack(stack, 1, 37, true)) {
                    return ItemStack.EMPTY;
                }
                slot.onSlotChange(stack, itemStack);
            } else {
                if(stack.getItem() == Items.EXPERIENCE_BOTTLE || stack.getItem() == ModItems.CRYSTAL.get()
                        || stack.getItem() == ModBlocks.CRYSTALBLOCK.get().asItem()) {
                    if(!this.mergeItemStack(stack, 0, 1, false)) {
                        return ItemStack.EMPTY;
                    }
                } else if(index < 28) {
                    if(!this.mergeItemStack(stack, 28, 37, false)) {
                        return ItemStack.EMPTY;
                    }
                } else if(index < 37 && !this.mergeItemStack(stack, 1, 28, false)) {
                    return ItemStack.EMPTY;
                }
            }

            if(stack.isEmpty()) {
                slot.putStack(ItemStack.EMPTY);
            } else {
                slot.onSlotChanged();
            }

            if(stack.getCount() == itemStack.getCount()) {
                return ItemStack.EMPTY;
            }

            slot.onTake(playerIn, stack);
        }
        return itemStack;
    }

    public ObeliskTile getTileEntity() {
        return (ObeliskTile)this.tileEntity;
    }


    private boolean isItemValid(ItemStack stack) {
        Gramarye.LOGGER.debug(stack);
        if(stack.getItem() == Items.EXPERIENCE_BOTTLE || stack.getItem() == ModItems.CRYSTAL.get()
                || stack.getItem() == ModBlocks.CRYSTALBLOCK.get().asItem()) {
            return true;
        }
        return false;
    }

    public PlayerEntity getPlayer(){
        return this.playerEntity;
    }
}

 

tile entity

package com.mekelaina.gramarye.blocks.tiles;

import com.mekelaina.gramarye.Gramarye;
import com.mekelaina.gramarye.blocks.ModBlocks;
import com.mekelaina.gramarye.gui.containers.ObeliskContainer;
import com.mekelaina.gramarye.items.ModItems;
import com.mekelaina.gramarye.util.CustomEnergyStorage;
import com.mekelaina.gramarye.util.XPMathUtils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

public class ObeliskTile extends TileEntity implements ITickableTileEntity, INamedContainerProvider {

    private LazyOptional<IItemHandler> handler = LazyOptional.of(this::createHandler);
    private LazyOptional<IEnergyStorage> energy = LazyOptional.of(this::createEnergy);

    private ArrayList<InputWrapper> toProcess = new ArrayList<>();

    private int counter;
    private int inputType=0;
    private ItemStack lastItem;
    private double speed = 2;
    private double translation = 0;
    private double lastTranslation = 0;



    public ObeliskTile() {
        super(ModTileEntities.OBELISK_TILE.get());
    }

    @Override
    public void tick() {
        if(world.isRemote()) {
            return;
        }

        if(counter > 0) {
            counter--;
            if(counter <= 0) {
                energy.ifPresent(e -> ((CustomEnergyStorage)e).addEnergy(getXpPerInput()));
                inputType = 0;
            }
            markDirty();
        }

        if(counter <=0) {
            handler.ifPresent(handler1 -> {
                ItemStack stack = handler1.getStackInSlot(0);
                if(stack.getItem() == Items.EXPERIENCE_BOTTLE || stack.getItem() == ModItems.CRYSTAL.get()
                        || stack.getItem() == ModBlocks.CRYSTALBLOCK.get().asItem()) {
                    lastItem = stack.copy();
                    handler1.extractItem(0, 1, false);
                    counter = 20;
                    markDirty();
                }
            });
        }

        /*for (InputWrapper i : toProcess) {
            Gramarye.LOGGER.debug("DOOOOOOOOO");
            if(i.isAdd()){
                energy.ifPresent(iEnergyStorage -> {
                    ((CustomEnergyStorage)iEnergyStorage).addEnergy(XPMathUtils.getXpToInsert(iEnergyStorage.getEnergyStored(),
                            iEnergyStorage.getMaxEnergyStored(), i.getAmount()));
                });
            } else {
                energy.ifPresent(iEnergyStorage -> {
                    ((CustomEnergyStorage)iEnergyStorage).consumeEnergy(XPMathUtils.getXpToInsert(iEnergyStorage.getEnergyStored(),
                            iEnergyStorage.getMaxEnergyStored(), i.getAmount()));
                });
            }
            //toProcess.remove(i);
            markDirty();
        }

        toProcess.clear();*/

        sendOutPower();

    }

    private void sendOutPower() {
        energy.ifPresent(e -> {
            AtomicInteger capacity = new AtomicInteger(e.getEnergyStored());
            if(capacity.get() > 0) {
                for (Direction direction : Direction.values()) {
                    TileEntity tileEntity = world.getTileEntity(pos.offset(direction));
                    if(tileEntity != null) {
                        boolean doContinue = tileEntity.getCapability(CapabilityEnergy.ENERGY, direction).map(handler -> {
                            if(handler.canReceive()) {
                                int received = handler.receiveEnergy(Math.min(capacity.get(), 100), false);
                                capacity.addAndGet(-received);
                                ((CustomEnergyStorage)e).consumeEnergy(received);
                                markDirty();
                                return capacity.get() > 0;
                            } else {
                                return true;
                            }
                        }).orElse(true);
                        if(!doContinue) {
                            return;
                        }
                    }
                }
            }
        });
    }

    @Override
    public void read(CompoundNBT compound) {
        CompoundNBT invTag = compound.getCompound("inv");
        handler.ifPresent(handler1 -> ((INBTSerializable<CompoundNBT>)handler1).deserializeNBT(invTag));
        CompoundNBT energyTag = compound.getCompound("experion");
        energy.ifPresent(energy1 -> ((CustomEnergyStorage)energy1).setEnergy(energyTag.getInt("experion")));
        CompoundNBT speedTag = compound.getCompound("speed");
        this.speed = speedTag.getDouble("speed");
        super.read(compound);
    }

    @Override
    public CompoundNBT write(CompoundNBT compound) {
        handler.ifPresent(h -> {
            CompoundNBT compoundNBT = ((INBTSerializable<CompoundNBT>)h).serializeNBT();
            compound.put("inv", compoundNBT);
        });
        energy.ifPresent(h -> {
            CompoundNBT compoundNBT = ((INBTSerializable<CompoundNBT>)h).serializeNBT();
            compound.put("experion", compoundNBT);
        });
        compound.putDouble("speed", this.speed);
        return super.write(compound);
    }

    private ItemStackHandler createHandler() {
        return new ItemStackHandler(1){
            @Override
            public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
                if(stack.getItem() == Items.EXPERIENCE_BOTTLE || stack.getItem() == ModItems.CRYSTAL.get()
                        || stack.getItem() == ModBlocks.CRYSTALBLOCK.get().asItem()) {
                    return true;
                }
                return false;
            }

            @Override
            protected void onContentsChanged(int slot) {
                markDirty();
            }

            @Nonnull
            @Override
            public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
                if(stack.getItem() != ModItems.CRYSTAL.get() && stack.getItem() != Items.EXPERIENCE_BOTTLE
                && stack.getItem() != ModBlocks.CRYSTALBLOCK.get().asItem()){
                    return stack;
                }
                return super.insertItem(slot, stack, simulate);
            }
        };
    }

    @Nonnull
    @Override
    public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
        if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
            return handler.cast();
        }
        if(cap == CapabilityEnergy.ENERGY) {
            return energy.cast();
        }
        return super.getCapability(cap, side);
    }

    @Override
    public ITextComponent getDisplayName() {
        return new TranslationTextComponent("block.gramarye.obelisk");
    }

    @Nullable
    @Override
    public Container createMenu(int i, PlayerInventory playerInventory, PlayerEntity playerEntity) {
        return new ObeliskContainer(i, world, pos, playerInventory, playerEntity);
    }

    private IEnergyStorage createEnergy() {
        return new CustomEnergyStorage(2048, 0);
    }

    private int getXpPerInput()
    {
       if(lastItem != null) {
           if(lastItem.getItem() == Items.EXPERIENCE_BOTTLE) {
               lastItem = ItemStack.EMPTY;
               return 3 + this.world.rand.nextInt(5) + this.world.rand.nextInt(5);
           }
           if(lastItem.getItem() == ModItems.CRYSTAL.get()) {
               lastItem = ItemStack.EMPTY;
               return 20;
           }
           if(lastItem.getItem() == ModBlocks.CRYSTALBLOCK.get().asItem()) {
               lastItem = ItemStack.EMPTY;
               return 100;
           }
       }
       return 0;

    }

    public boolean insertXp(int amount) {
        AtomicBoolean rtn = new AtomicBoolean(false);
        energy.ifPresent(iEnergyStorage -> {
            int temp = XPMathUtils.getXpToInsert(iEnergyStorage.getEnergyStored(),
                    iEnergyStorage.getMaxEnergyStored(), amount);
            ((CustomEnergyStorage)iEnergyStorage).addEnergy(temp);
            rtn.set(true);
            markDirty();
        });
        //markDirty();
        return rtn.get();

        /*toProcess.add(new InputWrapper(amount, true));
        return true;*/
    }

    public boolean removeXp(int amount) {
        AtomicBoolean rtn = new AtomicBoolean(false);
        energy.ifPresent(iEnergyStorage -> {
            int temp = XPMathUtils.getXpToInsert(iEnergyStorage.getEnergyStored(),
                    iEnergyStorage.getMaxEnergyStored(), amount);
            ((CustomEnergyStorage)iEnergyStorage).consumeEnergy(temp);
            rtn.set(true);
            markDirty();
        });

        return rtn.get();

        /*toProcess.add(new InputWrapper(amount, false));
        return true;*/
    }

    private void calculateTranslation() {
        this.lastTranslation = this.translation;
        this.translation += (float)(Math.sin(speed * counter));
    }

    public double getTranslation() {
        return translation;
    }

    public int getCapacity() {
        AtomicInteger temp = new AtomicInteger();
         energy.ifPresent(e -> {
             temp.set(e.getMaxEnergyStored());});
         return temp.get();
    }

    public int getEnergy() {
        AtomicInteger temp = new AtomicInteger();
        energy.ifPresent(e -> {
            temp.set(e.getEnergyStored());
        });
        return temp.get();
    }

    private boolean isItemValid(ItemStack stack) {
        //Gramarye.LOGGER.debug("called from is item valid");
        if(stack.getItem() == Items.EXPERIENCE_BOTTLE) {
           inputType = 1;
            Gramarye.LOGGER.debug("xp bottle " + inputType);
           return true;
       } else if(stack.getItem() == ModItems.CRYSTAL.get()) {
           inputType = 2;
            Gramarye.LOGGER.debug("crystal " + inputType);
           return true;
       } else if(stack.getItem() == ModBlocks.CRYSTALBLOCK.get().asItem()) {
            inputType = 3;
            Gramarye.LOGGER.debug("cryatal blcok  " + inputType);
            return true;
        }
        return false;
    }
}

class InputWrapper {
    private int amount;
    private boolean add;

    public InputWrapper(int amount, boolean add) {
        this.amount = amount;
        this.add = add;
    }

    public int getAmount() {
        return amount;
    }

    public boolean isAdd() {
        return add;
    }
}

 

 

the energy capability extension

package com.mekelaina.gramarye.util;

import net.minecraft.nbt.CompoundNBT;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.energy.EnergyStorage;

public class CustomEnergyStorage extends EnergyStorage implements INBTSerializable<CompoundNBT> {
    public CustomEnergyStorage(int capacity, int maxTransfer) {
        super(capacity, maxTransfer);
    }

    public void setEnergy(int energy){
        this.energy = energy;
    }

    public void addEnergy(int energy)
    {
        this.energy += energy;
        if(this.energy > getMaxEnergyStored()){
            this.energy = getEnergyStored();
        }
    }

    public void consumeEnergy(int energy)
    {
        this.energy -= energy;
        if(this.energy < 0){
            this.energy = 0;
        }
    }



    @Override
    public CompoundNBT serializeNBT() {
        CompoundNBT tag = new CompoundNBT();
        tag.putInt("experion", getEnergyStored());
        return tag;
    }

    @Override
    public void deserializeNBT(CompoundNBT nbt) {
        setEnergy(nbt.getInt("experion"));
    }
}

 

Posted

Since screen is client side only, changes done through the screen will only affect the client which server does not know anything from it (will not be saved), so you will need packets to tell the server what you've changed from client.

And the reason for the 

Quote

"gain" xp by placing items in its slot

works because you are making changes on server ( in tick() ), which it saves and knows what you've done.

 

  • Like 1

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.