Jump to content

[1.7.10] entity takes on properties of another entity (entity id conflict?)


Recommended Posts

Posted

so i have a couple of entities. im going to focus on the two that are interfering. both are projectiles. one of them spawn snow and ice particles every tick, the other one bounces when it hits walls. i have an item that spawns the bouncy projectile, however when it is spawned in the world it, despite bouncing around, keeps spawning ice and snow particles! it's so strange! my guess is that there is a clientside id-conflict where the client thinks that the entity is the snowy one. how do i deal with this? :(

in item class:

public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)
{
	--itemstack.stackSize;

	world.playSoundAtEntity(player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

	EntityTennisBall entityProjectile = new EntityTennisBall(world, player, 0.01F);
	entityProjectile.setEntityItemStack(itemstack);
	if (!world.isRemote)
	{
		world.spawnEntityInWorld(entityProjectile);
	}
	return itemstack;
}

entity registration in main mod class:

	registerEntity(EntitySplicerThuggish.class, "SplicerThuggish", 0x2E2400, 0xEFEFEF);
	registerEntity(EntityBigDaddyBouncer.class, "BigDaddyBouncer", 0x826725, 0x5B5B5B);

	registerEntityNoEgg(EntityElectroBoltProjectile.class, "ElectroBoltProjectile");
	registerEntityNoEgg(EntityElectroBoltWaterElectro.class, "ElectroBoltWaterElectro");
	registerEntityNoEgg(EntityEnrageProjectile.class, "EnrageProjectile");
	registerEntityNoEgg(EntityHypnotizeBigDaddyProjectile.class, "HypnotizeBigDaddyProjectile");
	registerEntityNoEgg(EntityIncinerateFlame.class, "IncinerateFlame");
	registerEntityNoEgg(EntityIncinerateProjectile.class, "IncinerateProjectile");
	registerEntityNoEgg(EntityMurderOfCrowsProjectile.class, "MurderOfCrowsProjectile");
	registerEntityNoEgg(EntityMurderOfCrowsCrow.class, "MurderOfCrowsCrow");
	registerEntityNoEgg(EntityWinterBlastProjectile.class, "OldManWinterProjectile");
	registerEntityNoEgg(EntityReturnToSenderProjectile.class, "ReturnToSenderProjectile");
	registerEntityNoEgg(EntityShockJockeyProjectile.class, "ShockJockeyProjectile");
	registerEntityNoEgg(EntityShockJockeyWaterElectro.class, "ShockJockeyWaterElectro");
	registerEntityNoEgg(EntityWinterBlastProjectile.class, "WinterBlastProjectile");

	registerEntityNoEgg(EntityTennisBall.class, "TennisBall");
	registerEntityNoEgg(EntityGrenadeLauncherShell.class, "GrenadeLauncherShell");
	registerEntityNoEgg(EntityBullet.class, "Bullet");
	registerEntityNoEgg(EntityCrossbowBolt.class, "CrossbowBolt");
	registerEntityNoEgg(EntityElectricTrap.class, "CrossbowBoltElectricTrap");

	registerEntityNoEgg(EntityTargeter.class, "Targeter");

are there too many entities?

entitiy registration functions called from entity registration:

//Register entity
public static void registerEntity(Class entityClass, String name, int primaryColor, int secondaryColor)
{
	int entityID = EntityRegistry.findGlobalUniqueEntityId();

	EntityRegistry.registerGlobalEntityID(entityClass, name, entityID);
	EntityRegistry.registerModEntity(entityClass, name, entityID, instance, 64, 1, true);
	EntityList.entityEggs.put(Integer.valueOf(entityID), new EntityList.EntityEggInfo(entityID, primaryColor, secondaryColor));
	EntityList.entityEggs.get(EntityList.entityEggs.size()-1);

}

//Register entity without egg
public static void registerEntityNoEgg(Class entityClass, String name)
{
	int entityID = EntityRegistry.findGlobalUniqueEntityId();

	EntityRegistry.registerGlobalEntityID(entityClass, name, entityID);
	EntityRegistry.registerModEntity(entityClass, name, entityID, instance, 64, 1, true);
}

tennis ball entity:

package com.sigurd4.Bioshock.entity.projectiles;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

import com.sigurd4.Bioshock.BioshockMod;
import com.sigurd4.Bioshock.items.ItemTennisBall;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class EntityTennisBall extends EntityThrowable
{
public int bounces;

public EntityTennisBall(World world)
{
	super(world);
}

public EntityTennisBall(World world, EntityLivingBase thrower, float f)
{
	super(world, thrower);
	this.bounces = 0;
	this.setSize(1/16*4, 1/16*4);
	this.setLocationAndAngles(thrower.posX, thrower.posY + thrower.getEyeHeight(), thrower.posZ, thrower.rotationYaw, thrower.rotationPitch);
	this.posX -= MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F;
	this.posY -= 0.10000000149011612D;
	this.posZ -= MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F;
	this.setPosition(this.posX, this.posY, this.posZ);
	this.yOffset = 0.0F;
	this.motionX = -MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI) * f;
	this.motionZ = MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI) * f;
	this.motionY = -MathHelper.sin((this.rotationPitch + this.func_70183_g()) / 180.0F * (float)Math.PI) * f;
	this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, this.func_70182_d(), 1.0F);
	this.motionX += hi(0.001);
	this.motionY += hi(0.001);
	this.motionZ += hi(0.001);
}

    /**
     * Sets the velocity to the args. Args: x, y, z
     */
    @Override
