Jump to content

NBT property values being assigned cumutively to joining players


Elijah482

Recommended Posts

I'm basically just trying to assign an NBT tag to each player that tracks how many cobblestone they've broken and assigns an achievement once it hits a certain amount. It seems to work somewhat but only the first player connecting to a world can unlock the achievement - everyone connecting after that has the cumulative value of all the cobblestone broken by previous players assigned to the tag. For example, if player 101 if the first player to join a new world from a test client and digs up 10 blocks, the tag registers perfectly ok and the achievement is triggered - if the client is closed and reopened, player 102 will having the tag assigned to a value of 11 upon breaking the first cobblestone block.

 

Is this because of some weirdness associated with the eclipse test client (I've noticed you start with the same items, but not achievements?) loading the same player data over and over, or is my code just running indiscriminately and assigning NBT tag values regardless of specific player?

 

 

My extendedplayer class that assigns the NBT tags is below

 

package achievementsplus;

 

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.world.World;

import net.minecraftforge.common.IExtendedEntityProperties;

 

public class ExtendedPlayer implements IExtendedEntityProperties {

 

public final static String EXT_PROP_NAME = "Achievements+";

 

private final EntityPlayer player;

 

private int cobblebrokenCount = 0;

private int obsidianbrokenCount = 0;

private int woodbrokenCount = 0;

 

 

 

public ExtendedPlayer(EntityPlayer player)

{

this.player = player;

this.cobblebrokenCount = 0;

this.obsidianbrokenCount = 0;

this.woodbrokenCount = 0;

}

 

public static final void register(EntityPlayer player)

{

player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer(player));

}

 

public static final ExtendedPlayer get(EntityPlayer player)

{

return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME);

}

 

@Override

public void saveNBTData(NBTTagCompound compound)

{

 

NBTTagCompound properties = new NBTTagCompound();

 

properties.setInteger("CobbleBroken", this.cobblebrokenCount);

properties.setInteger("WoodBroken", this.woodbrokenCount);

properties.setInteger("ObsidianBroken", this.obsidianbrokenCount);

 

 

compound.setTag(EXT_PROP_NAME, properties);

}

 

@Override

public void loadNBTData(NBTTagCompound compound)

{

NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);

 

this.cobblebrokenCount = properties.getInteger("CobbleBroken");

this.woodbrokenCount = properties.getInteger("WoodBroken");

this.obsidianbrokenCount = properties.getInteger("ObsidianBroken");

 

 

}

 

@Override

public void init(Entity entity, World world)

{

}

 

//////Block checker methods

public int increasecobbleCount()

{

this.cobblebrokenCount++;

if (this.cobblebrokenCount == 10){return 4;}

if (this.cobblebrokenCount == 9){return 3;}

if (this.cobblebrokenCount == 8){return 2;}

if (this.cobblebrokenCount == 7){return 1;}

System.out.println(cobblebrokenCount);

return 0;

}

 

public int increasewoodCount()

{

this.woodbrokenCount++;

if (this.woodbrokenCount == 4){return 4;}

if (this.woodbrokenCount == 3){return 3;}

if (this.woodbrokenCount == 2){return 2;}

if (this.woodbrokenCount == 1){return 1;}

System.out.println(woodbrokenCount);

return 0;

}

 

public int increaseobsidianCount()

{

this.obsidianbrokenCount++;

if (this.obsidianbrokenCount == 80){return 4;}

if (this.obsidianbrokenCount == 60){return 3;}

if (this.obsidianbrokenCount == 40){return 2;}

if (this.obsidianbrokenCount == 20){return 1;}

System.out.println(obsidianbrokenCount);

return 0;

}

 

 

 

}

 

 

 

and the eventhandler calling it is here

 

package achievementsplus;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;

import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;

import net.minecraftforge.event.world.BlockEvent.BreakEvent;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

 

public class myEventHandler {

 

 

 

@SubscribeEvent

public void onApplePickup(LivingUpdateEvent event)

{

 

if (event.entityLiving instanceof EntityPlayer)

{

 

EntityPlayer player = (EntityPlayer)event.entity;

 

if (player.inventory.hasItem(Items.apple))

{

System.out.println("SCRUB!");

player.addStat(AchievementsList.appleAchieve, 1);

}

 

 

 

 

}

 

}

 

@SubscribeEvent

public void onBlockBreak(BreakEvent event)

{

 

EntityPlayer player = event.getPlayer();

ExtendedPlayer props = ExtendedPlayer.get(player);

 

if (event.block == Blocks.stone && player.capabilities.isCreativeMode == false)

{

int count = props.increasecobbleCount();

 

if(count == 4){player.addStat(AchievementsList.cobbleAchieve4, 4);}

if(count == 3){player.addStat(AchievementsList.cobbleAchieve3, 3);}

if(count == 2){player.addStat(AchievementsList.cobbleAchieve2, 2);}

if(count == 1){player.addStat(AchievementsList.cobbleAchieve1, 1);}

 

}

 

if (event.block == Blocks.obsidian && player.capabilities.isCreativeMode == false)

{

int count = props.increaseobsidianCount();

 

if(count == 4){player.addStat(AchievementsList.obsidianAchieve4, 4);}

if(count == 3){player.addStat(AchievementsList.obsidianAchieve3, 3);}

if(count == 2){player.addStat(AchievementsList.obsidianAchieve2, 2);}

if(count == 1){player.addStat(AchievementsList.obsidianAchieve1, 1);}

 

}

 

if (event.block == Blocks.log && player.capabilities.isCreativeMode == false)

{

int count = props.increasewoodCount();

 

if(count == 4){player.addStat(AchievementsList.woodAchieve4, 4);}

if(count == 3){player.addStat(AchievementsList.woodAchieve3, 3);}

if(count == 2){player.addStat(AchievementsList.woodAchieve2, 2);}

if(count == 1){player.addStat(AchievementsList.woodAchieve1, 1);}

 

}

}

 

@SubscribeEvent

public void onEntityConstructing(EntityConstructing event)

{

if (event.entity instanceof EntityPlayer && ExtendedPlayer.get((EntityPlayer) event.entity) == null)

{

ExtendedPlayer.register((EntityPlayer) event.entity);

}

}

 

 

 

 

}

 

 

Link to comment
Share on other sites

I'm pretty sure that's just the Eclipse test environment - unless you specify a username or full login, it gives you a semi-random username each time you launch the client, but it sounds like it uses the same player data file in the background regardless of user name.

 

As I said, I haven't tested that, but your code looks like it should work fine. If you can, try running the test Server via Eclipse, then connect via both your computer and one other computer via LAN - each player should have their own IEEP data.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
    • Here's the link: https://mclo.gs/7L5FibL Here's the link: https://mclo.gs/7L5FibL
    • Also the mod "Connector Extras" modifies Reach-entity-attributes and can cause fatal errors when combined with ValkrienSkies mod. Disable this mod and continue to use Syntra without it.
    • Hi everyone. I was trying modify the vanilla loot of the "short_grass" block, I would like it drops seeds and vegetal fiber (new item of my mod), but I don't found any guide or tutorial on internet. Somebody can help me?
    • On 1.20.1 use ValkrienSkies mod version 2.3.0 Beta 1. I had the same issues as you and it turns out the newer beta versions have tons of unresolved incompatibilities. If you change the version you will not be required to change the versions of eureka or any other additions unless prompted at startup. This will resolve Reach-entity-attributes error sound related error and cowardly errors.
  • Topics

×
×
  • Create New...

Important Information

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