use of net.minecraft.entity.item.ExperienceOrbEntity in project minecolonies by Minecolonies.
the class NewBobberEntity method getDamage.
public int getDamage() {
if (!this.level.isClientSide && this.angler != null) {
int i = 0;
final net.minecraftforge.event.entity.player.ItemFishedEvent event = null;
if (this.caughtEntity != null) {
this.bringInHookedEntity();
this.level.broadcastEntityEvent(this, (byte) 31);
i = this.caughtEntity instanceof ItemEntity ? 3 : 5;
} else if (this.ticksCatchable > 0) {
LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerWorld) this.level)).withParameter(LootParameters.ORIGIN, this.position()).withParameter(LootParameters.TOOL, this.getAngler().getMainHandItem()).withParameter(LootParameters.THIS_ENTITY, this).withRandom(this.random).withLuck((float) this.luck);
lootcontext$builder.withParameter(LootParameters.KILLER_ENTITY, this.angler).withParameter(LootParameters.THIS_ENTITY, this);
final LootTable loottable = this.level.getServer().getLootTables().get(ModLootTables.FISHING);
final List<ItemStack> list = loottable.getRandomItems(lootcontext$builder.create(LootParameterSets.FISHING));
for (final ItemStack itemstack : list) {
final ItemEntity itementity = new ItemEntity(this.level, onWaterPos.x, onWaterPos.y, onWaterPos.z, itemstack);
final double d0 = this.angler.getX() - onWaterPos.x;
final double d1 = (this.angler.getY() + 0.5D) - onWaterPos.y;
final double d2 = this.angler.getZ() - onWaterPos.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.level.addFreshEntity(itementity);
this.angler.level.addFreshEntity(new ExperienceOrbEntity(this.angler.level, this.angler.getX(), this.angler.getY() + 0.5D, this.angler.getZ() + 0.5D, XP_PER_CATCH));
}
i = 1;
}
if (this.inGround) {
i = 2;
}
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 ExperienceBottleEntityMixin method onImpact.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
protected void onImpact(RayTraceResult result) {
if (!this.world.isRemote) {
int i = 3 + this.world.rand.nextInt(5) + this.world.rand.nextInt(5);
ExpBottleEvent event = CraftEventFactory.callExpBottleEvent((ExperienceBottleEntity) (Object) this, i);
i = event.getExperience();
if (event.getShowEffect()) {
this.world.playEvent(2002, new BlockPos((ExperienceBottleEntity) (Object) this), PotionUtils.getPotionColor(Potions.WATER));
}
while (i > 0) {
int j = ExperienceOrbEntity.getXPSplit(i);
i -= j;
this.world.addEntity(new ExperienceOrbEntity(this.world, this.posX, this.posY, this.posZ, j));
}
this.remove();
}
}
use of net.minecraft.entity.item.ExperienceOrbEntity in project Arclight by IzzelAliz.
the class ExperienceOrbEntityMixin method onCollideWithPlayer.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void onCollideWithPlayer(PlayerEntity entityIn) {
if (!this.world.isRemote) {
if (this.delayBeforeCanPickup == 0 && entityIn.xpCooldown == 0) {
if (MinecraftForge.EVENT_BUS.post(new PlayerXpEvent.PickupXp(entityIn, (ExperienceOrbEntity) (Object) this)))
return;
entityIn.xpCooldown = 2;
entityIn.onItemPickup((ExperienceOrbEntity) (Object) this, 1);
Map.Entry<EquipmentSlotType, ItemStack> entry = EnchantmentHelper.getRandomItemWithEnchantment(Enchantments.MENDING, entityIn);
if (entry != null) {
ItemStack itemstack = entry.getValue();
if (!itemstack.isEmpty() && itemstack.isDamaged()) {
int i = Math.min((int) (this.xpValue * itemstack.getXpRepairRatio()), itemstack.getDamage());
org.bukkit.event.player.PlayerItemMendEvent event = CraftEventFactory.callPlayerItemMendEvent(entityIn, (ExperienceOrbEntity) (Object) this, itemstack, i);
i = event.getRepairAmount();
if (!event.isCancelled()) {
this.xpValue -= this.durabilityToXp(i);
itemstack.setDamage(itemstack.getDamage() - i);
}
}
}
if (this.xpValue > 0) {
entityIn.giveExperiencePoints(CraftEventFactory.callPlayerExpChangeEvent(entityIn, this.xpValue).getAmount());
}
this.remove();
}
}
}
use of net.minecraft.entity.item.ExperienceOrbEntity in project Arclight by IzzelAliz.
the class LivingEntityMixin_1_14 method onDeathUpdate.
// @formatter:on
/**
* @author IzzelAliz
* @reason
*/
@SuppressWarnings("ConstantConditions")
@Overwrite
protected void onDeathUpdate() {
++this.deathTime;
if (this.deathTime >= 20 && !this.removed) {
if (!this.world.isRemote && (this.isPlayer() || this.recentlyHit > 0 && this.canDropLoot() && this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT))) {
int i = this.bridge$getExpToDrop();
while (i > 0) {
int j = ExperienceOrbEntity.getXPSplit(i);
i -= j;
this.world.addEntity(new ExperienceOrbEntity(this.world, this.posX, this.posY, this.posZ, j));
}
this.bridge$setExpToDrop(0);
}
// Forge keep data until we revive player
this.remove((Object) this instanceof ServerPlayerEntity);
for (int k = 0; k < 20; ++k) {
double d2 = this.rand.nextGaussian() * 0.02D;
double d0 = this.rand.nextGaussian() * 0.02D;
double d1 = this.rand.nextGaussian() * 0.02D;
this.world.addParticle(ParticleTypes.POOF, this.posX + (double) (this.rand.nextFloat() * this.getWidth() * 2.0F) - (double) this.getWidth(), this.posY + (double) (this.rand.nextFloat() * this.getHeight()), this.posZ + (double) (this.rand.nextFloat() * this.getWidth() * 2.0F) - (double) this.getWidth(), d2, d0, d1);
}
}
}
use of net.minecraft.entity.item.ExperienceOrbEntity in project Fragile-Glass by fredtargaryen.
the class SugarCauldronBlock method onPlayerDestroy.
@Override
public void onPlayerDestroy(IWorld worldIn, BlockPos pos, BlockState state) {
World w = (World) worldIn;
if (state.get(AGE_0_7).equals(6) && !w.isRemote) {
double x = pos.getX();
double y = pos.getY();
double z = pos.getZ();
ItemEntity entityItem = new ItemEntity(w, x + 0.5D, y + 1.0D, z + 0.5D, new ItemStack(FragileGlassBase.FRAGILE_GLASS, WorldgenConfig.GLASS_YIELD.get()));
w.addEntity(entityItem);
w.addEntity(new ExperienceOrbEntity(w, x + 0.5, y + 0.5, z + 0.5, 4));
}
super.onPlayerDestroy(worldIn, pos, state);
}
Aggregations