Jump to content

[1.14.4] How to add to vanilla loot tables without overriding them?


BlockyPenguin

Recommended Posts

So I want to add an item to the vanilla loot table "simple_dungeon", but whatever I try, it doesn't work...

Any help appreciated.

 

EDIT: I now have this code:

@SubscribeEvent
        public void onLootLoad(LootTableLoadEvent e) {
            if (e.getName().toString().equals("minecraft:chests/simple_dungeon")) {
				LootPool pool = LootPool.builder().rolls(ConstantRange.of(1)).addEntry(ItemLootEntry.builder(ModItems.GOLDEN_FEATHER).weight(25)).addEntry(ItemLootEntry.builder(Items.AIR).weight(75)).build();
                e.getTable().addPool(pool);
            }
        }

but it still doesn't add it to the the loot table. I can check the loot tables with /loot, but I also added in some messages to be printed to the console when onLootLoad was run, and they never got printed. What's going on?

Edited by BlockyPenguin

Today (22/10/20) I reached 100 posts!

I'm probably more excited than I should be for something so realistically minor...

Link to comment
Share on other sites

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

@Draco18s, thanks for your reply. I now have this code:
 

@SubscribeEvent
public void onLootLoad(LootTableLoadEvent e) {
  LOGGER.info("LOOT IS LOADING");
  if(e.getName().equals(new ResourceLocation("minecraft", "chests/simple_dungeon"))) {
    e.getTable().addPool(LootPool.builder().addEntry(TableLootEntry.builder(new ResourceLocation(MODID, "inject/simple_dungeon"))).build());
  }
}

But it still doesn't work. In fact "LOOT IS LOADING" never gets sent to the console! Why is this? My json file is in "resources/data/labkit/loot_tables/inject/simple_dungeon.json", that seems fine...

Today (22/10/20) I reached 100 posts!

I'm probably more excited than I should be for something so realistically minor...

Link to comment
Share on other sites

Show more of your code.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

EUREKA! Halfway through pasting a bunch of my code here, I realised my mistake. I'd accidentally put the onLootLoad method in with the registries. I've moved it to its proper place in my main class. Running a test now :)

Today (22/10/20) I reached 100 posts!

I'm probably more excited than I should be for something so realistically minor...

Link to comment
Share on other sites

Nope, nevermind, whatever I tweak, the code never seems to run in the first place...

Here's my Main Class:

Spoiler

package ...

import ...

// The value here should match an entry in the META-INF/mods.toml file
@Mod(LabKit.MODID)
public class LabKit {
	public static final String MODID = "labkit";
	public static final Logger LOGGER = LogManager.getLogger();
	
	public static IProxy proxy = DistExecutor.runForDist(() -> () -> new ClientProxy(), () -> () -> new ServerProxy());
	public static ModSetup setup  = new ModSetup(); 

    public LabKit() {
        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        MinecraftForge.EVENT_BUS.register(LabKit.class);
    }

    private void setup(final FMLCommonSetupEvent event) {
        LOGGER.info("Hello, Scientists!");
        LOGGER.info("LabKit now starting...");
        setup.init();
        proxy.init();
    }
    
