use of net.minecraft.entity.item.ExperienceOrbEntity in project ChocolateQuestRepoured by TeamChocoQuest.
the class EntityCQRExterminator method tickDeath.
// Death animation
// Death animation time: 1.44s => 29 ticks
@Override
protected void tickDeath() {
++this.deathTime;
if (this.deathTime == 65) {
this.spawnDeathPoofParticles();
}
if (this.deathTime >= 70 && this.isServerWorld()) {
if (this.deathCause != null) {
super.dropAllDeathLoot(deathCause);
// super.dropLoot(this.lastHurtByPlayerTime > 0, net.minecraftforge.common.ForgeHooks.getLootingLevel(this, this.deathCause.getEntity(), this.deathCause), this.deathCause);
}
// Copied from EntityLivingBase
if (!this.level.isClientSide && this.lastHurtByPlayerTime > 0 && this.shouldDropLoot() && this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
int i = this.getExperienceReward(this.lastHurtByPlayer);
i = net.minecraftforge.event.ForgeEventFactory.getExperienceDrop(this, this.lastHurtByPlayer, i);
while (i > 0) {
int j = ExperienceOrbEntity.getExperienceValue(i);
i -= j;
this.level.addFreshEntity(new ExperienceOrbEntity(this.level, this.getX(), this.getY(), this.getZ(), j));
}
}
this.remove();
this.onFinalDeath();
}
}
use of net.minecraft.entity.item.ExperienceOrbEntity in project minecolonies by ldtteam.
the class CitizenExperienceHandler method dropExperience.
@Override
public void dropExperience() {
int experience;
if (!CompatibilityUtils.getWorldFromCitizen(citizen).isClientSide && citizen.getRecentlyHit() > 0 && citizen.checkCanDropLoot() && CompatibilityUtils.getWorldFromCitizen(citizen).getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
experience = (int) (citizen.getCitizenData().getCitizenSkillHandler().getTotalXP());
while (experience > 0) {
final int j = ExperienceOrbEntity.getExperienceValue(experience);
experience -= j;
CompatibilityUtils.getWorldFromCitizen(citizen).addFreshEntity(new ExperienceOrbEntity(CompatibilityUtils.getWorldFromCitizen(citizen), citizen.getX(), citizen.getY(), citizen.getZ(), j));
}
}
// Spawn particle explosion of xp orbs on death
for (int i = 0; i < XP_PARTICLE_EXPLOSION_SIZE; ++i) {
final double d2 = citizen.getRandom().nextGaussian() * 0.02D;
final double d0 = citizen.getRandom().nextGaussian() * 0.02D;
final double d1 = citizen.getRandom().nextGaussian() * 0.02D;
CompatibilityUtils.getWorldFromCitizen(citizen).addParticle(ParticleTypes.EXPLOSION, citizen.getX() + (citizen.getRandom().nextDouble() * citizen.getBbWidth() * 2.0F) - (double) citizen.getBbWidth(), citizen.getY() + (citizen.getRandom().nextDouble() * citizen.getBbHeight()), citizen.getZ() + (citizen.getRandom().nextDouble() * citizen.getBbWidth() * 2.0F) - (double) citizen.getBbWidth(), d2, d0, d1);
}
}
use of net.minecraft.entity.item.ExperienceOrbEntity in project minecolonies by ldtteam.
the class CitizenExperienceHandler method gatherXp.
@Override
public void gatherXp() {
if (citizen.level.isClientSide) {
return;
}
final int growSize = counterMovedXp > 0 || citizen.getRandom().nextInt(100) < 20 ? 8 : 2;
final AxisAlignedBB box = citizen.getBoundingBox().inflate(growSize);
if (!WorldUtil.isAABBLoaded(citizen.level, box)) {
return;
}
boolean movedXp = false;
for (@NotNull final ExperienceOrbEntity orb : citizen.level.getLoadedEntitiesOfClass(ExperienceOrbEntity.class, box)) {
if (orb.tickCount < 5) {
continue;
}
Vector3d vec3d = new Vector3d(citizen.getX() - orb.getX(), citizen.getY() + (double) this.citizen.getEyeHeight() / 2.0D - orb.getY(), citizen.getZ() - orb.getZ());
double d1 = vec3d.lengthSqr();
if (d1 < 1.0D) {
addExperience(orb.getValue() / 2.5D);
orb.remove();
counterMovedXp = 0;
} else if (counterMovedXp > MAX_XP_PICKUP_ATTEMPTS) {
addExperience(orb.getValue() / 2.0D);
orb.remove();
counterMovedXp = 0;
return;
}
double d2 = 1.0D - Math.sqrt(d1) / 8.0D;
orb.setDeltaMovement(orb.getDeltaMovement().add(vec3d.normalize().scale(d2 * d2 * 0.1D)));
movedXp = true;
counterMovedXp++;
}
if (!movedXp) {
counterMovedXp = 0;
}
}
use of net.minecraft.entity.item.ExperienceOrbEntity in project ChaosAwakens by ChaosAwakens.
the class UltimateFishingBobberEntity method retrieve.
@Override
public int retrieve(ItemStack p_146034_1_) {
PlayerEntity playerentity = this.getPlayerOwner();
if (!this.level.isClientSide && playerentity != null) {
int i = 0;
net.minecraftforge.event.entity.player.ItemFishedEvent e = null;
if (this.hookedIn != null) {
this.bringInHookedEntity();
CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayerEntity) playerentity, p_146034_1_, this, Collections.emptyList());
this.level.broadcastEntityEvent(this, (byte) 31);
i = this.hookedIn instanceof ItemEntity ? 3 : 5;
} else if (this.nibble > 0) {
LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerWorld) this.level)).withParameter(LootParameters.ORIGIN, this.position()).withParameter(LootParameters.TOOL, p_146034_1_).withParameter(LootParameters.THIS_ENTITY, this).withRandom(this.random).withLuck((float) this.luck + playerentity.getLuck());
lootcontext$builder.withParameter(LootParameters.KILLER_ENTITY, this.getOwner()).withParameter(LootParameters.THIS_ENTITY, this);
double d = (float) MathHelper.floor(this.getBoundingBox().minY) + 1.0F;
BlockState state = this.level.getBlockState(new BlockPos(this.getX(), d - 1.0D, this.getZ()));
ResourceLocation table;
if (state.getMaterial() == Material.LAVA) {
World w = playerentity.level;
// final String location = biome.location().toString();
if (BiomeDictionary.hasType(Biomes.NETHER_WASTES, BiomeDictionary.Type.NETHER) || BiomeDictionary.hasType(Biomes.CRIMSON_FOREST, BiomeDictionary.Type.NETHER) || BiomeDictionary.hasType(Biomes.WARPED_FOREST, BiomeDictionary.Type.NETHER)) {
// loottable = this.level.getServer().getLootTables().get(CALootTables.FISHING_NETHER_FISH);
table = CALootTables.FISHING_NETHER_FISH;
} else if (!BiomeDictionary.hasType(Biomes.NETHER_WASTES, BiomeDictionary.Type.NETHER) || BiomeDictionary.hasType(Biomes.CRIMSON_FOREST, BiomeDictionary.Type.NETHER) || BiomeDictionary.hasType(Biomes.WARPED_FOREST, BiomeDictionary.Type.NETHER)) {
// loottable = this.level.getServer().getLootTables().get(CALootTables.FISHING_LAVA_FISH);
table = CALootTables.FISHING_LAVA_FISH;
} else {
table = CALootTables.FISHING_LAVA_FISH;
}
} else {
// loottable = this.level.getServer().getLootTables().get(LootTables.FISHING);
table = LootTables.FISHING;
}
LootTable loottable = this.level.getServer().getLootTables().get(table);
List<ItemStack> list = loottable.getRandomItems(lootcontext$builder.create(LootParameterSets.FISHING));
e = new net.minecraftforge.event.entity.player.ItemFishedEvent(list, this.onGround ? 2 : 1, this);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(e);
if (e.isCanceled()) {
this.remove();
return e.getRodDamage();
}
CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayerEntity) playerentity, p_146034_1_, this, list);
for (ItemStack itemstack : list) {
ItemEntity itementity = new ItemEntity(this.level, this.getX(), this.getY(), this.getZ(), itemstack);
double d0 = playerentity.getX() - this.getX();
double d1 = playerentity.getY() - this.getY();
double d2 = playerentity.getZ() - this.getZ();
double d3 = 0.1D;
itementity.setDeltaMovement(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
this.level.addFreshEntity(itementity);
playerentity.level.addFreshEntity(new ExperienceOrbEntity(playerentity.level, playerentity.getX(), playerentity.getY() + 0.5D, playerentity.getZ() + 0.5D, this.random.nextInt(6) + 1));
if (itemstack.getItem().is(ItemTags.FISHES)) {
playerentity.awardStat(Stats.FISH_CAUGHT, 1);
}
}
i = 1;
}
if (this.onGround) {
i = 2;
}
this.remove();
return e == null ? i : e.getRodDamage();
} else {
return 0;
}
}
use of net.minecraft.entity.item.ExperienceOrbEntity in project minecolonies by Minecolonies.
the class CitizenExperienceHandler method dropExperience.
@Override
public void dropExperience() {
int experience;
if (!CompatibilityUtils.getWorldFromCitizen(citizen).isClientSide && citizen.getRecentlyHit() > 0 && citizen.checkCanDropLoot() && CompatibilityUtils.getWorldFromCitizen(citizen).getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
experience = (int) (citizen.getCitizenData().getCitizenSkillHandler().getTotalXP());
while (experience > 0) {
final int j = ExperienceOrbEntity.getExperienceValue(experience);
experience -= j;
CompatibilityUtils.getWorldFromCitizen(citizen).addFreshEntity(new ExperienceOrbEntity(CompatibilityUtils.getWorldFromCitizen(citizen), citizen.getX(), citizen.getY(), citizen.getZ(), j));
}
}
// Spawn particle explosion of xp orbs on death
for (int i = 0; i < XP_PARTICLE_EXPLOSION_SIZE; ++i) {
final double d2 = citizen.getRandom().nextGaussian() * 0.02D;
final double d0 = citizen.getRandom().nextGaussian() * 0.02D;
final double d1 = citizen.getRandom().nextGaussian() * 0.02D;
CompatibilityUtils.getWorldFromCitizen(citizen).addParticle(ParticleTypes.EXPLOSION, citizen.getX() + (citizen.getRandom().nextDouble() * citizen.getBbWidth() * 2.0F) - (double) citizen.getBbWidth(), citizen.getY() + (citizen.getRandom().nextDouble() * citizen.getBbHeight()), citizen.getZ() + (citizen.getRandom().nextDouble() * citizen.getBbWidth() * 2.0F) - (double) citizen.getBbWidth(), d2, d0, d1);
}
}
Aggregations