Java Code Examples for net.minecraft.entity.Entity

The following examples show how to use net.minecraft.entity.Entity. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Override
protected Entity findPlayerToAttack()
{
    if (getHasCaughtPrey()) { return null; }

    if (worldObj.difficultySetting > 0)// && getIsAdult())
    {
        double attackD = 12D;
         
        if (getIsResting())
        {
        	attackD = 6D;
        }
        
        EntityPlayer entityplayer = worldObj.getClosestPlayerToEntity(this, attackD); 
        if((entityplayer != null) && getIsAdult()) 
        { 
        	 return entityplayer; 
        }
        
        EntityLiving entityliving = getClosestEntityLiving(this, attackD);
        return entityliving;
    }
    return null;
}
 
Example 2
Source Project: ToroQuest   Source File: EntityVillageLord.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void dropRepTo(Entity entity) {
	if (entity == null) {
		return;
	}

	if (!(entity instanceof EntityPlayer)) {
		return;
	}

	EntityPlayer player = (EntityPlayer) entity;

	CivilizationType civ = getCivilization();
	if (civ == null) {
		return;
	}

	PlayerCivilizationCapabilityImpl.get(player).adjustReputation(civ, -5);
}
 
Example 3
@SuppressWarnings("UnresolvedMixinReference")
@Inject(
    method = "method_13238",
    at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/PlayerManager;broadcastChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V",
        ordinal = 0
    ),
    locals = LocalCapture.CAPTURE_FAILSOFT
)
private static void onCommand(CommandContext<ServerCommandSource> context, CallbackInfoReturnable<Integer> cir, TranslatableText translatableText, Entity entity) {
    if (!(entity instanceof ServerPlayerEntity)) return;

    Main main = Main.Companion.getMain();
    ServerPlayerEntity player = (ServerPlayerEntity) entity;

    if (main == null || !main.getEventManager().emit(new PlayerChatEvent(player, translatableText)).getCancel()) {
        player.server.getPlayerManager().broadcastChatMessage(translatableText, MessageType.CHAT, entity.getUuid());
    } else {
        cir.setReturnValue(0);
        cir.cancel();
        player.server.sendSystemMessage(translatableText.append(" (Canceled)"), entity.getUuid());
    }
}
 
Example 4
@Override
protected void attackEntity(Entity entity, float f)
{

    /*if (attackTime <= 0 && (f < 3.0D) && (entity.boundingBox.maxY > boundingBox.minY) && (entity.boundingBox.minY < boundingBox.maxY))
    {
            
    }*/

    if (this.attackTime <= 0 && f < 2.0F && entity.boundingBox.maxY > this.boundingBox.minY && entity.boundingBox.minY < this.boundingBox.maxY)
    {
        this.attackTime = 20;
        openMouth();
        flapWings();
        entity.attackEntityFrom(DamageSource.causeMobDamage(this), 3);
        //this.attackEntityAsMob(par1Entity);
    }

}
 
Example 5
@SubscribeEvent
public void worldTick(TickEvent.WorldTickEvent event){
    if(event.phase == TickEvent.Phase.END) {
        try {
            for(Entity entity : (List<Entity>)event.world.loadedEntityList) {
                HackingEntityProperties hackingProps = (HackingEntityProperties)entity.getExtendedProperties("PneumaticCraftHacking");
                if(hackingProps != null) {
                    hackingProps.update(entity);
                } else {
                    Log.warning("Extended entity props HackingEntityProperties couldn't be found in the entity " + entity.getCommandSenderName());
                }
            }
        } catch(Throwable e) {
            //Catching a CME which I have no clue on what might cause it.
        }
    }
}
 
