Posted July 19, 20196 yr So basically I want to create an entity that has a custom value in his NBT (the custom value is a string). But I have no idea of how to write a new value or how to read it ! Can someone help me please ? ย My code so far with my entity Spoiler package fr.uiytt.playershop.Entity; import java.util.List; import java.util.UUID; import fr.uiytt.playershop.Main; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAISwimming; import net.minecraft.entity.ai.EntityAIWatchClosest; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.SoundEvents; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentString; import net.minecraft.world.World; public class PlayerShop extends EntityCreature { private boolean shopopen = false; public PlayerShop(World worldIn) { super(worldIn); setupAI(); } @Override public float getBlockPathWeight(BlockPos pos) { return 0.1F; } @Override protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.5D); this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(1.0D); this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(16.0D); } @Override public boolean isAIDisabled() { return false; } protected void setupAI() { clearAITasks(); this.tasks.addTask(0,new EntityAISwimming(this)); this.tasks.addTask(1,new EntityAIShopWander(this)); this.tasks.addTask(2,new EntityAIWatchClosest(this, EntityPlayer.class, 10.0F)); } protected void clearAITasks() { this.tasks.taskEntries.clear(); this.targetTasks.taskEntries.clear(); } @Override public boolean attackEntityFrom(DamageSource dmsource, float dmg) { if(this.getIsInvulnerable()) { return false; } if(!(dmsource.getTrueSource() instanceof EntityPlayer)) { return false; }else { EntityPlayer player = (EntityPlayer)dmsource.getTrueSource(); if(player.capabilities.isCreativeMode) { this.damageEntity(dmsource, dmg); this.playHurtSound(dmsource); this.performHurtAnimation(); return true; } } return false; } protected SoundEvent getHurtSound(DamageSource damageSourceIn) { return SoundEvents.ENTITY_VILLAGER_HURT; } protected SoundEvent getDeathSound() { return SoundEvents.ENTITY_VILLAGER_DEATH; } public boolean isShopopen() { return shopopen; } public void setShopopen(boolean shopopen) { this.shopopen = shopopen; } } ย ย Edited July 19, 20196 yr by uiytt
July 19, 20196 yr Author After looking through the code of some mods : https://github.com/Vazkii/Botania/blob/master/src/main/java/vazkii/botania/common/entity/EntityPixie.java#L71 You must use dataManager for the entity that are load And when is entity is loaded / de-loaded it call automatically the "writeEntityToNBT" and "readEntityFromNBT", and with that you can set data in the dataManager
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.