本文整理汇总了Java中net.minecraft.world.storage.loot.LootTable.generateLootForPools方法的典型用法代码示例。如果您正苦于以下问题:Java LootTable.generateLootForPools方法的具体用法?Java LootTable.generateLootForPools怎么用?Java LootTable.generateLootForPools使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.world.storage.loot.LootTable
的用法示例。
在下文中一共展示了LootTable.generateLootForPools方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fillItemHandlerWithLoot
import net.minecraft.world.storage.loot.LootTable; //导入方法依赖的package包/类
/**
* Fill an {@link IItemHandler} with random loot from a {@link LootTable}.
* <p>
* Adapted from {@link LootTable#fillInventory}.
*
* @param itemHandler The inventory to fill with loot
* @param lootTable The LootTable to generate loot from
* @param random The Random object to use in the loot generation
* @param context The LootContext to use in the loot generation
*/
public static void fillItemHandlerWithLoot(IItemHandler itemHandler, LootTable lootTable, Random random, LootContext context) {
final List<ItemStack> items = lootTable.generateLootForPools(random, context);
final List<Integer> emptySlots = getEmptySlotsRandomized(itemHandler, random);
try {
SHUFFLE_ITEMS.invoke(lootTable, items, emptySlots.size(), random);
} catch (Throwable throwable) {
Throwables.propagate(throwable);
}
for (ItemStack itemStack : items) {
if (emptySlots.isEmpty()) {
Logger.warn("Tried to over-fill %s while generating loot.");
return;
}
final int slot = emptySlots.remove(emptySlots.size() - 1);
final ItemStack remainder = itemHandler.insertItem(slot, itemStack, false);
if (remainder != null) {
Logger.warn("Couldn't fully insert %s into slot %d of %s, %d items remain.", itemStack, slot, itemHandler, remainder.stackSize);
}
}
}
示例2: generateLoot
import net.minecraft.world.storage.loot.LootTable; //导入方法依赖的package包/类
public static void generateLoot(ItemStackHandler items, String tableStr, long seed,
World world, EntityPlayer player) {
Random rnd = new Random(seed);
double maxFullness = (0.6 + rnd.nextDouble() * 0.2);
int maxOccupiedSlots = (int)Math.ceil(items.getSlots() * maxFullness);
LootTableManager manager = world.getLootTableManager();
LootTable table = manager.getLootTableFromLocation(new ResourceLocation(tableStr));
LootContext context = new LootContext(((player != null) ? player.getLuck() : 0),
(WorldServer)world, manager, player, null, null);
List<ItemStack> loot = table.generateLootForPools(rnd, context);
Collections.shuffle(loot);
List<Integer> randomizedSlots = new ArrayList<Integer>(items.getSlots());
for (int i = 0; i < items.getSlots(); i++) randomizedSlots.add(i);
Collections.shuffle(randomizedSlots);
for (int i = 0; (i < maxOccupiedSlots) && (i < loot.size()); i++) {
ItemStack stack = loot.get(i);
int slot = randomizedSlots.get(i);
items.setStackInSlot(slot, stack);
}
}
示例3: dropLoot
import net.minecraft.world.storage.loot.LootTable; //导入方法依赖的package包/类
/**
* drops the loot of this entity upon death
*/
protected void dropLoot(boolean wasRecentlyHit, int lootingModifier, DamageSource source)
{
ResourceLocation resourcelocation = this.deathLootTable;
if (resourcelocation == null)
{
resourcelocation = this.getLootTable();
}
if (resourcelocation != null)
{
LootTable loottable = this.world.getLootTableManager().getLootTableFromLocation(resourcelocation);
this.deathLootTable = null;
LootContext.Builder lootcontext$builder = (new LootContext.Builder((WorldServer)this.world)).withLootedEntity(this).withDamageSource(source);
if (wasRecentlyHit && this.attackingPlayer != null)
{
lootcontext$builder = lootcontext$builder.withPlayer(this.attackingPlayer).withLuck(this.attackingPlayer.getLuck());
}
for (ItemStack itemstack : loottable.generateLootForPools(this.deathLootTableSeed == 0L ? this.rand : new Random(this.deathLootTableSeed), lootcontext$builder.build()))
{
this.entityDropItem(itemstack, 0.0F);
}
this.dropEquipment(wasRecentlyHit, lootingModifier);
}
else
{
super.dropLoot(wasRecentlyHit, lootingModifier, source);
}
}
示例4: dropLoot
import net.minecraft.world.storage.loot.LootTable; //导入方法依赖的package包/类
/**
* drops the loot of this entity upon death
*/
protected void dropLoot(boolean wasRecentlyHit, int lootingModifier, DamageSource source)
{
ResourceLocation resourcelocation = this.deathLootTable;
if (resourcelocation == null)
{
resourcelocation = this.getLootTable();
}
if (resourcelocation != null)
{
LootTable loottable = this.worldObj.getLootTableManager().getLootTableFromLocation(resourcelocation);
this.deathLootTable = null;
LootContext.Builder lootcontext$builder = (new LootContext.Builder((WorldServer)this.worldObj)).withLootedEntity(this).withDamageSource(source);
if (wasRecentlyHit && this.attackingPlayer != null)
{
lootcontext$builder = lootcontext$builder.withPlayer(this.attackingPlayer).withLuck(this.attackingPlayer.getLuck());
}
for (ItemStack itemstack : loottable.generateLootForPools(this.deathLootTableSeed == 0L ? this.rand : new Random(this.deathLootTableSeed), lootcontext$builder.build()))
{
this.entityDropItem(itemstack, 0.0F);
}
this.dropEquipment(wasRecentlyHit, lootingModifier);
}
else
{
super.dropLoot(wasRecentlyHit, lootingModifier, source);
}
}
示例5: update
import net.minecraft.world.storage.loot.LootTable; //导入方法依赖的package包/类
@Override
public void update() {
World world = this.getWorld();
Random rand = world.rand;
if (rand.nextDouble() < this.getFishSpeed() &&
isValidPosition() && isEquipmentValid() &&
world instanceof WorldServer && world != null &&
world.getWorldTime() % Const.TICKS_PER_SEC == 0) {
LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) world);
int luck = EnchantmentHelper.getEnchantmentLevel(Enchantments.LUCK_OF_THE_SEA, this.getStackInSlot(toolSlot));
lootcontext$builder.withLuck((float) luck);
// java.lang.NullPointerException: Ticking block entity at com.lothrazar.cyclicmagic.block.tileentity.TileEntityFishing.func_73660_a(TileEntityFishing.java:58)
LootTableManager loot = world.getLootTableManager();
if (loot == null) {
return;
}
LootTable table = loot.getLootTableFromLocation(LootTableList.GAMEPLAY_FISHING);
if (table == null) {
return;
}
LootContext context = lootcontext$builder.build();
if (context == null) {
return;
}
for (ItemStack itemstack : table.generateLootForPools(rand, context)) {
UtilParticle.spawnParticle(world, EnumParticleTypes.WATER_WAKE, pos.up());
//damage phase.
int mending = EnchantmentHelper.getEnchantmentLevel(Enchantments.MENDING, this.getStackInSlot(toolSlot));
if (mending == 0) {
damageTool();
}
else {
if (rand.nextDouble() < 0.25) {//25% chance damage
damageTool();
}
else if (rand.nextDouble() < 0.60) {//60-25 = 40 chance repair
attemptRepairTool();
}
//else do nothing, leave it flat. mimics getting damaged and repaired right away
}
//loot phase
this.sendOutputItem(itemstack);
}
}
}