Example 6
Source Project: Thermos   Source File: CraftEventFactory.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions) {
    EntityDamageEvent event;
    if (damager != null) {
        event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
    } else {
        event = new EntityDamageEvent(damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
    }

    callEvent(event);

    if (!event.isCancelled()) {
        event.getEntity().setLastDamageCause(event);
    }

    return event;
}
 
Example 7
Source Project: Thermos   Source File: CraftEventFactory.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static boolean handleNonLivingEntityDamageEvent(Entity entity, DamageSource source, double damage) {
    if (entity instanceof EntityEnderCrystal && !(source instanceof EntityDamageSource)) {
        return false;
    }

    final EnumMap<DamageModifier, Double> modifiers = new EnumMap<DamageModifier, Double>(DamageModifier.class);
    final EnumMap<DamageModifier, Function<? super Double, Double>> functions = new EnumMap(DamageModifier.class);

    modifiers.put(DamageModifier.BASE, damage);
    functions.put(DamageModifier.BASE, ZERO);

    final EntityDamageEvent event = handleEntityDamageEvent(entity, source, modifiers, functions);
    if (event == null) {
        return false;
    }
    return event.isCancelled() || (event.getDamage() == 0 && !(entity instanceof EntityItemFrame)); // Cauldron - fix frame removal
}
 
Example 8
Source Project: the-hallow   Source File: BloodBlock.java    License: MIT License 6 votes vote down vote up
@Override
public void onEntityCollision(BlockState blockState, World world, BlockPos pos, Entity entity) {
	if(!world.isClient) {
		if (pos.equals(entity.getBlockPos())) {
			if (entity instanceof ItemEntity && !((ItemEntity) entity).getStack().isEmpty()) {
				ItemEntity itemEntity = (ItemEntity) entity;
				ItemStack stack = itemEntity.getStack();
				if (stack.getItem() instanceof DyeableItem) {
					DyeableItem item = (DyeableItem) stack.getItem();
					if (item.hasColor(stack)) item.setColor(stack, 0xFF0000 | item.getColor(stack));
					else item.setColor(stack, 0xFF0000);

					return;
				}
			}
		}
	}

	super.onEntityCollision(blockState, world, pos, entity);
}
 
Example 9
public static void transferEntityToDimension(Entity ent, int dim, ServerConfigurationManager manager, Environment environ) {

		if (ent instanceof EntityPlayerMP) {
			transferPlayerToDimension((EntityPlayerMP) ent, dim, manager, environ);
			return;
		}
		WorldServer worldserver = manager.getServerInstance().worldServerForDimension(ent.dimension);
		ent.dimension = dim;
		WorldServer worldserver1 = manager.getServerInstance().worldServerForDimension(ent.dimension);
		worldserver.removePlayerEntityDangerously(ent);
		if (ent.riddenByEntity != null) {
			ent.riddenByEntity.mountEntity(null);
		}
		if (ent.ridingEntity != null) {
			ent.mountEntity(null);
		}
		ent.isDead = false;
		transferEntityToWorld(ent, worldserver, worldserver1);
	}
 
Example 10
Source Project: HexxitGear   Source File: ItemThiefArmor.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getArmorTexture(ItemStack stack, Entity entity, int slot,
                              int layer) {
    if (entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entity;
        if (player.isPotionActive(Potion.invisibility))
            return "/textures/armor/invisible.png";
    }

    // If the helmet slot, return helmet texture map
    if (slot == 0)
        return "/textures/maps/HoodHelmet.png";

    if (stack.itemID == HexxitGear.thiefLeggings.itemID)
        return "/textures/armor/thief2.png";

    return "/textures/armor/thief.png";
}
 
Example 11
/**
 * This method must be overrided to work in conjunction with our
 * onLivingUpdate update packets. It is currently used to fix mount bug when
 * players reconnect.
 */
@Override
public void mountEntity(Entity par1Entity)
{
	if (updateMount())
	{
		if (par1Entity == null)
		{
			if (this.ridingEntity != null)
			{
				this.setLocationAndAngles(this.ridingEntity.posX, this.ridingEntity.boundingBox.minY + (double) this.ridingEntity.height, this.ridingEntity.posZ, this.rotationYaw, this.rotationPitch);
				this.ridingEntity.riddenByEntity = null;
			}
			this.ridingEntity = null;
		}
		else
		{
			this.ridingEntity = par1Entity;
			par1Entity.riddenByEntity = this;
		}
	}
	else
	{
		super.mountEntity(par1Entity);
	}
}
 
Example 12
Source Project: mocreaturesdev   Source File: MoCModelMouse.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
{
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5);
    Head.render(f5);
    EarR.render(f5);
    EarL.render(f5);
    WhiskerR.render(f5);
    WhiskerL.render(f5);
    Tail.render(f5);
    FrontL.render(f5);
    FrontR.render(f5);
    RearL.render(f5);
    RearR.render(f5);
    BodyF.render(f5);
}
 