    // You can use SubscribeEvent and let the Event Bus discover methods to call
    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent e) {
        LOGGER.info("LabKit now starting on server...");
    }
    
    @SubscribeEvent
    public void onLootLoad(LootTableLoadEvent e) {
    	LOGGER.info("LOOT IS LOADING");
    	if(e.getName().equals(new ResourceLocation("minecraft", "chests/simple_dungeon"))) {
            e.getTable().addPool(LootPool.builder().addEntry(TableLootEntry.builder(new ResourceLocation(MODID, "inject/simple_dungeon"))).build());
        }
    }
    
	public static Item.Properties mainItemGroup = new Item.Properties()
    	.group(ModItemGroups.LABKIT_MAIN_ITEMGROUP);
    	
	public static Item.Properties WIPItemGroup = new Item.Properties()
    	.group(ModItemGroups.LABKIT_WIP_ITEMGROUP);

    // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
    // Event bus for receiving Registry Events)
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> event) {
            event.getRegistry().register(new WhiteFloorTiles());
            event.getRegistry().register(new GreyFloorTiles());
            event.getRegistry().register(new DarkGreyFloorTiles());
            event.getRegistry().register(new ReinforcedWhiteFloorTiles());
            event.getRegistry().register(new ReinforcedGreyFloorTiles());
            event.getRegistry().register(new ReinforcedDarkGreyFloorTiles());
            event.getRegistry().register(new CautionBlock());
            event.getRegistry().register(new ReinforcedCautionBlock());
            event.getRegistry().register(new KeycardReader());
            event.getRegistry().register(new SolarPanel());
            
            LOGGER.info("Blocks Registered!");
        }
        
        @SubscribeEvent
        public static void onItemsRegistry(final RegistryEvent.Register<Item> event) {
        	
            event.getRegistry().register(new BlockItem(ModBlocks.WHITE_FLOOR_TILES, mainItemGroup).setRegistryName("white_floor_tiles"));
            event.getRegistry().register(new BlockItem(ModBlocks.GREY_FLOOR_TILES, mainItemGroup).setRegistryName("grey_floor_tiles"));
            event.getRegistry().register(new BlockItem(ModBlocks.DARK_GREY_FLOOR_TILES, mainItemGroup).setRegistryName("dark_grey_floor_tiles"));
            event.getRegistry().register(new BlockItem(ModBlocks.REINFORCED_WHITE_FLOOR_TILES, mainItemGroup).setRegistryName("reinforced_white_floor_tiles"));
            event.getRegistry().register(new BlockItem(ModBlocks.REINFORCED_GREY_FLOOR_TILES, mainItemGroup).setRegistryName("reinforced_grey_floor_tiles"));
            event.getRegistry().register(new BlockItem(ModBlocks.REINFORCED_DARK_GREY_FLOOR_TILES, mainItemGroup).setRegistryName("reinforced_dark_grey_floor_tiles"));
            event.getRegistry().register(new BlockItem(ModBlocks.CAUTION_BLOCK, mainItemGroup).setRegistryName("caution_block"));
            event.getRegistry().register(new BlockItem(ModBlocks.REINFORCED_CAUTION_BLOCK, mainItemGroup).setRegistryName("reinforced_caution_block"));
            event.getRegistry().register(new BlockItem(ModBlocks.KEYCARD_READER, WIPItemGroup).setRegistryName("keycard_reader"));
            event.getRegistry().register(new BlockItem(ModBlocks.SOLAR_PANEL, WIPItemGroup).setRegistryName("solar_panel"));
            
            event.getRegistry().register(new Keycard());
            event.getRegistry().register(new ObsidianShards());
            event.getRegistry().register(new GoldenFeather());
            
            LOGGER.info("Items Registered!");
        }
        
        @SubscribeEvent
        public static void onTileEntityRegistry(final RegistryEvent.Register<TileEntityType<?>> event) {
        	
            event.getRegistry().register(TileEntityType.Builder.create(SolarPanelTile::new, ModBlocks.SOLAR_PANEL).build(null).setRegistryName("solar_panel"));
            event.getRegistry().register(TileEntityType.Builder.create(KeycardReaderTile::new, ModBlocks.KEYCARD_READER).build(null).setRegistryName("keycard_reader"));
            
            LOGGER.info("TileEntities Registered!");
        }
        
        @SubscribeEvent
        public static void onEffectsRegistry(final RegistryEvent.Register<Effect> event) {
        	
			event.getRegistry().register(ModEffects.FLYING);
			event.getRegistry().register(ModEffects.SPAWN_SETTING);
            
            LOGGER.info("Effects Registered!");
        }
        
        @SubscribeEvent
        public static void onPotionsRegistry(final RegistryEvent.Register<Potion> event) {
        	
			event.getRegistry().register(ModPotions.FLYING_POTION);
			event.getRegistry().register(ModPotions.FLYING_POTION_LONG);
			
			event.getRegistry().register(ModPotions.SPAWN_SETTING_POTION);
            
            LOGGER.info("Potions Registered!");
        }
    }
}

 

 

And here's my resources/data/labkit/inject/simple_dungeon.json:

Spoiler

{
    "pools": [
        {
            "name": "main",
            "rolls": 1,
            "entries": [
                {
                    "type": "item",
                    "name": "labkit:golden_feather",
                    "weight": 25
                },
                {
                    "type": "empty",
                    "weight": 75
                }
            ]
        }
    ]
}

 

 

Today (22/10/20) I reached 100 posts!

I'm probably more excited than I should be for something so realistically minor...

Link to comment
Share on other sites

5 hours ago, BlockyPenguin said:

MinecraftForge.EVENT_BUS.register(LabKit.class);

You registered the class itself to the event bus. This requires the event listeners to be static (because instance methods require an instance).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have created a very simple mod that is just supposed to send a message to a player when they join. Upon adding it to a server (that has other mods on it), the following crash message appears: [12:13:01] [main/ERROR] [minecraft/Main]: Failed to start the minecraft server net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [         Epic Mod (epicmod) has failed to load correctly §7java.lang.NoSuchMethodException: net.ed.epicmod.EpicMod.<init>() ]         at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:243) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.fml.ModLoader.lambda$dispatchAndHandleError$24(ModLoader.java:208) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] {re:mixin}         at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:208) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$14(ModLoader.java:185) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] {re:mixin,re:computing_frames}         at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:185) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.server.loading.ServerModLoader.load(ServerModLoader.java:32) ~[forge-1.19.2-43.2.14-universal.jar%23552!/:?] {re:classloading}         at net.minecraft.server.Main.main(Main.java:113) ~[server-1.19.2-20220805.130853-srg.jar%23547!/:?] {re:classloading,re:mixin,pl:mixin:A}         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}         at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}         at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}         at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$launchService$0(CommonServerLaunchHandler.java:29) ~[fmlloader-1.19.2-43.2.14.jar%2367!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.2.jar:?] {} Why could this be? I have tried using the mod on another forge server with only this mod installed and it works there. Is my mod somehow interfering with other mods? MC version is 1.19.2
    • how to make animated doors?, maybe geckolib, but i don't know how to code it?
    • For crash 1, set max-tick-time to -1 in your server.properties Crash 2 shows a conflict or incompatibility between LuckPerms and the mod boh-0.0.6.1-forge-1.20.1_2.jar
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • so my minecraft crashes when opening my world, i played without any troubles for about 5 days and today it started tweaking.. pls help me
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.