LootGenerator¶
- loottweaker.LootGenerator¶
A reusable object for generating loot from the tables of a specific world with a configured loot context (luck, looted entity, player, etc.). Generation does not reset the context.
You’ll need to be familiar with the vanilla loot system and its loot contexts to make use of the full capabilities of this class.
Call LootTweaker.createLootGenerator to create a loot generator.
- LootGenerator luck(float luck) ¶
Configures the luck value of the loot generator’s context.
- Returns:
the same loot generator, to allow method chaining
import loottweaker.LootTweaker; LootTweaker.createLootGenerator(world) .luck(42.0) .generate("minecraft:entities/cow");
- LootGenerator lootedEntity(IEntity entity) ¶
Configures the looted entity of the loot generator’s context.
- Returns:
the same loot generator, to allow method chaining
import loottweaker.LootTweaker; LootTweaker.createLootGenerator(world) .lootedEntity(someEntity) .generate("minecraft:entities/cow");
- LootGenerator player(IPlayer player) ¶
Configures the looting player of the loot generator’s context.
- Returns:
the same loot generator, to allow method chaining
import loottweaker.LootTweaker; LootTweaker.createLootGenerator(world) .player(somePlayer) .generate("minecraft:entities/cow");
- LootGenerator damageSource(IDamageSource damageSource) ¶
Configures the killing damage source of the loot generator’s context.
- Returns:
the same loot generator, to allow method chaining
import loottweaker.LootTweaker; import crafttweaker.damage.IDamageSource; LootTweaker.createLootGenerator(world) .damageSource(IDamageSource.MAGIC()) .generate("minecraft:entities/cow");
- IItemStack[] generate(String tableId) ¶
Generates loot with the previously configured context. The configured loot context is retained after calling.
- Parameters:
tableId - the id of the loot table to generate loot from
- Errors:
if no loot table exists with the specified name.
- Returns:
an array of item stacks generated from the loot table with the loot generator’s configured context.
- generateInto(String tableId, IEntity iEntity, String face, String overflow) ¶
Convenience method for generating loot into an inventory of a entity. The configured loot context is retained after calling.
- Parameters:
tableId - the id of the loot table to generate loot from
iEntity - the entity
face - (Optional) Which “side” of the entity to access. Some entities provide access to different entities from different sides. If you’re not sure, use
"NONE". Valid values are"NONE"(default),"TOP","BOTTOM","NORTH","EAST","SOUTH", or"WEST".overflow - (Optional) Determines what is done with loot that doesn’t fit in the inventory. Valid values are
"VOID"(default) to destroy excess loot, or"DROP"to drop excess loot at the entity’s position.
- Errors:
if the entity provides no inventory for the specified
faceif no loot table exists with the specified name.
- generateInto(String tableId, IBlockPos inventoryPos, String face, String overflow) ¶
Convenience method for generating loot into an inventory of a block. The configured loot context is retained after calling.
- Parameters:
tableId - the id of the loot table to generate loot from
inventoryPos - the position of the block
face - (Optional) Which “side” of the block to access. Some blocks provide access to different entities from different sides. If you’re not sure, use
"NONE". Valid values are"NONE"(default),"TOP","BOTTOM","NORTH","EAST","SOUTH", or"WEST".overflow - (Optional) Determines what is done with loot that doesn’t fit in the inventory. Valid values are
"VOID"(default) to destroy excess loot, or"DROP"to drop excess loot aboveinventoryPos.
- Errors:
if there is no tile entity at
inventoryPosif the tile entity provides no inventory for the specified
faceif no loot table exists with the specified name.
// A simple example focusing on the most important code
// world is an IWorld val/var defined and set elsewhere
if (!world.remote)
{
val cowItems = LootTweaker.createLootGenerator(world)
.generate("minecraft:entities/cow");
for item in cowItems {
print(item);
}
}
import loottweaker.LootTweaker;
import crafttweaker.event.EntityLivingJumpEvent;
import crafttweaker.player.IPlayer;
import crafttweaker.damage.IDamageSource;
events.onEntityLivingJump(function(event as EntityLivingJumpEvent) {
val world = event.entity.world;
if (world.remote || !(event.entity instanceof IPlayer))
{
return;
}
val player as IPlayer = event.entity;
val lootGenerator = LootTweaker.createLootGenerator(world)
.luck(42.0)
.lootedEntity(event.entity)
.player(player)
.damageSource(IDamageSource.MAGIC());
for item in lootGenerator.generate("minecraft:entities/cow") {
player.dropItem(item);
}
});