Example 13
@Override
public void onDeath(DamageSource damagesource)
{
    Entity entity = damagesource.getEntity();
    if ((scoreValue > 0) && (entity != null))
    {
        entity.addToPlayerScore(this, scoreValue);
    }
    if (entity != null)
    {
        entity.onKillEntity(this);
    }
    //unused_flag = true;
    if (!worldObj.isRemote)
    {
        for (int i = 0; i < 2; i++)
        {
            int j = getDropItemId();
            if (j > 0)
            {
                dropItem(j, 1);
            }
        }

    }
}
 
Example 14
public boolean changeSelection(World world, Entity entity, int maxDistance)
{
    AreaSelection area = this.getCurrentSelection();

    if (area != null)
    {
        RayTraceWrapper trace = RayTraceUtils.getWrappedRayTraceFromEntity(world, entity, maxDistance);

        if (trace.getHitType() == HitType.SELECTION_BOX_CORNER || trace.getHitType() == HitType.SELECTION_BOX_BODY || trace.getHitType() == HitType.SELECTION_ORIGIN)
        {
            this.changeSelection(area, trace);
            return true;
        }
        else if (trace.getHitType() == HitType.MISS)
        {
            area.clearCurrentSelectedCorner();
            area.setSelectedSubRegionBox(null);
            area.setOriginSelected(false);
            return true;
        }
    }

    return false;
}
 
Example 15
Source Project: ForgeHax   Source File: Aimbot.java    License: MIT License 5 votes vote down vote up
private boolean isFiltered(Entity entity) {
  switch (EntityUtils.getRelationship(entity)) {
    case PLAYER:
      return target_players.get();
    case FRIENDLY:
    case NEUTRAL:
      return target_mobs_friendly.get();
    case HOSTILE:
      return target_mobs_hostile.get();
    case INVALID:
    default:
      return false;
  }
}
 
Example 16
@Nullable
@Override
public Class<? extends Entity> getEntityClass()
{
    if (entityClass == null)
    {
        entityClass = EntityList.getClass(mobName);
    }

    return entityClass;
}
 
Example 17
Source Project: Cyberware   Source File: ItemCyberlimb.java    License: MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleSound(PlaySoundAtEntityEvent event)
{
	Entity e = event.getEntity();
	if (e instanceof EntityPlayer && event.getSound() == SoundEvents.ENTITY_PLAYER_HURT && e.worldObj.isRemote)
	{
		if (didFall.contains(e.getEntityId()))
		{
			int numLegs = 0;
			
			if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(this, 1, 2)))
			{
				numLegs++;
			}
			
			if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(this, 1, 3)))
			{
				numLegs++;
			}
			
			if (numLegs > 0)
			{	
				event.setSound(SoundEvents.ENTITY_IRONGOLEM_HURT);
				event.setPitch(event.getPitch() + 1F);
				didFall.remove((Integer) e.getEntityId());
			}
		}
	}	
}
 
Example 18
Source Project: Hyperium   Source File: MixinWorld.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @author asbyth
 * @reason Post event
 */
@Overwrite
public void loadEntities(Collection<Entity> entityCollection) {
    for (Entity entity : entityCollection) {
        EntityJoinWorldEvent event = new EntityJoinWorldEvent((World) (Object) this, entity);
        EventBus.INSTANCE.post(event);
        if (!event.isCancelled()) {
            loadedEntityList.add(entity);
            onEntityAdded(entity);
        }
    }
}
 
