Java Code Examples for net.minecraft.entity.LivingEntity

The following examples show how to use net.minecraft.entity.LivingEntity. 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 check out the related API usage on the sidebar.
Example 1
@Override
public void onCommand(String command, String[] args) throws Exception {
    if (mc.player.getVehicle() != null) {
        if     (mc.player.getVehicle() instanceof HorseEntity ||
                mc.player.getVehicle() instanceof DonkeyEntity ||
                mc.player.getVehicle() instanceof LlamaEntity ||
                mc.player.getVehicle() instanceof MuleEntity) {
            HorseBaseEntity h = (HorseBaseEntity) mc.player.getVehicle();
            maxHealth = h.getHealthMaximum() + " §2HP";
            speed = round(43.17 * h.getMovementSpeed(), 2) + " §2m/s";
            jumpHeight = round(-0.1817584952 * Math.pow(h.getJumpStrength(), 3) + 3.689713992 * Math.pow(h.getJumpStrength(), 2) + 2.128599134 * h.getJumpStrength() - 0.343930367, 4) + " §2m";
            BleachLogger.infoMessage("\n§6Entity Stats:\n§cMax Health: §b" + maxHealth + "\n§cSpeed: §b" + speed + "\n§cJump: §b" + jumpHeight);
        } else if (mc.player.getVehicle() instanceof LivingEntity) {
            LivingEntity l = (LivingEntity) mc.player.getVehicle();
            maxHealth = l.getHealthMaximum() + " §2HP";
            speed = round(43.17 * l.getMovementSpeed(), 2) + " §2m/s";
            BleachLogger.infoMessage("\n§6Entity Stats:\n§cMax Health: §b" + maxHealth + "\n§cSpeed: §b" + speed);
        }
    } else {
        BleachLogger.errorMessage("Not riding a living entity.");
    }
}
 
Example 2
Source Project: the-hallow   Source File: ScytheItem.java    License: MIT License 6 votes vote down vote up
@Override
public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity user) {
	if (!target.isAlive()) {
		if (target instanceof PlayerEntity) {
			// give player soul
		} else if (target instanceof WitherEntity) {
			// give withered soul
		} else {
			EntityCategory category = target.getType().getCategory();
			switch (category) {
				case MONSTER:
					// give monster soul
					break;
				case CREATURE:
				case WATER_CREATURE:
				case AMBIENT:
					// give creature soul
					break;
				default:
					break;
			}
		}
	}
	return super.postHit(stack, target, user);
}
 
Example 3
Source Project: MineLittlePony   Source File: Pony.java    License: MIT License 6 votes vote down vote up
@Override
public Vec3d getAbsoluteRidingOffset(LivingEntity entity) {
    IPony ridingPony = getMountedPony(entity);

    if (ridingPony != null) {
        LivingEntity ridee = (LivingEntity)entity.getVehicle();

        Vec3d offset = PonyTransformation.forSize(ridingPony.getMetadata().getSize()).getRiderOffset();
        float scale = ridingPony.getMetadata().getSize().getScaleFactor();

        return ridingPony.getAbsoluteRidingOffset(ridee)
                .add(0, offset.y - ridee.getHeight() * 1/scale, 0);
    }

    float delta = MinecraftClient.getInstance().getTickDelta();

    return new Vec3d(
            MathHelper.lerp(delta, entity.prevX, entity.getX()),
            MathHelper.lerp(delta, entity.prevY, entity.getY()),
            MathHelper.lerp(delta, entity.prevZ, entity.getZ())
    );
}
 
Example 4
Source Project: Wurst7   Source File: RemoteViewHack.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onUpdate()
{
	// validate entity
	if(entity.removed || ((LivingEntity)entity).getHealth() <= 0)
	{
		setEnabled(false);
		return;
	}
	
	// update position, rotation, etc.
	MC.player.copyPositionAndRotation(entity);
	MC.player.resetPosition(entity.getX(),
		entity.getY() - MC.player.getEyeHeight(MC.player.getPose())
			+ entity.getEyeHeight(entity.getPose()),
		entity.getZ());
	MC.player.setVelocity(Vec3d.ZERO);
	
	// set entity invisible
	entity.setInvisible(true);
}
 
