Search in sources :

Example 26 with ExperienceOrbEntity

use of net.minecraft.entity.item.ExperienceOrbEntity in project minecolonies by ldtteam.

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));
    }
}
Also used : LootTable(net.minecraft.loot.LootTable) ItemEntity(net.minecraft.entity.item.ItemEntity) LootContext(net.minecraft.loot.LootContext) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity)

Aggregations

ExperienceOrbEntity (net.minecraft.entity.item.ExperienceOrbEntity)26 ItemStack (net.minecraft.item.ItemStack)12 ItemEntity (net.minecraft.entity.item.ItemEntity)10 Overwrite (org.spongepowered.asm.mixin.Overwrite)8 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)6 List (java.util.List)5 ServerWorld (net.minecraft.world.server.ServerWorld)5 LootContext (net.minecraft.loot.LootContext)4 LootTable (net.minecraft.loot.LootTable)4 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)4 World (net.minecraft.world.World)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 Item (net.minecraft.item.Item)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)2 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)2 Entity (net.minecraft.entity.Entity)2 ActionResultType (net.minecraft.util.ActionResultType)2 Hand (net.minecraft.util.Hand)2 PacketItemInfo (com.supermartijn642.simplemagnets.packets.magnet.PacketItemInfo)1