Example 19
protected void getPathOrWalkableBlock(Entity entity, float f)
{
	PathEntity pathentity = worldObj.getPathEntityToEntity(this, entity, 16F, true, false, false, true);
	if ((pathentity == null) && (f > 8F))
	{
		int i = MathHelper.floor_double(entity.posX) - 2;
		int j = MathHelper.floor_double(entity.posZ) - 2;
		int k = MathHelper.floor_double(entity.boundingBox.minY);
		for (int l = 0; l <= 4; l++)
		{
			for (int i1 = 0; i1 <= 4; i1++)
			{
				if (((l < 1) || (i1 < 1) || (l > 3) || (i1 > 3)) && worldObj.isBlockNormalCube(i + l, k - 1, j + i1) && !worldObj.isBlockNormalCube(i + l, k, j + i1) && !worldObj.isBlockNormalCube(i + l, k + 1, j + i1))
				{
					setLocationAndAngles((i + l) + 0.5F, k, (j + i1) + 0.5F, rotationYaw, rotationPitch);
					return;
				}
			}

		}

	}
	else
	{
		setPathToEntity(pathentity);
	}
}
 
Example 20
Source Project: LiquidBounce   Source File: MixinBlock.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * @author CCBlueX
 */
@Overwrite
public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity) {
    AxisAlignedBB axisalignedbb = this.getCollisionBoundingBox(worldIn, pos, state);
    BlockBBEvent blockBBEvent = new BlockBBEvent(pos, blockState.getBlock(), axisalignedbb);
    LiquidBounce.eventManager.callEvent(blockBBEvent);
    axisalignedbb = blockBBEvent.getBoundingBox();
    if(axisalignedbb != null && mask.intersectsWith(axisalignedbb))
        list.add(axisalignedbb);
}
 
Example 21
Source Project: customstuff4   Source File: BlockWall.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean p_185477_7_)
{
    if (!p_185477_7_)
    {
        state = this.getActualState(state, worldIn, pos);
    }

    addCollisionBoxToList(pos, entityBox, collidingBoxes, CLIP_AABB_BY_INDEX[getAABBIndex(state)]);
}
 
Example 22
private ICamera createCamera(Entity entity, float partialTicks)
{
    double x = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double) partialTicks;
    double y = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double) partialTicks;
    double z = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double) partialTicks;

    this.entity = entity;
    this.camera = new Frustum();
    this.camera.setPosition(x, y, z);

    return this.camera;
}
 
Example 23
Source Project: GardenCollection   Source File: ScanResult.java    License: MIT License 5 votes vote down vote up
public ScanResult(byte type, int blockId, int blockMeta, Entity entity,
		String phenomena) {
	super();
	this.type = type;
	this.id = blockId;
	this.meta = blockMeta;		
	this.entity = entity;
	this.phenomena = phenomena;
}
 
Example 24
Source Project: Wurst7   Source File: ItemEspHack.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onUpdate()
{
	items.clear();
	for(Entity entity : MC.world.getEntities())
		if(entity instanceof ItemEntity)
			items.add((ItemEntity)entity);
}
 
Example 25
Source Project: Kettle   Source File: CraftEventFactory.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static ProjectileHitEvent callProjectileHitEvent(Entity entity, RayTraceResult position) {
    Block hitBlock = null;
    if (position.typeOfHit == RayTraceResult.Type.BLOCK) {
        BlockPos blockposition = position.getBlockPos();
        hitBlock = entity.getBukkitEntity().getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
    }

    ProjectileHitEvent event = new ProjectileHitEvent((Projectile) entity.getBukkitEntity(), position.entityHit == null ? null : position.entityHit.getBukkitEntity(), hitBlock);
    entity.world.getServer().getPluginManager().callEvent(event);
    return event;
}
 
Example 26
Source Project: TofuCraftReload   Source File: TofuBlockUtils.java    License: MIT License 5 votes vote down vote up
public static void onFallenUponFragileTofu(World par1World, Entity par5Entity, Block block, float par6,
		BlockUtils.IEntityWeightingBlockHandler handler) {
	if (!par1World.isRemote) {
		if (par6 > 0.5F) {
			if (!(par5Entity instanceof EntityPlayer) && !par1World.getGameRules().getBoolean("mobGriefing"))
				return;
			BlockUtils.handleEntityWeightingBlock(par1World, par5Entity, block, handler);
		}
	}
}
 
