Java Code Examples for net.minecraft.entity.Entity#getEntityId()

The following examples show how to use net.minecraft.entity.Entity#getEntityId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Protocol_1_10.java    From multiconnect with MIT License 6 votes vote down vote up
private static Entity changeEntityType(Entity entity, EntityType<?> newType) {
    ClientWorld world = (ClientWorld) entity.world;
    Entity destEntity = newType.create(world);
    if (destEntity == null) {
        return entity;
    }

    // copy the entity
    destEntity.fromTag(entity.toTag(new CompoundTag()));
    destEntity.trackedX = entity.trackedX;
    destEntity.trackedY = entity.trackedY;
    destEntity.trackedZ = entity.trackedZ;

    // replace entity in world and exchange entity id
    int entityId = entity.getEntityId();
    world.removeEntity(entityId);
    destEntity.setEntityId(entityId);
    world.addEntity(entityId, destEntity);

    // exchange data tracker (this may be part of a series of data tracker updates, need the same data tracker instance)
    DataTrackerManager.transferDataTracker(entity, destEntity);
    return destEntity;
}
 
Example 2
Source File: FMLPlayMessages.java    From patchwork-api with GNU Lesser General Public License v2.1 6 votes vote down vote up
public SpawnEntity(Entity entity) {
	this.entity = entity;

	this.typeId = Registry.ENTITY_TYPE.getRawId(entity.getType());
	this.entityId = entity.getEntityId();
	this.uuid = entity.getUuid();
	this.posX = entity.x;
	this.posY = entity.y;
	this.posZ = entity.z;
	this.pitch = (byte) MathHelper.floor(entity.pitch * 256.0F / 360.0F);
	this.yaw = (byte) MathHelper.floor(entity.yaw * 256.0F / 360.0F);
	this.headYaw = (byte) (entity.getHeadYaw() * 256.0F / 360.0F);

	Vec3d velocity = entity.getVelocity();
	double clampedVelX = MathHelper.clamp(velocity.x, -3.9D, 3.9D);
	double clampedVelY = MathHelper.clamp(velocity.y, -3.9D, 3.9D);
	double clampedVelZ = MathHelper.clamp(velocity.z, -3.9D, 3.9D);
	this.velX = (int) (clampedVelX * 8000.0D);
	this.velY = (int) (clampedVelY * 8000.0D);
	this.velZ = (int) (clampedVelZ * 8000.0D);

	this.buf = null;
}
 
Example 3
Source File: Debug.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
public static int[] getMop() {
    MovingObjectPosition preMop = Wrapper.INSTANCE.mc().objectMouseOver;
    Entity ent = Wrapper.INSTANCE.mc().pointedEntity;
    int[] arrn = new int[5];
    arrn[0] = preMop.blockX;
    arrn[1] = preMop.blockY;
    arrn[2] = preMop.blockZ;
    arrn[3] = preMop.sideHit;
    arrn[4] = ent != null ? ent.getEntityId() : 0;
    int[] mop = arrn;
    return mop;
}
 
Example 4
Source File: VanishTracker.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean isVanished(Entity entity) {
	int id = entity.getEntityId();
	for (VanishedObject v : vanishes) {
		if (v.entityID == id) return true;
	}
	return false;
}
 
Example 5
Source File: TransformationHelper.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static EntityGolemBase findGolem(int entityId) {
    List<Entity> loaded = Minecraft.getMinecraft().thePlayer.worldObj.getLoadedEntityList();
    for(int i = 0; i < loaded.size(); i++) {
        Entity entity = loaded.get(i);
        if(entity instanceof EntityGolemBase && entity.getEntityId() == entityId) {
            return (EntityGolemBase) entity;
        }
    }
    return null;
}
 
Example 6
Source File: EntityTrackHandler.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addInfo(Entity entity, List<String> curInfo){
    curInfo.add("Owner: " + ((EntityDrone)entity).playerName);
    curInfo.add("Routine: " + ((EntityDrone)entity).getLabel());
    if(DroneDebugUpgradeHandler.enabledForPlayer(PneumaticCraft.proxy.getPlayer()) && NBTUtil.getInteger(PneumaticCraft.proxy.getPlayer().getCurrentArmor(3), NBTKeys.PNEUMATIC_HELMET_DEBUGGING_DRONE) != entity.getEntityId()) {
        curInfo.add(EnumChatFormatting.RED + "Press '" + Keyboard.getKeyName(KeyHandler.getInstance().keybindDebuggingDrone.getKeyCode()) + "' to debug");
    }
}
 