Example 5
@Override
public void onCommand(String command, String[] args) throws Exception {
    if (mc.player.getVehicle() != null) {
        if     (mc.player.getVehicle() instanceof HorseEntity ||
                mc.player.getVehicle() instanceof DonkeyEntity ||
                mc.player.getVehicle() instanceof LlamaEntity ||
                mc.player.getVehicle() instanceof MuleEntity) {
            HorseBaseEntity h = (HorseBaseEntity) mc.player.getVehicle();
            maxHealth = h.getMaximumHealth() + " §2HP";
            speed = round(43.17 * h.getMovementSpeed(), 2) + " §2m/s";
            jumpHeight = round(-0.1817584952 * Math.pow(h.getJumpStrength(), 3) + 3.689713992 * Math.pow(h.getJumpStrength(), 2) + 2.128599134 * h.getJumpStrength() - 0.343930367, 4) + " §2m";
            BleachLogger.infoMessage("\n§6Entity Stats:\n§cMax Health: §b" + maxHealth + "\n§cSpeed: §b" + speed + "\n§cJump: §b" + jumpHeight);
        } else if (mc.player.getVehicle() instanceof LivingEntity) {
            LivingEntity l = (LivingEntity) mc.player.getVehicle();
            maxHealth = l.getMaximumHealth() + " §2HP";
            speed = round(43.17 * l.getMovementSpeed(), 2) + " §2m/s";
            BleachLogger.infoMessage("\n§6Entity Stats:\n§cMax Health: §b" + maxHealth + "\n§cSpeed: §b" + speed);
        }
    } else {
        BleachLogger.errorMessage("Not riding a living entity.");
    }
}
 
Example 6
Source Project: MineLittlePony   Source File: ArmourFeature.java    License: MIT License 6 votes vote down vote up
private static <T extends LivingEntity, V extends BipedEntityModel<T> & IArmour> void renderArmourPart(
        MatrixStack matrices, VertexConsumerProvider provider,
        int light, boolean glint, V model, float r, float g, float b, IArmourTextureResolver<T> resolver, ArmourLayer layer, Identifier texture) {

    VertexConsumer vertices = ItemRenderer.method_27952(provider, RenderLayer.getArmorCutoutNoCull(texture), false, glint);

    model.setVariant(resolver.getArmourVariant(layer, texture));
    model.render(matrices, vertices, light, OverlayTexture.DEFAULT_UV, r, g, b, 1);
}
 
Example 7
Source Project: MineLittlePony   Source File: Pony.java    License: MIT License 5 votes vote down vote up
@Override
public boolean isCrouching(LivingEntity entity) {

    boolean isSneak = entity.isInSneakingPose();
    boolean isFlying = isFlying(entity);
    boolean isSwimming = isSwimming(entity);

    return !isPerformingRainboom(entity) && !isSwimming && isSneak && !isFlying;
}
 
Example 8
Source Project: Sandbox   Source File: BlockWrapper.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onPlaced(World world_1, BlockPos blockPos_1, BlockState blockState_1, @Nullable LivingEntity livingEntity_1, net.minecraft.item.ItemStack itemStack_1) {
    block.onBlockPlaced(
            (org.sandboxpowered.sandbox.api.world.World) world_1,
            (Position) blockPos_1,
            (org.sandboxpowered.sandbox.api.state.BlockState) blockState_1,
            (Entity) livingEntity_1,
            WrappingUtil.cast(itemStack_1, ItemStack.class)
    );
}
 
Example 9
Source Project: MineLittlePony   Source File: Pony.java    License: MIT License 5 votes vote down vote up
@Override
public IPony getMountedPony(LivingEntity entity) {
    if (entity.hasVehicle() && entity.getVehicle() instanceof LivingEntity) {
        LivingEntity mount = (LivingEntity) entity.getVehicle();

        IPonyRenderContext<LivingEntity, ?> render = PonyRenderDispatcher.getInstance().getPonyRenderer(mount);

        return render == null ? null : render.getEntityPony(mount);
    }
    return null;
}
 
Example 10
Source Project: MineLittlePony   Source File: IPonyRenderContext.java    License: MIT License 5 votes vote down vote up
/**
 * Called by riders to have their transportation adjust their position.
 */
