Posted July 16, 20196 yr Ok so... I have this entity : Spoiler package fr.uiytt.playershop.Entity; 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.util.DamageSource; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class PlayerShop extends EntityCreature { private boolean shopopen = false; private UUID owner; 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; } if(player.getUUID(player.getGameProfile()) == this.owner) { this.damageEntity(dmsource, dmg); this.playHurtSound(dmsource); this.performHurtAnimation(); return true; } else { Main.modloger.info("PlayerUUID:" + player.getUUID(player.getGameProfile()).toString() + "\n" + "OwnerUUID:"+this.owner+"\n"+player.getUUID(player.getGameProfile())); } } 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; } public UUID getOwner() { return owner; } public void setOwner(UUID owner) { this.owner = owner; } } When I summon my entity with the /summon, everything works fine But when I use my custom Item to summon it, my entity is not affected by gravity, does not make any sound when punched and disappear after 5 to 10 seconds My custom item code : Spoiler package fr.uiytt.playershop.items; import fr.uiytt.playershop.Main; import fr.uiytt.playershop.Entity.PlayerShop; import fr.uiytt.playershop.init.ModItems; import fr.uiytt.playershop.util.IHasModel; import net.minecraft.block.BlockLiquid; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; public class ShopInvoc extends Item implements IHasModel { private String name; public ShopInvoc(String name) { this.setUnlocalizedName(name); this.setRegistryName(name); this.setCreativeTab(Main.modcreativetab); this.name = name; ModItems.ITEM.add(this); } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { Boolean isRemote = worldIn.isRemote; ItemStack itemstack = playerIn.getHeldItem(handIn); if(isRemote) { return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack); } RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true); if (raytraceresult != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) { BlockPos blockpos = raytraceresult.getBlockPos(); if (worldIn.getBlockState(blockpos).getBlock() instanceof BlockLiquid) { return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack); } PlayerShop shopEntity = new PlayerShop(worldIn); shopEntity.setOwner(playerIn.getUUID(playerIn.getGameProfile())); if(shopEntity.getCanSpawnHere()) { shopEntity.posX = blockpos.getX(); shopEntity.posY = blockpos.getY() + 1.0D; shopEntity.posZ = blockpos.getZ(); worldIn.spawnEntity(shopEntity); if (!playerIn.capabilities.isCreativeMode){ itemstack.shrink(1); } return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack); } return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack); } return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack); } @Override public void registerModels() { Main.proxy.registerItemRenderer(this,0,"inventory"); } } I have no idea where it may come from... Can you help me ? Edited July 16, 20196 yr by uiytt Forgot to add a code
July 19, 20196 yr Author Well, I've finally found the answer, you have to use shopEntity.setLocationAndAngles(x, y, z, yaw, pitch); and not : shopEntity.posX = blockpos.getX(); shopEntity.posY = blockpos.getY() + 1.0D; shopEntity.posZ = blockpos.getZ();
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.