Jump to content

Recommended Posts

Posted

Hey there,

 

*Packets are being to used to sync everything*

 

SO I have a capability that adds: level, corruption, and experience. Simple. However, when I'm using an Item to add to the capability, it displays for 1 frame, then resets, here are some pictures of whats happening:

 

 

So, on connect, it displays normally:

1d5939e96a3540848f8b79911a57977e.png

However, when I right click with the item, It seems to display a weird number for 1 frame, then reset.

Note: that local debugging shows the values are always 0 however.

99ba203e052f443fa6bb521f54a8c615.png

phew, that took awhile, anyways, then it resets to this:

1d5939e96a3540848f8b79911a57977e.png

 

 

 

 

Okay, so I am syncing the client every time the value is changed and when the player connects..

So here is the capability data:

public class CapabilityLevelData extends LevelHandler
{
    private EntityLivingBase entity;

    public CapabilityLevelData(){ super(500); }

    public EntityLivingBase getEntity() {
        return entity;
    }

    public void setEntity(EntityLivingBase entity)
    {
        this.entity = entity;
    }

    public float addExperienceInternal(float experienceToAdd) {
        float toReturn = this.addExperience(experienceToAdd);
        sendPacket();
        return toReturn;
    }

    public int addLevelsInternal(int levelsToAdd) {
        int toReturn = this.addLevels(levelsToAdd);
        sendPacket();
        return toReturn;
    }

    public int removeLevelsInternal(int levelsToRemove) {
        int toReturn = this.removeLevels(levelsToRemove);
        sendPacket();
        return toReturn;
    }

    public int addCorruptionInternal(int corruptionToAdd) {
        int toReturn = this.addCorruption(corruptionToAdd);
        sendPacket();
        return toReturn;
    }

    public int removeCorruptionInternal(int corruptionToRemove) {
        int toReturn = this.removeCorruption(corruptionToRemove);
        sendPacket();
        return toReturn;
    }
//todo
public void updateExpForLevelUp() {
    float currentXP = this.getExperience();
    int currentLevel = this.getLevels();
    int currentCorruption = this.getCorruption();

    float currentXPToLevelUp = currentLevel * (levelUpIncrement + currentCorruption);

    if(currentXP >= currentXPToLevelUp) {
        this.addLevelsInternal(1);
        this.setExpereince(0);
    }

    if(currentLevel <= 0) {
        this.setLevel(1);
    }

    if(currentLevel >= 100) {
        this.setLevel(100);
    }
}


    @Override
    public float addExperience(float experienceToAdd) {
        float currentExp = this.getExperience();

        float returnedExp = currentExp+=experienceToAdd;

        this.setExpereince(returnedExp);

        return returnedExp;
    }

    @Override
    public int addLevels(int levelsToAdd) {
        int currentLevel = this.getLevels();

        int returnedLevel = currentLevel+=levelsToAdd;

        this.setLevel(returnedLevel);
        sendPacket();
        return returnedLevel;
    }

    @Override
    public int removeLevels(int levelsToRemove) {
        int currentLevel = this.getLevels();

        int returnedLevel = currentLevel-+levelsToRemove;

        this.setLevel(returnedLevel);
        sendPacket();
        return returnedLevel;
    }

    @Override
    public int addCorruption(int corruptionToAdd) {
        int currentCurruption = this.getCorruption();

        int returnedCorruption = currentCurruption+=corruptionToAdd;

        this.setCorruption(returnedCorruption);
        sendPacket();
        return returnedCorruption;
    }

    @Override
    public int removeCorruption(int corruptionToRemove) {
        int currentCurruption = this.getCorruption();

        int returnedCorruption = currentCurruption-=corruptionToRemove;

        this.setCorruption(returnedCorruption);
        sendPacket();
        return returnedCorruption;
    }

    public void readFromNBT(NBTTagCompound compound){
        this.setLevel(compound.getInteger("Level"));
        this.setCorruption(compound.getInteger("Corruption"));
        this.setExpereince(compound.getFloat("Experience"));
    }

    public void writeToNBT(NBTTagCompound compound){
        compound.setInteger("Level", this.getLevels());
        compound.setInteger("Corruption", this.getCorruption());
        compound.setFloat("Experience", this.getExperience());
    }

    public NBTBase writeData()
    {
        NBTTagCompound tag = new NBTTagCompound();
        tag.setInteger("Level", level);
        tag.setInteger("Corruption", levelCorruption);
        tag.setFloat("Experience", experience);
        return tag;
    }

    public void readData(NBTBase nbt)
    {
        NBTTagCompound tag = (NBTTagCompound) nbt;
        this.setLevel(tag.getInteger("Level"));
        this.setCorruption(tag.getInteger("Corruption"));
        this.setExpereince(tag.getFloat("Experience"));
    }

    public int getLevels() {
        return level;
    }

    public int getCorruption() {
        return levelCorruption;
    }

    public float getExperience() { return experience; }

    public int setLevel(int levelToSet) {
        return this.level = levelToSet;
    }

    public int setCorruption(int corruptionToSet) {
        return this.levelCorruption = corruptionToSet;
    }

    public float setExpereince(float experienceToSet) { return this.experience = experienceToSet; }

    public void sendPacket() {
        if(entity instanceof EntityPlayerMP && entity != null) {
            PlentifulMisc.network.sendTo(new LevelNetworkSyncClient(this.getLevels()),  (EntityPlayerMP) entity);
            PlentifulMisc.network.sendTo(new CorruptionNetworkSyncClient(this.getCorruption()), (EntityPlayerMP) entity);
            PlentifulMisc.network.sendTo(new ExperienceNetworkSyncClient(this.getExperience()), (EntityPlayerMP) entity);
        }
    }
}

 

I'm thinking that its because I'm using 3 different networks for 3 different values, maybe I can store it into one? Last time I did that, I get an error... here is how I'm registering them:

        network.registerMessage(LevelClientNetworkHandler.class, LevelNetworkSyncClient.class, 1, Side.CLIENT);
        network.registerMessage(CorruptionClientNetworkHandler.class, CorruptionNetworkSyncClient.class, 2, Side.CLIENT);
        network.registerMessage(ExperienceClientNetworkHandler.class, ExperienceNetworkSyncClient.class, 3, Side.CLIENT);

,

 

then how I'm modifying the cap:

    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand itemStackIn)
    {
        if(!worldIn.isRemote) {
            if (playerIn.hasCapability(CapabilityLevel.LEVEL, null)) {
                CapabilityLevelData cap = playerIn.getCapability(CapabilityLevel.LEVEL, null);
                cap.addExperienceInternal(200);
                if(playerIn.isSneaking()) {
                    cap.removeLevelsInternal(10);
                }
               return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(itemStackIn));
            }
        }
        return new ActionResult(EnumActionResult.PASS, playerIn.getHeldItem(itemStackIn));
    }
}

 

Thanks for your time,

 

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

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.