Skip to content

Instantly share code, notes, and snippets.

Created July 20, 2017 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/cb28f1f23e036d2c6c815400bf115eab to your computer and use it in GitHub Desktop.
Save anonymous/cb28f1f23e036d2c6c815400bf115eab to your computer and use it in GitHub Desktop.
Loot Tables
"pools":[
{
"name": "main",
"rolls": 3,
"entries": [
{
"type": "item",
"name": "minecraft:porkchop",
"weight": 20,
},
{
"type": "item",
"name": "augmentedvoid:legendbow",
"weight": 10,
}
]
}
]
package mod.teamvoid.augmentedvoid.items;
import java.util.List;
import java.util.Random;
import mod.teamvoid.augmentedvoid.init.ModLootTables;
import mod.teamvoid.augmentedvoid.init.SpaceTabs;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraft.world.storage.loot.LootTableList;
public class ItemLegendaryGem extends Item{
public ItemLegendaryGem(){
super();
this.setRegistryName("legendarygem");
this.setUnlocalizedName("legendarygem");
setCreativeTab(SpaceTabs.tabSpace);
}
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)
{
list.add(TextFormatting.WHITE + "Creates a chest with loot");
list.add(TextFormatting.ITALIC + "Normally places our custom loot table");
list.add(TextFormatting.ITALIC + "Sneaking places a modified loot table");
}
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing theface, float hitX, float hitY, float hitZ)
{
IBlockState iblockstate = Blocks.CHEST.getDefaultState();
world.setBlockState(pos, Blocks.CHEST.correctFacing(world, pos, iblockstate), 2);
TileEntity tileentity = world.getTileEntity(pos);
Random random = new Random();
if (tileentity instanceof TileEntityChest)
{
/**Our Custom Loot**/
ResourceLocation location = ModLootTables.Custom_Chest_Loot;
if(player.isSneaking()){
/**Our modified Spawn Chest Loot**/
location = LootTableList.CHESTS_SPAWN_BONUS_CHEST;
}
((TileEntityChest)tileentity).setLootTable(location, random.nextLong());
}
return EnumActionResult.SUCCESS;
}
}
package mod.teamvoid.augmentedvoid.init;
import java.util.List;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.LootEntry;
import net.minecraft.world.storage.loot.LootEntryTable;
import net.minecraft.world.storage.loot.LootPool;
import net.minecraft.world.storage.loot.LootTable;
import net.minecraft.world.storage.loot.RandomValueRange;
import net.minecraft.world.storage.loot.conditions.LootCondition;
import net.minecraftforge.event.LootTableLoadEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
public class ModEventHandler {
@SubscribeEvent
public void Table_Additives(LootTableLoadEvent event){
/*Name of the table*/
String name = event.getName().toString();
try{
/*Loot tables to match*/
if(name.matches("minecraft:chests/spawn_bonus_chest")
|| name.matches("minecraft:entities/chicken")){
/*Adding a loot pool to the target table*/
event.getTable().addPool(getAdditive("augmentedinferno:Loot_Additive"));
}
/*Finding and adding to non mincraft loot*/
if(name.matches("augmentedvoid:Custom_Chest_Loot")){
}
//setblock ~ ~ ~ minecraft:chest 2 replace {LootTable:chests/spawn_bonus_chest}
}
catch(Exception exc){
}
}
/** Here we are creating a new pool from the resource location we feed it. **/
private LootPool getAdditive(String entryName) {
return new LootPool(new LootEntry[] { getAdditiveEntry(entryName, 1) }, new LootCondition[0], new RandomValueRange(1), new RandomValueRange(0, 1), "Additive_pool");
}
/** Make sure to setup your resource location accordingly **/
private LootEntryTable getAdditiveEntry(String name, int weight) {
return new LootEntryTable(new ResourceLocation(name), weight, 0, new LootCondition[0], "Additive_entry");
}
}
package mod.teamvoid.augmentedvoid.init;
import mod.teamvoid.augmentedvoid.Main;
import mod.teamvoid.augmentedvoid.Reference;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.LootTable;
import net.minecraft.world.storage.loot.LootTableList;
/** Registration and reference for new loot tables **/
public class ModLootTables {
public static final ResourceLocation Custom_Chest_Loot = register("Custom_Chest_Loot");
private static ResourceLocation register(String id) {
return LootTableList.register(new ResourceLocation(Reference.MOD_ID, id));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment