public void fillWithLoot(@Nullable EntityPlayer player) { if (this.lootTable != null && this.world != null && this.world.getLootTableManager() != null) { LootTable loottable = this.world.getLootTableManager().getLootTableFromLocation(this.lootTable); this.lootTable = null; Random random; if (this.lootTableSeed == 0L) { random = new Random(); } else { random = new Random(this.lootTableSeed); } LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) this.world); if (player != null) { lootcontext$builder.withLuck(player.getLuck()).withPlayer(player); // Forge: add player to LootContext } loottable.fillInventory(this, random, lootcontext$builder.build()); } }
public static void generateLootFor(World world, @Nullable EntityPlayer player, IItemHandler inventory, Random rng, ResourceLocation lootTableName, int rolls) { LootContext.Builder builder = new LootContext.Builder((WorldServer) world); LootTable lootTable = world.getLootTableManager().getLootTableFromLocation(lootTableName); if (player != null) { builder.withLuck(player.getLuck()).withPlayer(player); } LootContext lootContext = builder.build(); NonNullList<ItemStack> loot = NonNullList.create(); for (int i = 0; i < rolls; i++) { mergeItemStacks(loot, toNonNullList(lootTable.generateLootForPools(rng, lootContext))); } List<Integer> randomSlots = getEmptySlotsRandomized(inventory, rng); shuffleItems(loot, randomSlots.size(), rng); for (ItemStack itemstack : loot) { if (randomSlots.isEmpty()) { AncientWarfareCore.LOG.warn("Tried to over-fill a container"); return; } if (!itemstack.isEmpty()) { inventory.insertItem(randomSlots.remove(randomSlots.size() - 1), itemstack, false); } } }
.withPlayer(FakePlayerFactory.getMinecraft((WorldServer) tile.getWorld())) .withDamageSource(DamageSource.GENERIC);
lootcontext$builder.withLuck((float) EnchantmentHelper.getLuckOfSeaModifier(angler) + angler.getLuck() + tier); lootcontext$builder.withLootedEntity(this); lootcontext$builder.withPlayer(angler);
lootcontext$builder.withPlayer(angler); lootcontext$builder.withLootedEntity(this); for (ItemStack itemstack : worldObj.getLootTableManager().getLootTableFromLocation(MaricultureAPI.fishing.getLootTableFromBait(bait)).generateLootForPools(rand, lootcontext$builder.build())) {
builder = builder.withPlayer((EntityPlayer) trueSource).withLuck(ForgeHooks.getLootingLevel(entity, trueSource, source));
/** * Our Method to drop a random item from an entire Loot Table */ public void dropRandomLootFromLootTable(ResourceLocation dungeonLoot, boolean wasRecentlyHit, int lootingModifier, DamageSource source) { long LootTableSeed = 0; int maxCount = 0; int currentCount = 0; Random Randomize = new Random(); int roll = 0; // Things for Looting enchant calculations LootTable loottable = world.getLootTableManager().getLootTableFromLocation(dungeonLoot); LootContext.Builder lootcontext$builder = (new LootContext.Builder((WorldServer) world)).withLootedEntity(this).withDamageSource(source); if (wasRecentlyHit && attackingPlayer != null) { lootcontext$builder = lootcontext$builder.withPlayer(attackingPlayer).withLuck(attackingPlayer.getLuck()); } // Here we count the amount of pools are in the Loot Table Array for (ItemStack itemstack : loottable.generateLootForPools(LootTableSeed == 0L ? rand : new Random(LootTableSeed), lootcontext$builder.build())) { maxCount++; } // Our Roll dependent on the amount of pools we counted roll = Randomize.nextInt(maxCount); for (ItemStack itemstack : loottable.generateLootForPools(LootTableSeed == 0L ? rand : new Random(LootTableSeed), lootcontext$builder.build())) { // Check if our current iteration matches our roll if (currentCount == roll) { entityDropItem(itemstack, 0.0F); } currentCount++; // Incrementing the current Iteration } }
@SubscribeEvent public void onKillChicken(LivingDeathEvent event) { if (Debug.CHICKEN_FISHING > 0) { EntityPlayer angler = event.getSource().getEntity() instanceof EntityPlayer ? (EntityPlayer) event.getSource().getEntity() : null; if (angler != null && !angler.worldObj.isRemote && event.getEntityLiving() instanceof EntityChicken) { for (int i = 0; i < Debug.CHICKEN_FISHING; i++) { LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) angler.worldObj); lootcontext$builder.withLuck((float) EnchantmentHelper.getLuckOfSeaModifier(angler) + angler.getLuck()); lootcontext$builder.withPlayer(angler); //Added by Mariculture lootcontext$builder.withLootedEntity(event.getEntityLiving()); //Added by Mariculture for (ItemStack itemstack : angler.worldObj.getLootTableManager().getLootTableFromLocation(LootTableList.GAMEPLAY_FISHING).generateLootForPools(this.rand, lootcontext$builder.build())) { EntityItem entityitem = new EntityItem(angler.worldObj, event.getEntityLiving().posX, event.getEntityLiving().posY, event.getEntityLiving().posZ, itemstack); double d0 = angler.posX - event.getEntityLiving().posX; double d1 = angler.posY - event.getEntityLiving().posY; double d2 = angler.posZ - event.getEntityLiving().posZ; double d3 = (double) MathHelper.sqrt_double(d0 * d0 + d1 * d1 + d2 * d2); double d4 = 0.1D; entityitem.motionX = d0 * d4; entityitem.motionY = d1 * d4 + (double) MathHelper.sqrt_double(d3) * 0.08D; entityitem.motionZ = d2 * d4; angler.worldObj.spawnEntityInWorld(entityitem); angler.worldObj.spawnEntityInWorld(new EntityXPOrb(angler.worldObj, angler.posX, angler.posY + 0.5D, angler.posZ + 0.5D, this.rand.nextInt(6) + 1)); } } } } } }
@Override protected void dropLoot(boolean wasRecentlyHit, int lootingModifier, @Nullable DamageSource damageSource) { super.dropLoot(wasRecentlyHit, lootingModifier, damageSource); // Also drop loot from inner entity! EntityLivingBase innerEntity = getInnerEntity(); if (innerEntity instanceof EntityLiving && damageSource != DamageSource.OUT_OF_WORLD) { ResourceLocation deathLootTable = ObfuscationHelpers.getLootTable((EntityLiving) innerEntity); if (deathLootTable != null) { LootTable loottable = getEntityWorld().getLootTableManager().getLootTableFromLocation(deathLootTable); LootContext.Builder lootcontext$builder = (new LootContext.Builder((WorldServer) getEntityWorld())) .withLootedEntity(innerEntity) .withDamageSource(DamageSource.GENERIC); if (wasRecentlyHit && this.attackingPlayer != null) { lootcontext$builder = lootcontext$builder.withPlayer(this.attackingPlayer).withLuck(this.attackingPlayer.getLuck()); } for (ItemStack itemstack : loottable.generateLootForPools(getEntityWorld().rand, lootcontext$builder.build())) { this.entityDropItem(itemstack, 0.0F); } } } }
private static List<ItemStack> getLoot(World world, @Nullable EntityPlayer player, boolean entityWasRecentlyHit, ResourceLocation lootTableName) { LootContext.Builder builder = new LootContext.Builder((WorldServer) world); LootTable lootTable = world.getLootTableManager().getLootTableFromLocation(lootTableName); if (entityWasRecentlyHit && player != null) { builder.withLuck(player.getLuck()).withPlayer(player); } return lootTable.generateLootForPools(world.rand, builder.build()); }
public static List<ItemStack> getLoot(ResourceLocation loot, World world, EntityPlayer player, float luck) { LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) world); lootcontext$builder.withLuck(player.getLuck() + luck); lootcontext$builder.withPlayer(player); return world.getLootTableManager().getLootTableFromLocation(loot).generateLootForPools(world.rand, lootcontext$builder.build()); }
public ItemStack getItemFromLootTable() { LootTable loottable = this.world.getLootTableManager().getLootTableFromLocation(getDeadLootTable()); LootContext.Builder lootcontext$builder = (new LootContext.Builder((WorldServer) this.world)).withLootedEntity(this).withDamageSource(DamageSource.GENERIC); if (this.attackingPlayer != null) { lootcontext$builder = lootcontext$builder.withPlayer(this.attackingPlayer).withLuck(this.attackingPlayer.getLuck()); } List<ItemStack> loot = loottable.generateLootForPools(this.rand, lootcontext$builder.build()); if (loot.isEmpty()) { return ItemStack.EMPTY; } else { return loot.get(0); } }