public void setVelocity(double p_70016_1_, double p_70016_3_, double p_70016_5_)
    {
        this.motionX = p_70016_1_;
        this.motionY = p_70016_3_;
        this.motionZ = p_70016_5_;

        if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
        {
            float f = MathHelper.sqrt_double(p_70016_1_ * p_70016_1_ + p_70016_5_ * p_70016_5_);
            this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(p_70016_1_, p_70016_5_) * 180.0D / Math.PI);
            this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(p_70016_3_, f) * 180.0D / Math.PI);
        }
    }

@Override
protected void entityInit()
{
	this.getDataWatcher().addObjectByDataType(10, 5);
}

@Override
public void onEntityUpdate()
{
	ItemStack stack = this.getDataWatcher().getWatchableObjectItemStack(10);
	stack.stackSize = 1;
	if(stack != null && stack.getItem() != null)
	{
		EntityItem entityItem = new EntityItem(this.worldObj);
		entityItem.setEntityItemStack(stack);

		entityItem.delayBeforeCanPickup = 20;
		if (stack.getItem().onEntityItemUpdate(entityItem))
		{
			return;
		}
	}
	if (this.getEntityItem() == null)
	{
		this.setDead();
	}
}

/**
 * Called when this EntityThrowable hits a block or entity.
 */