Example 27
/**
 * Internal implementation of creating a path from an entity to a point
 */
private PathEntity createEntityPathTo(Entity par1Entity, double par2, double par4, double par6, float par8){
    path.clearPath();
    pointMap.clearMap();
    boolean flag = isPathingInWater;
    int i = MathHelper.floor_double(par1Entity.boundingBox.minY + 0.5D);

    if(canEntityDrown && par1Entity.isInWater()) {
        i = (int)par1Entity.boundingBox.minY;

        for(Block j = worldMap.getBlock(MathHelper.floor_double(par1Entity.posX), i, MathHelper.floor_double(par1Entity.posZ)); j == Blocks.water || j == Blocks.flowing_water; j = worldMap.getBlock(MathHelper.floor_double(par1Entity.posX), i, MathHelper.floor_double(par1Entity.posZ))) {
            ++i;
        }

        flag = isPathingInWater;
        isPathingInWater = false;
    } else {
        i = MathHelper.floor_double(par1Entity.boundingBox.minY + 0.5D);
    }

    PathPoint pathpoint = openPoint(MathHelper.floor_double(par1Entity.boundingBox.minX), i, MathHelper.floor_double(par1Entity.boundingBox.minZ));
    PathPoint pathpoint1 = openPoint(MathHelper.floor_double(par2 - par1Entity.width / 2.0F), MathHelper.floor_double(par4), MathHelper.floor_double(par6 - par1Entity.width / 2.0F));
    PathPoint pathpoint2 = new PathPoint(MathHelper.floor_float(par1Entity.width + 1.0F), MathHelper.floor_float(par1Entity.height + 1.0F), MathHelper.floor_float(par1Entity.width + 1.0F));
    PathEntity pathentity = addToPath(par1Entity, pathpoint, pathpoint1, pathpoint2, par8);
    isPathingInWater = flag;
    return pathentity;
}
 
Example 28
@Override
public void onEntityCollision(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
{
    if (worldIn.isRemote == false)
    {
        if (entityIn instanceof EntityPlayer)
        {
            TickHandler.instance().addPlayerToTeleport((EntityPlayer) entityIn);
        }
        else
        {
            this.teleportEntity(worldIn, pos, state, entityIn);
        }
    }
}
 
Example 29
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
	if (worldIn.isRemote) return;

	try (ManaManager.CapManagerBuilder mgr = ManaManager.forObject(entityIn)) {
		mgr.setMaxMana(ConfigValues.crudeHaloBufferSize);
		mgr.setMaxBurnout(ConfigValues.crudeHaloBufferSize);
		mgr.removeBurnout(mgr.getMaxBurnout() * ConfigValues.haloGenSpeed * 2);
	}
}
 
Example 30
Source Project: Wizardry   Source File: SpellRing.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean taxCaster(@Nonnull World world, SpellData data, double multiplier, boolean failSound) {
	if(data.getData(SpellData.DefaultKeys.CASTER) == null) return true;

	Entity caster = world.getEntityByID(data.getData(SpellData.DefaultKeys.CASTER));

	if(caster == null) {
		Wizardry.LOGGER.warn("Caster was null!");
		return true;
	}

	IManaCapability cap = ManaCapabilityProvider.getCap(caster);
	if (cap == null) return false;

	double manaDrain = getManaDrain(data) * multiplier;
	double burnoutFill = getBurnoutFill(data) * multiplier;

	boolean fail = false;

	try (ManaManager.CapManagerBuilder mgr = ManaManager.forObject(cap)) {
		if (mgr.getMana() < manaDrain) fail = true;

		mgr.removeMana(manaDrain);
		mgr.addBurnout(burnoutFill);
	}

	if (fail && failSound) {

		Vec3d origin = data.getOriginWithFallback(world);
		if (origin != null)
			world.playSound(null, new BlockPos(origin), ModSounds.SPELL_FAIL, SoundCategory.NEUTRAL, 1f, 1f);
	}

	return !fail;
}