use of net.minecraft.entity.item.ExperienceOrbEntity in project minecolonies by Minecolonies.
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 minecolonies by Minecolonies.
the class EntityAIWorkFisherman method generateBonusLoot.
/**
* Generates bonus fishing loot according to the building-level table
*/
private void generateBonusLoot() {
final LootContext context = (new LootContext.Builder((ServerWorld) this.world)).withParameter(LootParameters.ORIGIN, entityFishHook.position()).withParameter(LootParameters.THIS_ENTITY, entityFishHook).withParameter(LootParameters.TOOL, worker.getMainHandItem()).withParameter(LootParameters.KILLER_ENTITY, worker).withRandom(worker.getRandom()).withLuck((float) getPrimarySkillLevel()).create(LootParameterSets.FISHING);
final LootTable bonusLoot = this.world.getServer().getLootTables().get(ModLootTables.FISHERMAN_BONUS.getOrDefault(this.getOwnBuilding().getBuildingLevel(), new ResourceLocation("")));
final List<ItemStack> loot = bonusLoot.getRandomItems(context);
for (final ItemStack itemstack : loot) {
final ItemEntity itementity = new ItemEntity(this.world, entityFishHook.position().x, entityFishHook.position().y, entityFishHook.position().z, itemstack);
final double d0 = worker.getX() - entityFishHook.position().x;
final double d1 = (worker.getY() + 0.5D) - entityFishHook.position().y;
final double d2 = worker.getZ() - entityFishHook.position().z;
itementity.noPhysics = true;
itementity.setDeltaMovement(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
this.world.addFreshEntity(itementity);
worker.level.addFreshEntity(new ExperienceOrbEntity(worker.level, worker.getX(), worker.getY() + 0.5D, worker.getZ() + 0.5D, XP_PER_CATCH));
}
}
use of net.minecraft.entity.item.ExperienceOrbEntity in project Enigmatic-Legacy by Aizistral-Studios.
the class XPScroll method onCurioTick.
@Override
public void onCurioTick(String identifier, LivingEntity entity) {
ItemStack itemstack = SuperpositionHandler.getCurioStack(entity, EnigmaticLegacy.xpScroll);
if (!(entity instanceof PlayerEntity) || entity.world.isRemote || !ItemNBTHelper.getBoolean(itemstack, "IsActive", false))
return;
PlayerEntity player = (PlayerEntity) entity;
World world = player.world;
if (ItemNBTHelper.getBoolean(itemstack, "AbsorptionMode", true)) {
if (player.experienceTotal >= xpPortion) {
player.giveExperiencePoints(-xpPortion);
ItemNBTHelper.setInt(itemstack, "XPStored", ItemNBTHelper.getInt(itemstack, "XPStored", 0) + xpPortion);
} else if (player.experienceTotal > 0 & ExperienceHelper.getPlayerXP(player) < xpPortion) {
int exp = player.experienceTotal;
player.giveExperiencePoints(-exp);
ItemNBTHelper.setInt(itemstack, "XPStored", ItemNBTHelper.getInt(itemstack, "XPStored", 0) + exp);
}
} else {
int xp = ItemNBTHelper.getInt(itemstack, "XPStored", 0);
if (xp >= xpPortion) {
ItemNBTHelper.setInt(itemstack, "XPStored", xp - xpPortion);
player.giveExperiencePoints(xpPortion);
} else if (xp > 0 & xp < xpPortion) {
ItemNBTHelper.setInt(itemstack, "XPStored", 0);
player.giveExperiencePoints(xp);
}
}
List<ExperienceOrbEntity> orbs = world.getEntitiesWithinAABB(ExperienceOrbEntity.class, SuperpositionHandler.getBoundingBoxAroundEntity(player, ConfigHandler.XP_SCROLL_COLLECTION_RANGE.getValue()));
for (ExperienceOrbEntity processed : orbs) {
if (!processed.isAlive())
continue;
player.xpCooldown = 0;
processed.onCollideWithPlayer(player);
// processed.setPositionAndUpdate(player.posX, player.posY, player.posZ);
}
}
use of net.minecraft.entity.item.ExperienceOrbEntity in project Arclight by IzzelAliz.
the class FishingBobberEntityMixin method handleHookRetraction.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public int handleHookRetraction(ItemStack p_146034_1_) {
if (!this.world.isRemote && this.angler != null) {
int i = 0;
ItemFishedEvent event = null;
if (this.caughtEntity != null) {
PlayerFishEvent fishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) this.angler).bridge$getBukkitEntity(), ((EntityBridge) this.caughtEntity).bridge$getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_ENTITY);
Bukkit.getPluginManager().callEvent(fishEvent);
if (fishEvent.isCancelled()) {
return 0;
}
this.bringInHookedEntity();
CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayerEntity) this.angler, p_146034_1_, (FishingBobberEntity) (Object) this, Collections.emptyList());
this.world.setEntityState((FishingBobberEntity) (Object) this, (byte) 31);
i = this.caughtEntity instanceof ItemEntity ? 3 : 5;
} else if (this.ticksCatchable > 0) {
LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerWorld) this.world)).withParameter(LootParameters.POSITION, new BlockPos((FishingBobberEntity) (Object) this)).withParameter(LootParameters.TOOL, p_146034_1_).withRandom(this.rand).withLuck((float) this.luck + this.angler.getLuck());
lootcontext$builder.withParameter(LootParameters.KILLER_ENTITY, this.angler).withParameter(LootParameters.THIS_ENTITY, (FishingBobberEntity) (Object) this);
LootTable loottable = this.world.getServer().getLootTableManager().getLootTableFromLocation(LootTables.GAMEPLAY_FISHING);
List<ItemStack> list = loottable.generate(lootcontext$builder.build(LootParameterSets.FISHING));
event = new ItemFishedEvent(list, this.inGround ? 2 : 1, (FishingBobberEntity) (Object) this);
MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled()) {
this.remove();
return event.getRodDamage();
}
CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayerEntity) this.angler, p_146034_1_, (FishingBobberEntity) (Object) this, list);
for (ItemStack itemstack : list) {
ItemEntity itementity = new ItemEntity(this.world, this.posX, this.posY, this.posZ, itemstack);
PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) this.angler).bridge$getBukkitEntity(), ((EntityBridge) itementity).bridge$getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH);
playerFishEvent.setExpToDrop(this.rand.nextInt(6) + 1);
Bukkit.getPluginManager().callEvent(playerFishEvent);
if (playerFishEvent.isCancelled()) {
return 0;
}
double d0 = this.angler.posX - this.posX;
double d1 = this.angler.posY - this.posY;
double d2 = this.angler.posZ - this.posZ;
double d3 = 0.1D;
itementity.setMotion(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
this.world.addEntity(itementity);
if (playerFishEvent.getExpToDrop() > 0) {
this.angler.world.addEntity(new ExperienceOrbEntity(this.angler.world, this.angler.posX, this.angler.posY + 0.5D, this.angler.posZ + 0.5D, playerFishEvent.getExpToDrop()));
}
if (itemstack.getItem().isIn(ItemTags.FISHES)) {
this.angler.addStat(Stats.FISH_CAUGHT, 1);
}
}
i = 1;
}
if (this.inGround) {
PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) this.angler).bridge$getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.IN_GROUND);
Bukkit.getPluginManager().callEvent(playerFishEvent);
if (playerFishEvent.isCancelled()) {
return 0;
}
i = 2;
}
if (i == 0) {
PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) this.angler).bridge$getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.REEL_IN);
Bukkit.getPluginManager().callEvent(playerFishEvent);
if (playerFishEvent.isCancelled()) {
return 0;
}
}
this.remove();
return event == null ? i : event.getRodDamage();
} else {
return 0;
}
}
use of net.minecraft.entity.item.ExperienceOrbEntity in project Arclight by IzzelAliz.
the class FoxEntity_MateGoalMixin method spawnBaby.
/**
* @author IzzekAkuz
* @reason
*/
@Overwrite
protected void spawnBaby() {
FoxEntity foxentity = (FoxEntity) this.animal.createChild(this.targetMate);
if (foxentity != null) {
ServerPlayerEntity serverplayerentity = this.animal.getLoveCause();
ServerPlayerEntity serverplayerentity1 = this.targetMate.getLoveCause();
ServerPlayerEntity serverplayerentity2 = serverplayerentity;
if (serverplayerentity != null) {
((FoxEntityBridge) foxentity).bridge$addTrustedUUID(serverplayerentity.getUniqueID());
} else {
serverplayerentity2 = serverplayerentity1;
}
if (serverplayerentity1 != null && serverplayerentity != serverplayerentity1) {
((FoxEntityBridge) foxentity).bridge$addTrustedUUID(serverplayerentity1.getUniqueID());
}
int experience = this.animal.getRNG().nextInt(7) + 1;
final EntityBreedEvent entityBreedEvent = CraftEventFactory.callEntityBreedEvent(foxentity, this.animal, this.targetMate, serverplayerentity, ((AnimalEntityBridge) this.animal).bridge$getBreedItem(), experience);
if (entityBreedEvent.isCancelled()) {
return;
}
experience = entityBreedEvent.getExperience();
if (serverplayerentity2 != null) {
serverplayerentity2.addStat(Stats.ANIMALS_BRED);
CriteriaTriggers.BRED_ANIMALS.trigger(serverplayerentity2, this.animal, this.targetMate, foxentity);
}
int i = 6000;
this.animal.setGrowingAge(6000);
this.targetMate.setGrowingAge(6000);
this.animal.resetInLove();
this.targetMate.resetInLove();
foxentity.setGrowingAge(-24000);
foxentity.setLocationAndAngles(this.animal.posX, this.animal.posY, this.animal.posZ, 0.0F, 0.0F);
((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BREEDING);
this.world.addEntity(foxentity);
this.world.setEntityState(this.animal, (byte) 18);
if (this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
if (experience > 0) {
this.world.addEntity(new ExperienceOrbEntity(this.world, this.animal.posX, this.animal.posY, this.animal.posZ, experience));
}
}
}
}
Aggregations