Jump to content

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


Recommended Posts

Posted (edited)

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
Posted

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.

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

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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