本文整理汇总了Java中net.minecraft.world.storage.loot.LootTable类的典型用法代码示例。如果您正苦于以下问题:Java LootTable类的具体用法?Java LootTable怎么用?Java LootTable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LootTable类属于net.minecraft.world.storage.loot包,在下文中一共展示了LootTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEntityLoot_Table
import net.minecraft.world.storage.loot.LootTable; //导入依赖的package包/类
private List<ItemStack> getEntityLoot_Table(EntityLiving el){
ResourceLocation location = (ResourceLocation)ReflectionHelper.getPrivateValue(EntityLiving.class, el, "deathLootTable","field_184659_bA");
if(location==null){
Method getLT = ReflectionHelper.findMethod(EntityLiving.class,"getLootTable","func_184647_J");
try {
location = (ResourceLocation)getLT.invoke(el);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
RunesofWizardry_Classics.log().error("Exception when trying to get LootTable from entity: "+el.getName(),e);
return getEntityLoot_Hacky(el);
}
}
if(location==null){
RunesofWizardry_Classics.log().warn(el.getName()+" does not have a LootTable. falling back to kill method");
return getEntityLoot_Hacky(el);
}
LootTableManager manager = el.world.getLootTableManager();
LootTable table = manager.getLootTableFromLocation(location);
return LootUtils.tableToItemStacks(table);
}
示例2: fillWithLoot
import net.minecraft.world.storage.loot.LootTable; //导入依赖的package包/类
/**
* Fill this inventory with loot.
* <p>
* Does nothing if no loot table has been set, loot has already been generated or this is being called on the client side.
*
* @param player The player whose Luck to use when generating loot
*/
public void fillWithLoot(@Nullable EntityPlayer player) {
final World world = worldContainer.getContainedWorld();
if (lootTableLocation != null && !world.isRemote) {
final LootTable lootTable = world.getLootTableManager().getLootTableFromLocation(lootTableLocation);
lootTableLocation = null;
final Random random = lootTableSeed == 0 ? new Random() : new Random(lootTableSeed);
final LootContext.Builder builder = new LootContext.Builder((WorldServer) world);
if (player != null) {
builder.withLuck(player.getLuck());
}
InventoryUtils.fillItemHandlerWithLoot(this, lootTable, random, builder.build());
}
}
示例3: 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);
}
}
}
示例4: 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);
}
}
示例5: onItemUseFirst
import net.minecraft.world.storage.loot.LootTable; //导入依赖的package包/类
@Override
public @Nonnull EnumActionResult onItemUseFirst(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side,
float hitX, float hitY, float hitZ, @Nonnull EnumHand hand) {
if (world.isRemote || System.getProperty("INDEV") == null || !player.isCreative()) {
return EnumActionResult.PASS;
}
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileEntityChest) {
TileEntityChest chest = (TileEntityChest) te;
chest.clear();
LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) world);
lootcontext$builder.withLuck(player.getLuck());
LootTable loottable = world.getLootTableManager().getLootTableFromLocation(LootTableList.CHESTS_SIMPLE_DUNGEON);
// LootTable loottable = world.getLootTableManager().getLootTableFromLocation(LootTableList.CHESTS_IGLOO_CHEST);
loottable.fillInventory(chest, world.rand, lootcontext$builder.build());
return EnumActionResult.PASS;
}
return EnumActionResult.PASS;
}
示例6: addPool
import net.minecraft.world.storage.loot.LootTable; //导入依赖的package包/类
private static void addPool(LootTable table)
{
LootEntry common = new LootEntryTable(new ResourceLocation("lootslashconquer:chests/common_chest"), 60, 1, new LootCondition[0], "common");
LootEntry uncommon = new LootEntryTable(new ResourceLocation("lootslashconquer:chests/uncommon_chest"), 25, 1, new LootCondition[0], "uncommon");
LootEntry rare = new LootEntryTable(new ResourceLocation("lootslashconquer:chests/rare_chest"), 10, 1, new LootCondition[0], "rare");
LootEntry legendary = new LootEntryTable(new ResourceLocation("lootslashconquer:chests/legendary_chest"), 5, 1, new LootCondition[0], "legendary");
LootEntry exotic = new LootEntryTable(new ResourceLocation("lootslashconquer:chests/exotic_chest"), 2, 1, new LootCondition[0], "exotic");
LootPool pool = new LootPool(new LootEntry[] { common, uncommon, rare, legendary, exotic }, new LootCondition[0], new RandomValueRange(0, 1), new RandomValueRange(0), "loot");
table.addPool(pool);
}
示例7: lootLoaded
import net.minecraft.world.storage.loot.LootTable; //导入依赖的package包/类
@SubscribeEvent
public static void lootLoaded(LootTableLoadEvent event)
{
if (event.getName().equals(LootTableList.CHESTS_SIMPLE_DUNGEON))
{
LootTable customTable = event.getLootTableManager().getLootTableFromLocation(new ResourceLocation(BetterThanWeagles.MODID, "custom/simple_dungeon_chest"));
LootPool customPool = customTable.getPool("weagles");
event.getTable().addPool(customPool);
}
}
示例8: 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);
}
}
示例9: addLoot
import net.minecraft.world.storage.loot.LootTable; //导入依赖的package包/类
public static void addLoot(LootTable table, ResourceLocation tableName)
{
if(BBConfig.spawnMarshmallows)
{
if(tableName.equals(LootTableList.CHESTS_SIMPLE_DUNGEON))
{
LootUtil.addItemToTable(table, "main", RegisterItems.marshmallow, 100, 1, 5);
}
else if(tableName.equals(LootTableList.CHESTS_DESERT_PYRAMID))
{
LootUtil.addItemToTable(table, "main", RegisterItems.marshmallow, 200, 1, 10);
}
else if(tableName.equals(LootTableList.CHESTS_JUNGLE_TEMPLE))
{
LootUtil.addItemToTable(table, "main", RegisterItems.marshmallow, 200, 1, 10);
}
else if(tableName.equals(LootTableList.CHESTS_STRONGHOLD_CROSSING))
{
LootUtil.addItemToTable(table, "main", RegisterItems.marshmallow, 150, 1, 12);
}
else if(tableName.equals(LootTableList.CHESTS_STRONGHOLD_CORRIDOR))
{
LootUtil.addItemToTable(table, "main", RegisterItems.marshmallow, 150, 1, 12);
}
else if(tableName.equals(LootTableList.CHESTS_ABANDONED_MINESHAFT))
{
LootUtil.addItemToTable(table, "main", RegisterItems.marshmallow, 150, 1, 12);
}
}
}
示例10: loadLootTable
import net.minecraft.world.storage.loot.LootTable; //导入依赖的package包/类
public static LootTable loadLootTable(ResourceLocation name, LootTable table)
{
LootTableLoadEvent event = new LootTableLoadEvent(name, table);
if (MinecraftForge.EVENT_BUS.post(event))
return LootTable.EMPTY_LOOT_TABLE;
return event.getTable();
}
示例11: loadLootTable
import net.minecraft.world.storage.loot.LootTable; //导入依赖的package包/类
public static LootTable loadLootTable(Gson gson, ResourceLocation name, String data, boolean custom)
{
Deque<LootTableContext> que = lootContext.get();
if (que == null)
{
que = Queues.newArrayDeque();
lootContext.set(que);
}
LootTable ret = null;
try
{
que.push(new LootTableContext(name, custom));
ret = gson.fromJson(data, LootTable.class);
que.pop();
}
catch (JsonParseException e)
{
que.pop();
throw e;
}
if (!custom)
ret = ForgeEventFactory.loadLootTable(name, ret);
if (ret != null)
ret.freeze();
return ret;
}
示例12: 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);
}
}
示例13: tableToItemStacks
import net.minecraft.world.storage.loot.LootTable; //导入依赖的package包/类
/**
* Converts a LootTable to a list of possible drops, only looks for Item and metadata.
* @param table the loot table to get items from
* @return a LinkedList of the stacks in the loot table
*/
public static List<ItemStack> tableToItemStacks(LootTable table){
List<ItemStack> stacks = new LinkedList<>();
for(LootPool p:getPools(table)){
for(LootEntry entry:getEntries(p)){
if(entry instanceof LootEntryItem){
LootEntryItem ei = (LootEntryItem)entry;
Item item = getItem(ei);
LootFunction[] functs = getFunctions(ei);
boolean metaSet = false;
for(LootFunction func:functs){
if(func instanceof SetMetadata){
metaSet=true;
RandomValueRange range = (RandomValueRange)ReflectionHelper.getPrivateValue(SetMetadata.class, (SetMetadata)func, "metaRange","field_186573_b");
int meta = MathHelper.floor(range.getMin());
stacks.add(new ItemStack(item,1,meta));
}
}
if(!metaSet)stacks.add(new ItemStack(item));
}
/* won't bother with this case for now
else if(entry instanceof LootEntryTable){
//restart with that table
ResourceLocation location = (ResourceLocation) ReflectionHelper.getPrivateValue(LootEntryTable.class, (LootEntryTable)entry, "table","field_186371_a");
}
*/
}
}
return stacks;
}
示例14: onLootTableLoad
import net.minecraft.world.storage.loot.LootTable; //导入依赖的package包/类
@SubscribeEvent
public void onLootTableLoad(LootTableLoadEvent evt)
{
LootTable table = evt.getTable();
FyrestonePool lp = new FyrestonePool();
if (evt.getName() == LootTableList.CHESTS_SIMPLE_DUNGEON)
{
lp.addItem(createLootEntry(ItemRegister.itemMysticalOrb, 0, 1, 1, 0.25));
}
if (evt.getName() == LootTableList.CHESTS_JUNGLE_TEMPLE)
{
lp.addItem(createLootEntry(ItemRegister.itemMysticalOrb, 0, 1, 1, 0.3));
}
if (evt.getName() == LootTableList.CHESTS_VILLAGE_BLACKSMITH)
{
lp.addItem(createLootEntry(ItemRegister.itemMysticalOrb, 0, 1, 1, 0.25));
}
if (evt.getName() == LootTableList.ENTITIES_ENDERMAN)
{
lp.addItem(createLootEntry(ItemRegister.itemMysticalOrb, 0, 1, 1, 0.1));
}
if (!lp.isEmpty())
{
table.addPool(lp);
}
}
示例15: onLootTableLoad
import net.minecraft.world.storage.loot.LootTable; //导入依赖的package包/类
@SubscribeEvent
public static void onLootTableLoad(LootTableLoadEvent e) {
final ResourceLocation rl = e.getName();
if (rl.equals(LootTableList.CHESTS_VILLAGE_BLACKSMITH) || rl.equals(LootTableList.CHESTS_ABANDONED_MINESHAFT) || rl.equals(LootTableList.CHESTS_JUNGLE_TEMPLE)) {
final LootTable lt = e.getTable();
LootPool lp = lt.getPool("pool0");
if (lp == null)
lp = lt.getPool("main");
if (lp != null) {
lp.addEntry(new LootEntryItem(MCFluxResources.UPCHIP, 20, 0, new LootFunction[0], new LootCondition[0], "mcflux:loot/upchip"));
}
}
}