@Override
protected void onImpact(MovingObjectPosition pos)
{
	float f0 = 0.005F;
	float f1 = 0.01F;
	if(!this.worldObj.isRemote && this.ticksExisted > 100 && (this.getDistance(lastTickPosX, lastTickPosY, lastTickPosZ) < f1 || !((this.motionX > f0 || this.motionX < -f0) && (this.motionY > f0 || this.motionY < -f0) && (this.motionZ > f0 || this.motionZ < -f0))) && this.ticksExisted > 10 && !this.isDead)
	{
		this.entityDropItem(this.getEntityItem(), 0);
		this.setDead();
	}

	if(!this.worldObj.isRemote && this.bounces > 500 && !this.isDead)
	{
		this.entityDropItem(this.getEntityItem(), 0);
		this.setDead();
	}
	else
	{
		++this.bounces;
	}
	if(pos.entityHit != null)
	{
		boolean flag = false;
		if(pos.entityHit instanceof EntitySkeleton)
			if(pos.entityHit instanceof EntityPlayer)
			{
				if(((EntityPlayer)pos.entityHit).getHeldItem() == null)
				{
					if(!this.worldObj.isRemote && this.ticksExisted >= 10 && !this.isDead)
					{
						this.entityDropItem(this.getEntityItem(), 0);
						this.setDead();
					}
					flag = true;
				}
				else if(this.ticksExisted < 10)
				{
					flag = true;
				}
			}
		if(!flag)
		{
			pos.entityHit.velocityChanged = false;
			pos.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0);
			pos.entityHit.velocityChanged = false;
			pos.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0);
			pos.entityHit.velocityChanged = false;
			pos.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0);
		}
	}
	float bouncyness = 0.8F;
	float penalty = 0.9F;
	if(this.getEntityItem().stackTagCompound != null && this.getEntityItem().stackTagCompound.hasKey(ItemTennisBall.BOUNCYNESS))
	{
		bouncyness = this.getEntityItem().stackTagCompound.getFloat(ItemTennisBall.BOUNCYNESS);
	}
	if(bouncyness > 1)
	{
		bouncyness = 1;
	}
	if(pos.entityHit == null)
	{
		this.worldObj.scheduleBlockUpdate(pos.blockX, pos.blockY, pos.blockZ, this.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ), 0);
		this.bounceEffects(pos);
		if(pos.sideHit == 0)
		{
			if(this.motionY > 0)
			{ 
				this.motionY *= -bouncyness;
				this.onGround = false;
				this.motionX *= penalty;
				this.motionZ *= penalty;
			}
		}
		else if(pos.sideHit == 1)
		{
			if(this.motionY < 0)
			{
				this.motionY *= -bouncyness;
				this.onGround = false;
				this.motionX *= penalty;
				this.motionZ *= penalty;
			}
		}
		else if(pos.sideHit == 4)
		{
			if(this.motionX > 0)
			{
				this.motionX *= -bouncyness;
				this.onGround = false;
				this.motionY *= penalty;
				this.motionZ *= penalty;
			}
		}
		else if(pos.sideHit == 5)
		{
			if(this.motionX < 0)
			{
				this.motionX *= -bouncyness;
				this.onGround = false;
				this.motionY *= penalty;
				this.motionZ *= penalty;
			}
		}
		else if(pos.sideHit == 3)
		{
			if(this.motionZ < 0)
			{
				this.motionZ *= -bouncyness;
				this.onGround = false;
				this.motionX *= penalty;
				this.motionY *= penalty;
			}
		}
		else if(pos.sideHit == 2)
		{
			if(this.motionZ > 0)
			{
				this.motionZ *= -bouncyness;
				this.onGround = false;
				this.motionX *= penalty;
				this.motionY *= penalty;
			}
		}
		this.motionX += hi(0.003);
		this.motionY += hi(0.003);
		this.motionZ += hi(0.003);
	}
	else
	{
		this.motionX *= ((this.rand.nextFloat()*bouncyness*2)-bouncyness-this.motionX)/2;
		this.motionY *= this.rand.nextFloat()*bouncyness*2;
		this.motionZ *= ((this.rand.nextFloat()*bouncyness*2)-bouncyness-this.motionZ)/2;
		this.motionX *= penalty;
		this.motionZ *= penalty;
		this.onGround = false;
	}
}

public boolean attackEntityAsMob(Entity entity)
{
	if(entity instanceof EntityLivingBase)
	{
		if(((EntityLivingBase)entity).getHeldItem() == null)
		{
			this.entityDropItem(this.getEntityItem(), 0);
			this.setDead();
			return true;
		}
	}
	return true;
}

/**
 * First layer of player interaction
 */
@Override
public boolean interactFirst(EntityPlayer player)
{
	if(player.getHeldItem() == null)
	{
		this.entityDropItem(this.getEntityItem(), 0);
		this.setDead();
		return true;
	}
	return false;
}

/**
 * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge
 * length * 64 * renderDistanceWeight Args: distance
 */
@Override
@SideOnly(Side.CLIENT)
public boolean isInRangeToRenderDist(double p_70112_1_)
{
	double d1 = this.boundingBox.getAverageEdgeLength() * 4.0D;
	d1 *= 64.0D*6;
	return p_70112_1_ < d1 * d1;
}

/**
 * Returns the ItemStack corresponding to the Entity (Note: if no item exists, will log an error but still return an
 * ItemStack containing Block.stone)
 */
public ItemStack getEntityItem()
{
	ItemStack itemstack = this.getDataWatcher().getWatchableObjectItemStack(10);
	return itemstack == null ? new ItemStack(Blocks.stone) : itemstack;
}

/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
@Override
public void writeEntityToNBT(NBTTagCompound compound)
{
	super.writeEntityToNBT(compound);
	compound.setInteger("Bounces", this.bounces);
	if (this.getEntityItem() != null)
	{
		compound.setTag("Item", this.getEntityItem().writeToNBT(new NBTTagCompound()));
	}
}

/**
 * (abstract) Protected helper method to read subclass entity data from NBT.
 */
@Override
public void readEntityFromNBT(NBTTagCompound compound)
{
	super.readEntityFromNBT(compound);
	this.bounces = compound.getInteger("Bounces");
	NBTTagCompound nbttagcompound1 = compound.getCompoundTag("Item");
	this.setEntityItemStack(ItemStack.loadItemStackFromNBT(nbttagcompound1));

	ItemStack item = getDataWatcher().getWatchableObjectItemStack(10);

	if (item == null || item.stackSize <= 0)
	{
		this.setDead();
	}
}

/**
 * Sets the ItemStack for this entity
 */
public void setEntityItemStack(ItemStack p_92058_1_)
{
	this.getDataWatcher().updateObject(10, p_92058_1_);
	this.getDataWatcher().setObjectWatched(10);
}

protected double hi(double input)
{
	return this.rand.nextFloat()*input*2-input;
}

/**
 * Sound and particles.
 */
protected void bounceEffects(MovingObjectPosition pos)
{
	float power = 2.0F;
	power *= Math.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ)-1;
	if(power > 4.0F)
	{
		power = 4.0F;
	}
	if(power < 0)
	{
		power = 0;
	}
	for(int i = (int)(((((this.motionX+this.motionY+this.motionZ)/6+power/1.5)*(power/1.5+0.5F)*5)-this.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ).getBlockHardness(this.worldObj, pos.blockX, pos.blockY, pos.blockZ))/4-this.rand.nextFloat()); i > 0; --i)
	{
		this.worldObj.spawnParticle("blockcrack_" + Block.getIdFromBlock(this.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ)) + "_" + this.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ).getDamageValue(this.worldObj, pos.blockX, pos.blockY, pos.blockZ), this.posX+this.hi((this.motionX+this.motionY+this.motionZ)/12*(power+0.5F)), this.posY+this.hi((this.motionX+this.motionY+this.motionZ)/12*(power+0.5F)), this.posZ+this.hi((this.motionX+this.motionY+this.motionZ)/12*(power+0.5F)), this.hi((this.motionX+this.motionY+this.motionZ)/3*(power+0.5F)), this.hi((this.motionX+this.motionY+this.motionZ)/3*(power+0.5F)), this.hi((this.motionX+this.motionY+this.motionZ)/3*(power+0.5F)));
	}

	String stepSound = this.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ).stepSound.func_150496_b();

	this.worldObj.playSoundAtEntity(this, stepSound, 0.1F+power/8, 2+this.rand.nextFloat()/4);

	Material m = this.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ).getMaterial();

	if(m == Material.glass || Block.getIdFromBlock(this.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ)) == Block.getIdFromBlock(BioshockMod.RaptureGlass))
	{
		this.worldObj.playSoundAtEntity(this, "step.stone", 0.8F+this.rand.nextFloat()/4+power/8, this.rand.nextFloat());
	}
	else if(m == Material.leaves || m == Material.plants || m == Material.vine)
	{
		this.worldObj.playSoundAtEntity(this, "dig.grass", 0.4F+this.rand.nextFloat()/8, 1+this.rand.nextFloat()/4);
	}
}

@Override
@SideOnly(Side.CLIENT)
public float getShadowSize()
{
	return 0.3F;
}

/**
 * Gets the amount of gravity to apply to the thrown entity with each tick.
 */
@Override
protected float getGravityVelocity()
{
	return 0.06F;
}
}

http://www.planetminecraft.com/member/sigurd4

I'm making the bioshock mod!

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



×
×
  • Create New...

Important Information

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