default void translateRider(T entity, IPony entityPony, LivingEntity passenger, IPony passengerPony, MatrixStack stack, float ticks) {
    if (!passengerPony.getRace(false).isHuman()) {
        float yaw = MathUtil.interpolateDegress((float)entity.prevY, (float)entity.getY(), ticks);

        getModelWrapper().apply(entityPony.getMetadata());
        M model = getModelWrapper().getBody();

        model.transform(BodyPart.BACK, stack);

        getInternalRenderer().applyPostureRiding(entity, stack, yaw, ticks);
    }
}
 
Example 11
Source Project: Galacticraft-Rewoven   Source File: GalacticraftItems.java    License: MIT License 5 votes vote down vote up
@Override
public boolean postMine(ItemStack stack, World world, BlockState blockState, BlockPos blockPos, LivingEntity entityLiving) {
    //Stronger than vanilla
    if (blockState.getHardness(null, blockPos) > 0.2001F) {
        stack.damage(2, entityLiving, (livingEntity) -> livingEntity.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND));
    }
    return true;
}
 
Example 12
Source Project: the-hallow   Source File: ScytheItem.java    License: MIT License 5 votes vote down vote up
@Override
public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity user) {
	if (state.getBlock() == Blocks.SOUL_SAND) {
		// give random soul
	}
	return super.postMine(stack, world, state, pos, user);
}
 
Example 13
Source Project: MineLittlePony   Source File: Pony.java    License: MIT License 5 votes vote down vote up
@Override
public boolean isPerformingRainboom(LivingEntity entity) {
    Vec3d motion = entity.getVelocity();
    double zMotion = Math.sqrt(motion.x * motion.x + motion.z * motion.z);

    return (isFlying(entity) && canFly()) || entity.isFallFlying() & zMotion > 0.4F;
}
 
Example 14
Source Project: the-hallow   Source File: GoldenCandyCornItem.java    License: MIT License 5 votes vote down vote up
@Override
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) {
	if (user instanceof PlayerEntity) {
		PlayerEntity player = (PlayerEntity) user;
		stack.getOrCreateTag().putBoolean("Eating", true);
		player.getItemCooldownManager().set(this, 40);
	}
	return super.finishUsing(stack, world, user);
}
 
Example 15
Source Project: MiningGadgets   Source File: MiningGadget.java    License: MIT License 5 votes vote down vote up
@OnlyIn(Dist.CLIENT)
public void playLoopSound(LivingEntity player, ItemStack stack) {
    float volume = MiningProperties.getVolume(stack);
    PlayerEntity myplayer = Minecraft.getInstance().player;
    if (myplayer.equals(player)) {
        if (volume != 0.0f) {
            if (laserLoopSound == null) {
                laserLoopSound = new LaserLoopSound((PlayerEntity) player, volume);
                Minecraft.getInstance().getSoundHandler().play(laserLoopSound);
            }
        }
    }
}
 
Example 16
@Override
public ItemOverrideList getOverrides() {
    return new ItemOverrideList() {
        @Override
        public IBakedModel getModelWithOverrides(IBakedModel originalModel, ItemStack stack, World world, LivingEntity entity) {
            IBakedModel model = ModelBakery.getCachedItemModel(stack);
            if (model == null) {
                return originalModel;
            }
            return model;
        }
    };
}
 
Example 17
Source Project: Wurst7   Source File: RadarHack.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onUpdate()
{
	ClientPlayerEntity player = MC.player;
	ClientWorld world = MC.world;
	
	entities.clear();
	Stream<Entity> stream =
		StreamSupport.stream(world.getEntities().spliterator(), true)
			.filter(e -> !e.removed && e != player)
			.filter(e -> !(e instanceof FakePlayerEntity))
			.filter(e -> e instanceof LivingEntity)
			.filter(e -> ((LivingEntity)e).getHealth() > 0);
	
	if(filterPlayers.isChecked())
		stream = stream.filter(e -> !(e instanceof PlayerEntity));
	
	if(filterSleeping.isChecked())
		stream = stream.filter(e -> !(e instanceof PlayerEntity
			&& ((PlayerEntity)e).isSleeping()));
	
	if(filterMonsters.isChecked())
		stream = stream.filter(e -> !(e instanceof Monster));
	
	if(filterAnimals.isChecked())
		stream = stream.filter(
			e -> !(e instanceof AnimalEntity || e instanceof AmbientEntity
				|| e instanceof WaterCreatureEntity));
	
	if(filterInvisible.isChecked())
		stream = stream.filter(e -> !e.isInvisible());
	
	entities.addAll(stream.collect(Collectors.toList()));
}
 
