Jump to content

[1.12.2] Custom Entity works fine with /summon but not with customItem


uiytt

Recommended Posts

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

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 by uiytt
Forgot to add a code
Link to comment
Share on other sites

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();

 

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

    • " BLACK MAGIC INSTANT DEATH SPELL CASTER IN UGANDA, NETHERLANDS, SPAIN, KENYA, RWANDA POWERFUL WITCHCRAFT REVENGE SPELLS CASTER IN GHANA, BENIN. STRONG LOVE SPELLS CASTER IN MAURITIUS, MALTA. VOODOO DOLL SPELLS IN USA, UK,spell casters spell to make someone sick and die without delay. Germany, Asian, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. Sweden, Australia, Nigeria, Spain, Ghana, California, Greece , Voodoo revenge spell casters spell to make someone sick and die without delay. Drmama Bonne +256751735278
    • SPELL CASTER, DEATH SPELL, SPELL CASTER REVIEW, WITCHCRAFT, PSYCHIC, MAGIC FORUM,spell casters spell to make someone sick and die without delay. Germany, Asian, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. Sweden, Australia, Nigeria, Spain, Ghana, California, Greece , Voodoo revenge spell casters spell to make someone sick and die without delay. Drmama Bonne +256751735278
    • BLACK MAGIC INSTANT DEATH SPELL CASTER AND POWERFUL+256751735278 BLACK MAGIC INSTANT DEATH SPELL CASTER AND POWERFUL REVENGE SPELLS THAT WORK FAST IN AUSTRALIA, CANADA, UK GERMANY FRANCE DENMARK. +256751735278 Drmama Bonnei , black magic Revenge spells that work overnight or by accident i? Cast these strongest black magic revenge death spells that work fast overnight to kill ex lover, husband, wife girlfriend Enemies overnight without delay. It doesn’t matter whether he or she is in a far location, I guarantee you to have your results you are looking for immediately. Just make sure before you contact me you are committed and you want what you are looking for (Victim Death) because my Revenge spell work fast overnight after casting the spells. Immediately working black magic death spells that work fast will be cast on the person and result is 48hours,24 Hours . How To Cast A Revenge Spell On Someone, Call/ Whats App  Drmama Bonne Revenge Spells That Work Overnight to kill wicked Step-dad/ Step mom Death Revenge Spell on wicked friends, Voodoo Revenge Spells to kill Enemies Black Magic Spells To Harm Someone, Black magic Revenge spells on ex lover Revenge instant Revenge spells on uncle , powerful instant Revenge spells caster, online instant spell that work fast in USA, UK, Kuwait, Germany, Asian, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. Sweden, Australia, Nigeria, Spain, Ghana, California, Greece , Voodoo revenge spell casters spell to make someone sick and die without delay. Germany, Asian, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. Sweden, Australia, Nigeria, Spain, Ghana, California, Greece , Voodoo revenge spell casters spell to make someone sick and die without delay. Drmama Bonne +256751735278
    • Voodoo Spells Caster /SANGOMA / Death & Revenge Spells  +256751735278 Drmama Bonnei , black magic Revenge spells that work overnight or by accident i? Cast these strongest black magic revenge death spells that work fast overnight to kill ex lover, husband, wife girlfriend Enemies overnight without delay. It doesn’t matter whether he or she is in a far location, I guarantee you to have your results you are looking for immediately. Just make sure before you contact me you are committed and you want what you are looking for (Victim Death) because my Revenge spell work fast overnight after casting the spells. Immediately working black magic death spells that work fast will be cast on the person and result is 48hours,24 Hours . How To Cast A Revenge Spell On Someone, Call/ Whats App  Drmama Bonne Revenge Spells That Work Overnight to kill wicked Step-dad/ Step mom Death Revenge Spell on wicked friends, Voodoo Revenge Spells to kill Enemies Black Magic Spells To Harm Someone, Black magic Revenge spells on ex lover Revenge instant Revenge spells on uncle , powerful instant Revenge spells caster, online instant spell that work fast in USA, UK, Kuwait, Germany, Asian, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. Sweden, Australia, Nigeria, Spain, Ghana, California, Greece , Voodoo revenge spell casters spell to make someone sick and die without delay. Germany, Asian, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. Sweden, Australia, Nigeria, Spain, Ghana, California, Greece , Voodoo revenge spell casters spell to make someone sick and die without delay. Drmama Bonne +256751735278
  • Topics

×
×
  • Create New...

Important Information

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