use of net.minecraft.entity.monster.piglin.PiglinEntity in project Mekanism by mekanism.
the class MekanismTools method onLivingSpecialSpawn.
private void onLivingSpecialSpawn(LivingSpawnEvent.SpecialSpawn event) {
LivingEntity entity = event.getEntityLiving();
if (entity instanceof ZombieEntity || entity instanceof SkeletonEntity || entity instanceof PiglinEntity) {
// Don't bother calculating random numbers unless the instanceof checks pass
Random random = event.getWorld().getRandom();
double chance = random.nextDouble();
if (chance < MekanismToolsConfig.tools.armorSpawnRate.get()) {
// We can only spawn refined glowstone armor on piglins
int armorType = entity instanceof PiglinEntity ? 0 : random.nextInt(6);
if (armorType == 0) {
setEntityArmorWithChance(random, entity, ToolsItems.REFINED_GLOWSTONE_SWORD, ToolsItems.REFINED_GLOWSTONE_HELMET, ToolsItems.REFINED_GLOWSTONE_CHESTPLATE, ToolsItems.REFINED_GLOWSTONE_LEGGINGS, ToolsItems.REFINED_GLOWSTONE_BOOTS, MekanismToolsConfig.tools.refinedGlowstoneSpawnRate);
} else if (armorType == 1) {
setEntityArmorWithChance(random, entity, ToolsItems.LAPIS_LAZULI_SWORD, ToolsItems.LAPIS_LAZULI_HELMET, ToolsItems.LAPIS_LAZULI_CHESTPLATE, ToolsItems.LAPIS_LAZULI_LEGGINGS, ToolsItems.LAPIS_LAZULI_BOOTS, MekanismToolsConfig.tools.lapisLazuliSpawnRate);
} else if (armorType == 2) {
setEntityArmorWithChance(random, entity, ToolsItems.REFINED_OBSIDIAN_SWORD, ToolsItems.REFINED_OBSIDIAN_HELMET, ToolsItems.REFINED_OBSIDIAN_CHESTPLATE, ToolsItems.REFINED_OBSIDIAN_LEGGINGS, ToolsItems.REFINED_OBSIDIAN_BOOTS, MekanismToolsConfig.tools.refinedObsidianSpawnRate);
} else if (armorType == 3) {
setEntityArmorWithChance(random, entity, ToolsItems.STEEL_SWORD, ToolsItems.STEEL_HELMET, ToolsItems.STEEL_CHESTPLATE, ToolsItems.STEEL_LEGGINGS, ToolsItems.STEEL_BOOTS, MekanismToolsConfig.tools.steelSpawnRate);
} else if (armorType == 4) {
setEntityArmorWithChance(random, entity, ToolsItems.BRONZE_SWORD, ToolsItems.BRONZE_HELMET, ToolsItems.BRONZE_CHESTPLATE, ToolsItems.BRONZE_LEGGINGS, ToolsItems.BRONZE_BOOTS, MekanismToolsConfig.tools.bronzeSpawnRate);
} else {
// armorType == 5
setEntityArmorWithChance(random, entity, ToolsItems.OSMIUM_SWORD, ToolsItems.OSMIUM_HELMET, ToolsItems.OSMIUM_CHESTPLATE, ToolsItems.OSMIUM_LEGGINGS, ToolsItems.OSMIUM_BOOTS, MekanismToolsConfig.tools.osmiumSpawnRate);
}
}
}
}
use of net.minecraft.entity.monster.piglin.PiglinEntity in project relics by SSKirillSS.
the class BastionRingItem method curioTick.
@Override
public void curioTick(String identifier, int index, LivingEntity livingEntity, ItemStack stack) {
World world = livingEntity.getCommandSenderWorld();
if (world.isClientSide() || world.dimension() != World.NETHER || DurabilityUtils.isBroken(stack))
return;
PiglinEntity piglin = world.getNearestLoadedEntity(PiglinEntity.class, EntityPredicate.DEFAULT, livingEntity, livingEntity.getX(), livingEntity.getY(), livingEntity.getZ(), livingEntity.getBoundingBox().inflate(stats.locateRadius));
if (piglin == null || piglin.getTarget() == livingEntity)
return;
ServerWorld serverWorld = (ServerWorld) world;
BlockPos bastionPos = serverWorld.getChunkSource().getGenerator().findNearestMapFeature(serverWorld, Structure.BASTION_REMNANT, livingEntity.blockPosition(), 100, false);
if (bastionPos == null)
return;
piglin.addEffect(new EffectInstance(Effects.MOVEMENT_SLOWDOWN, 20, 255, false, false));
Vector3d currentVec = piglin.position();
Vector3d finalVec = currentVec.add(new Vector3d(bastionPos.getX(), piglin.getY(), bastionPos.getZ()).subtract(currentVec).normalize().multiply(2, 2, 2));
int distance = (int) Math.round(currentVec.distanceTo(finalVec)) * 20;
for (int i = 0; i < distance; i++) {
float x = (float) (((finalVec.x - currentVec.x) * i / distance) + currentVec.x);
float z = (float) (((finalVec.z - currentVec.z) * i / distance) + currentVec.z);
serverWorld.sendParticles(new CircleTintData(new Color(255, 240, 150), 0.2F - i * 0.00375F, 1, 0.99F, false), x, piglin.getY() + (piglin.getBbHeight() / 1.75F), z, 1, 0F, 0F, 0F, 0);
}
for (int i = 0; i < 2; i++) {
float angle = (0.02F * (piglin.tickCount * 3 + i * 160));
double extraX = (double) (0.75F * MathHelper.sin((float) (Math.PI + angle))) + piglin.getX();
double extraZ = (double) (0.75F * MathHelper.cos(angle)) + piglin.getZ();
serverWorld.sendParticles(new CircleTintData(new Color(255, 240, 150), 0.2F, 30, 0.95F, false), extraX, piglin.getY() + (piglin.getBbHeight() / 1.75F), extraZ, 1, 0F, 0F, 0F, 0);
}
}
Aggregations