use of net.minecraft.world.storage.loot.LootContext in project MorePlanets by SteveKunG.
the class TileEntityTreasureChestMP method fillWithLoot.
protected void fillWithLoot(@Nullable EntityPlayer player) {
if (this.lootTable != 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());
}
loottable.fillInventory(this, random, lootcontext$builder.build());
}
}
use of net.minecraft.world.storage.loot.LootContext in project MorePlanets by SteveKunG.
the class TileEntityCrashedAlienProbe method fillWithLoot.
protected void fillWithLoot(@Nullable EntityPlayer player) {
if (this.lootTable != 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());
}
loottable.fillInventory(this, random, lootcontext$builder.build());
}
}
use of net.minecraft.world.storage.loot.LootContext in project MorePlanets by SteveKunG.
the class EntitySpaceFishHook method handleHookRetraction.
@Override
public int handleHookRetraction() {
if (!this.world.isRemote && this.angler != null) {
int i = 0;
if (this.caughtEntity != null) {
this.bringInHookedEntity();
this.world.setEntityState(this, (byte) 31);
i = this.caughtEntity instanceof EntityItem ? 3 : 5;
} else if (this.ticksCatchable > 0) {
LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) this.world);
lootcontext$builder.withLuck(this.luck + this.angler.getLuck());
double x = MathHelper.floor(this.posX);
double y = MathHelper.floor(this.getEntityBoundingBox().minY) + 1.0F;
double z = MathHelper.floor(this.posZ);
Block block = this.world.getBlockState(new BlockPos(x, y - 1, z)).getBlock();
ResourceLocation resource = block instanceof IFishableLiquidBlock ? ((IFishableLiquidBlock) block).getLootTable() : this.world.provider instanceof IGalacticraftWorldProvider ? MPLootTables.SPACE_FISHING : LootTableList.GAMEPLAY_FISHING;
List<ItemStack> result = this.world.getLootTableManager().getLootTableFromLocation(resource).generateLootForPools(this.rand, lootcontext$builder.build());
for (ItemStack itemstack : result) {
EntityItem entityitem = new EntityItem(this.world, this.posX, this.posY, this.posZ, itemstack);
double d0 = this.angler.posX - this.posX;
double d1 = this.angler.posY - this.posY;
double d2 = this.angler.posZ - this.posZ;
double d3 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
entityitem.motionX = d0 * 0.1D;
entityitem.motionY = d1 * 0.1D + MathHelper.sqrt(d3) * 0.08D;
entityitem.motionZ = d2 * 0.1D;
this.world.spawnEntity(entityitem);
this.angler.world.spawnEntity(new EntityXPOrb(this.angler.world, this.angler.posX, this.angler.posY + 0.5D, this.angler.posZ + 0.5D, this.rand.nextInt(6) + 1));
Item item = itemstack.getItem();
if (item == Items.FISH || item == Items.COOKED_FISH) {
this.angler.addStat(StatList.FISH_CAUGHT, 1);
}
}
i = 1;
}
if (this.inGround) {
i = 2;
}
this.setDead();
return i;
} else {
return 0;
}
}
use of net.minecraft.world.storage.loot.LootContext in project ImmersiveEngineering by BluSunrize.
the class TileEntityWoodenCrate method onGuiOpened.
@Override
public void onGuiOpened(EntityPlayer player, boolean clientside) {
if (this.lootTable != null && !clientside) {
LootTable loottable = this.worldObj.getLootTableManager().getLootTableFromLocation(this.lootTable);
this.lootTable = null;
Random random;
LootContext.Builder contextBuilder = new LootContext.Builder((WorldServer) this.worldObj);
if (player != null)
contextBuilder.withLuck(player.getLuck());
LootContext context = contextBuilder.build();
Random rand = new Random();
List<ItemStack> list = loottable.generateLootForPools(rand, context);
List<Integer> listSlots = Lists.newArrayList();
for (int i = 0; i < inventory.length; i++) if (inventory[i] == null)
listSlots.add(Integer.valueOf(i));
Collections.shuffle(listSlots, rand);
if (listSlots.isEmpty())
return;
Utils.shuffleLootItems(list, listSlots.size(), rand);
for (ItemStack itemstack : list) {
int slot = listSlots.remove(listSlots.size() - 1).intValue();
inventory[slot] = itemstack;
}
}
}
Aggregations