Example 7
Source File: SquashEntityMessage.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SquashEntityMessage(Entity entity, EnumFacing.Axis axis) {
    this.entityId = entity.getEntityId();
    this.axis = axis;
}
 
Example 8
Source File: Debug.java    From ehacks-pro with GNU General Public License v3.0 4 votes vote down vote up
public static int getEntityId(Entity entity) {
    return entity.getEntityId();
}
 
Example 9
Source File: EntityUtils.java    From ForgeHax with MIT License 4 votes vote down vote up
public static boolean isFakeLocalPlayer(Entity entity) {
  return entity != null && entity.getEntityId() == -100;
}
 
Example 10
Source File: ItemBrainUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@SubscribeEvent(priority=EventPriority.HIGHEST)
public void handleHurt(LivingAttackEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	
	if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(this, 1, 4)) && isMatrixWorking(e))
	{

		if (!e.worldObj.isRemote && event.getSource() instanceof EntityDamageSource)
		{
			Entity attacker = ((EntityDamageSource) event.getSource()).getSourceOfDamage();
			if (e instanceof EntityPlayer)
			{
				String str = e.getEntityId() + " " + e.ticksExisted + " " + attacker.getEntityId();
				if (lastHits.contains(str))
				{
					return;
				}
				else
				{
					lastHits.add(str);
				}
			}
			
			boolean armor = false;
			for (ItemStack stack : e.getArmorInventoryList())
			{
				if (stack != null && stack.getItem() instanceof ItemArmor)
				{
					if (((ItemArmor) stack.getItem()).getArmorMaterial().getDamageReductionAmount(EntityEquipmentSlot.CHEST) > 4)
					{
						return;
					}
				}
				else if (stack != null && stack.getItem() instanceof ISpecialArmor)
				{
					if (((ISpecialArmor) stack.getItem()).getProperties(e, stack, event.getSource(), event.getAmount(), 1).AbsorbRatio * 25D > 4)
					{
						return;
					}
				}
				
				if (stack != null)
				{
					armor = true;
				}
				
			}
			

			if (!((float) e.hurtResistantTime > (float) e.maxHurtResistantTime / 2.0F))
               {
				Random random = e.getRNG();
				if (random.nextFloat() < (armor ? LibConstants.DODGE_ARMOR : LibConstants.DODGE_NO_ARMOR))
				{
					event.setCanceled(true);
					e.hurtResistantTime = e.maxHurtResistantTime;
					e.hurtTime = e.maxHurtTime = 10;
					ReflectionHelper.setPrivateValue(EntityLivingBase.class, e, 9999F, 46);
					
					CyberwarePacketHandler.INSTANCE.sendToAllAround(new DodgePacket(e.getEntityId()), new TargetPoint(e.worldObj.provider.getDimension(), e.posX, e.posY, e.posZ, 50));
				}
			}
		}
	}
}
 
Example 11
Source File: ClientStateMachine.java    From malmo with MIT License 4 votes vote down vote up
@Override
public void onMessage(MalmoMessageType messageType, Map<String, String> data)
{
    super.onMessage(messageType, data);
    // This message will be sent to us once the server has decided the mission is over.
    if (messageType == MalmoMessageType.SERVER_STOPAGENTS)
    {
        this.quitCode = data.containsKey("QuitCode") ? data.get("QuitCode") : "";
        try
        {
            // Save the quit code for anything that needs it:
            MalmoMod.getPropertiesForCurrentThread().put("QuitCode", this.quitCode);
        }
        catch (Exception e)
        {
            System.out.println("Failed to get properties - final reward may go missing.");
        }
        // Get the final reward data:
        ClientAgentConnection cac = currentMissionInit().getClientAgentConnection();
        if (currentMissionBehaviour() != null && currentMissionBehaviour().rewardProducer != null && cac != null)
            currentMissionBehaviour().rewardProducer.getReward(currentMissionInit(), ClientStateMachine.this.finalReward);

        onMissionEnded(ClientState.MISSION_ENDED, null);
    }
    else if (messageType == MalmoMessageType.SERVER_GO)
    {
        // First, force all entities to get re-added to their chunks, clearing out any old entities in the process.
        // We need to do this because the process of teleporting all agents to their start positions, combined
        // with setting them to/from spectator mode, leaves the client chunk entity lists etc in a parlous state.
        List lel = Minecraft.getMinecraft().world.loadedEntityList;
        for (int i = 0; i < lel.size(); i++)
        {
            Entity entity = (Entity)lel.get(i);
            Chunk chunk = Minecraft.getMinecraft().world.getChunkFromChunkCoords(entity.chunkCoordX, entity.chunkCoordZ);
            List<Entity> entitiesToRemove = new ArrayList<Entity>();
            for (int k = 0; k < chunk.getEntityLists().length; k++)
            {
                Iterator iterator = chunk.getEntityLists()[k].iterator();
                while (iterator.hasNext())
                {
                    Entity chunkent = (Entity)iterator.next();
                    if (chunkent.getEntityId() == entity.getEntityId())
                    {
                        entitiesToRemove.add(chunkent);
                    }
                }
            }
            for (Entity removeEnt : entitiesToRemove)
            {
                chunk.removeEntity(removeEnt);
            }
            entity.addedToChunk = false;    // Will force it to get re-added to the chunk list.
            if (entity instanceof EntityLivingBase)
            {
                // If we want the entities to be rendered with the correct yaw from the outset,
                // we need to set their render offset manually.
                // (Set the offset from the outset to avoid the onset of upset.)
                ((EntityLivingBase)entity).renderYawOffset = entity.rotationYaw;
                ((EntityLivingBase)entity).prevRenderYawOffset = entity.rotationYaw;
            }
            if (entity instanceof EntityPlayerSP)
            {
                // Although the following call takes place on the server, and should have taken effect already,
                // there is some discontinuity which is causing the effects to get lost, so we call it here too:
                entity.setInvisible(false);
            }
        }
        this.serverHasFiredStartingPistol = true; // GO GO GO!
    }
}
 
Example 12
Source File: FxLaser.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public void renderParticle(BufferBuilder worldRendererIn, Entity entityIn,
		float partialTicks, float rotationX, float rotationZ,
		float rotationYZ, float rotationXY, float rotationXZ) {
	//worldRendererIn.finishDrawing();
	
	float x = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)partialTicks - interpPosX);
	float y = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)partialTicks - interpPosY);
	float z = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)partialTicks - interpPosZ);
	
	int i = this.getBrightnessForRender(0);
	int j = i >> 16 & 65535;
	int k = i & 65535;
	
	double radius = .3f;
	double fwdOffset = 0.075f;
	double entityOffX = entityFrom.posX - MathHelper.cos((float) (entityFrom.rotationYaw * Math.PI/180f))*radius + fwdOffset*MathHelper.sin((float) (entityFrom.rotationYaw * Math.PI/180f));
	double entityOffY = entityFrom.posY + (entityFrom.getEntityId() == entityIn.getEntityId() && Minecraft.getMinecraft().gameSettings.thirdPersonView == 0 ? entityIn.getEyeHeight() - 0.12f : 1.15f);
	double entityOffZ = entityFrom.posZ - MathHelper.sin((float) (entityFrom.rotationYaw * Math.PI/180f))*radius - fwdOffset*MathHelper.cos((float) (entityFrom.rotationYaw * Math.PI/180f));
	
	
	GL11.glDisable(GL11.GL_LIGHTING);
	GL11.glEnable(GL11.GL_BLEND);
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE, 0, 0);
	OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
	
	BufferBuilder buffer = Tessellator.getInstance().getBuffer();
	buffer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION);
	GL11.glLineWidth(5);
	GlStateManager.color(0.8f, 0.2f, 0.2f, .4f);
	
	buffer.pos(entityOffX - entityIn.posX, entityOffY - entityIn.posY, entityOffZ - entityIn.posZ).endVertex();
	buffer.pos(x, y, z).endVertex();
	
	
	Tessellator.getInstance().draw();
	
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_LIGHTING);
	OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 0, 0);
	GlStateManager.color(1, 1, 1, 1);
	GL11.glLineWidth(1);
}
 
Example 13
Source File: PacketSpawnRing.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public PacketSpawnRing(double x, double y, double z, Entity targetEntity, int... colors){
    super(x, y, z);
    targetEntityId = targetEntity.getEntityId();
    this.colors = colors;
}
 
Example 14
Source File: PacketHackingEntityFinish.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public PacketHackingEntityFinish(Entity entity){
    entityId = entity.getEntityId();
}
 
Example 15
Source File: PacketSetEntityMotion.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public PacketSetEntityMotion(Entity entity, double dx, double dy, double dz){
    super(dx, dy, dz);
    entityId = entity.getEntityId();
}
 
Example 16
Source File: PacketHackingEntityStart.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public PacketHackingEntityStart(Entity entity){
    entityId = entity.getEntityId();
}