Example 18
/**
 * @param entity The placing entity, used for obtaining the look vector
 * @return The side towards which the entity is most directly looking.
 */
public static int getSideFromLookAngle(LivingEntity entity) {
    Vector3 look = new Vector3(entity.getLook(1));
    double max = 0;
    int maxs = 0;
    for (int s = 0; s < 6; s++) {
        double d = look.scalarProject(axes[s]);
        if (d > max) {
            max = d;
            maxs = s;
        }
    }
    return maxs;
}
 
Example 19
Source Project: Wurst7   Source File: HealthTagsHack.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String addHealth(LivingEntity entity, String nametag)
{
	if(!isEnabled())
		return nametag;
	
	int health = (int)entity.getHealth();
	return nametag + " " + getColor(health) + health;
}
 
Example 20
@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
private void hookDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> callback) {
	LivingEntity entity = (LivingEntity) (Object) this;

	if (EntityEvents.onLivingAttack(entity, source, amount)) {
		callback.setReturnValue(false);
	}
}
 
Example 21
Source Project: fabric-carpet   Source File: TntEntityMixin.java    License: MIT License 5 votes vote down vote up
@Inject(method = "<init>(Lnet/minecraft/world/World;DDDLnet/minecraft/entity/LivingEntity;)V",
            at = @At("RETURN"))
private void modifyTNTAngle(World world, double x, double y, double z, LivingEntity entity, CallbackInfo ci)
{
    if (CarpetSettings.hardcodeTNTangle != -1.0D)
        setVelocity(-Math.sin(CarpetSettings.hardcodeTNTangle) * 0.02, 0.2, -Math.cos(CarpetSettings.hardcodeTNTangle) * 0.02);
}
 
Example 22
Source Project: Wurst7   Source File: ProtectCmd.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void call(String[] args) throws CmdException
{
	if(args.length != 1)
		throw new CmdSyntaxError();
	
	ProtectHack protectHack = WURST.getHax().protectHack;
	
	if(protectHack.isEnabled())
		protectHack.setEnabled(false);
	
	Entity entity = StreamSupport
		.stream(MC.world.getEntities().spliterator(), true)
		.filter(e -> e instanceof LivingEntity)
		.filter(e -> !e.removed && ((LivingEntity)e).getHealth() > 0)
		.filter(e -> e != MC.player)
		.filter(e -> !(e instanceof FakePlayerEntity))
		.filter(e -> args[0].equalsIgnoreCase(e.getName().getString()))
		.min(
			Comparator.comparingDouble(e -> MC.player.squaredDistanceTo(e)))
		.orElse(null);
	
	if(entity == null)
		throw new CmdError(
			"Entity \"" + args[0] + "\" could not be found.");
	
	protectHack.setFriend(entity);
	protectHack.setEnabled(true);
}
 
Example 23
Source Project: Wurst7   Source File: FollowCmd.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void call(String[] args) throws CmdException
{
	if(args.length != 1)
		throw new CmdSyntaxError();
	
	FollowHack followHack = WURST.getHax().followHack;
	
	if(followHack.isEnabled())
		followHack.setEnabled(false);
	
	Entity entity = StreamSupport
		.stream(MC.world.getEntities().spliterator(), true)
		.filter(e -> e instanceof LivingEntity)
		.filter(e -> !e.removed && ((LivingEntity)e).getHealth() > 0)
		.filter(e -> e != MC.player)
		.filter(e -> !(e instanceof FakePlayerEntity))
		.filter(e -> args[0].equalsIgnoreCase(e.getName().getString()))
		.min(
			Comparator.comparingDouble(e -> MC.player.squaredDistanceTo(e)))
		.orElse(null);
	
	if(entity == null)
		throw new CmdError(
			"Entity \"" + args[0] + "\" could not be found.");
	
	followHack.setEntity(entity);
	followHack.setEnabled(true);
}
 
Example 24
@Redirect(at = @At(value = "INVOKE",
	target = "Lnet/minecraft/entity/LivingEntity;isInvisibleTo(Lnet/minecraft/entity/player/PlayerEntity;)Z",
	ordinal = 0),
	method = {
		"render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V"})
private boolean canWurstSeePlayer(LivingEntity e, PlayerEntity player)
{
	if(WurstClient.INSTANCE.getHax().trueSightHack.isEnabled())
		return false;
	
	return e.isInvisibleTo(player);
}
 
Example 25
@Redirect(at = @At(value = "INVOKE",
	target = "Lnet/minecraft/entity/LivingEntity;hasStatusEffect(Lnet/minecraft/entity/effect/StatusEffect;)Z",
	ordinal = 0),
	method = {
		"render(Lnet/minecraft/client/render/Camera;FLnet/minecraft/client/world/ClientWorld;IF)V",
		"applyFog(Lnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/BackgroundRenderer$FogType;FZ)V"})
private static boolean wurstHasStatusEffect(LivingEntity entity,
	StatusEffect effect)
{
	if(effect == StatusEffects.BLINDNESS
		&& WurstClient.INSTANCE.getHax().antiBlindHack.isEnabled())
		return false;
	
	return entity.hasStatusEffect(effect);
}
 
Example 26
Source Project: multiconnect   Source File: Protocol_1_14_4.java    License: MIT License 5 votes vote down vote up
@Override
public boolean acceptEntityData(Class<? extends Entity> clazz, TrackedData<?> data) {
    if (clazz == LivingEntity.class && data == LivingEntityAccessor.getStingerCount())
        return false;
    if (clazz == TridentEntity.class && data == TridentEntityAccessor.getHasEnchantmentGlint())
        return false;
    if (clazz == WolfEntity.class && data == WolfEntityAccessor.getBegging())
        DataTrackerManager.registerOldTrackedData(WolfEntity.class, OLD_WOLF_HEALTH, 20f, LivingEntity::setHealth);
    if (clazz == EndermanEntity.class && data == EndermanEntityAccessor.getProvoked())
        return false;

    return super.acceptEntityData(clazz, data);
}
 
Example 27
Source Project: multiconnect   Source File: MixinLivingEntity.java    License: MIT License 5 votes vote down vote up
@Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;isSprinting()Z", ordinal = 0))
private boolean modifySwimSprintSpeed(LivingEntity self) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) {
        return false;
    }
    return self.isSprinting();
}
 
Example 28
public static boolean isPlayerHolding(LivingEntity entity, Predicate<Item> predicate) {
    for (Hand hand : Hand.values()) {
        ItemStack stack = entity.getHeldItem(hand);
        if (!stack.isEmpty()) {
            if (predicate.test(stack.getItem())) {
                return true;
            }
        }
    }
    return false;
}
 
Example 29
Source Project: fabric-carpet   Source File: DamageReporter.java    License: MIT License 5 votes vote down vote up
public static void register_final_damage(LivingEntity target, DamageSource source, float amount)
{
    if (!LoggerRegistry.__damage) return;
    LoggerRegistry.getLogger("damage").log( (option, player)->
        verifyAndProduceMessage(option, player, source.getSource(), target, () ->
            Messenger.c("g  - total received ",
                    String.format("r %.2f", amount),
                    "g  points of damage")
        )
    );
}
 
Example 30
@Override
public boolean useOnEntity(ItemStack stack, PlayerEntity playerIn, LivingEntity entity, Hand hand) {
	if (entity.world.isClient) {
		return false;
	}

	// Avoid duplicating vanilla interactions
	if (this == Items.SHEARS) {
		EntityType<?> type = entity.getType();

		if (type == EntityType.MOOSHROOM || type == EntityType.SHEEP || type == EntityType.SNOW_GOLEM) {
			return false;
		}
	}

	if (entity instanceof IShearable) {
		IShearable target = (IShearable) entity;
		BlockPos pos = entity.getBlockPos();

		if (target.isShearable(stack, entity.world, pos)) {
			Shearables.shearEntity(stack, entity.world, pos, target);
		}

		return true;
	}

	return false;
}