Jump to content

SamuelYaron

Members
  • Posts

    11
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

SamuelYaron's Achievements

Tree Puncher

Tree Puncher (2/8)

1

Reputation

  1. Yeah, I expected something like that already.. For anyone interested: I solved my particular situation by making the canApply function of the enchantment always return false if my setting is false. This function is not called at registration time and thus has access to the config. That creates the following behavior: Items can be enchanted neither via Anvil+book nor at the enchantment table anymore Existing enchanted items and books still exist (though are useless since I respect the config also in the logic handling the enchantment) Creative/commands are still able to create this enchantments in some cases That behavior is enough for me. Thanks for the reply
  2. -- If alternatively there is a way to remove an item from the registry again after the Config has loaded this would be fine for me as well or is it even acceptable practice to register objects in the ModConfig.Loading event instead?
  3. Hi together, I am in kind of a pickle here. I either missed something on how to register/access the config or I have a conceptional error in my thinking. I want to create a mod that contains several different enchantments -- nothing too spectacular here yet. Via config files I want to make it configurable which enchantments are enabled. Though by trying out I realized that the configurations are loaded AFTER the Registration events have fired. So my question now is: Does anyone know how I can make it configurable if an enchantment is enabled or not? For clarity, here some snippets: Crash Report (which shows the Config is not initialized yet): [17:04:59.454] [Server thread/INFO] [minecraft/DedicatedServer]: Starting minecraft server version 1.14.3 [17:04:59.639] [modloading-worker-9/INFO] [ne.mi.co.ForgeMod/FORGEMOD]: Forge mod loading, version 27.0.57, for MC 1.14.3 with MCP 20190624.152911 [17:04:59.672] [modloading-worker-9/INFO] [ne.mi.co.MinecraftForge/FORGE]: MinecraftForge v27.0.57 Initialized [17:04:59.836] [Server thread/ERROR] [ne.mi.fm.ja.FMLModContainer/]: Exception caught during firing event: Cannot get config value without assigned Config object present Index: 1 Listeners: 0: NORMAL 1: ASM: class de.oxur.qole.enchantments.Enchantments$RegistrationHandler registerEnchantments(Lnet/minecraftforge/event/RegistryEvent$Register;)V java.lang.NullPointerException: Cannot get config value without assigned Config object present at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:787) at net.minecraftforge.common.ForgeConfigSpec$ConfigValue.get(ForgeConfigSpec.java:682) at de.oxur.qole.enchantments.Enchantments$RegistrationHandler.registerEnchantments(Enchantments.java:30) at net.minecraftforge.eventbus.ASMEventHandler_0_RegistrationHandler_registerEnchantments_Register.invoke(.dynamic) at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80) at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258) at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106) at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112) at net.minecraftforge.fml.ModList.lambda$dispatchSynchronousEvent$4(ModList.java:110) at java.util.ArrayList.forEach(ArrayList.java:1257) at net.minecraftforge.fml.ModList.dispatchSynchronousEvent(ModList.java:110) at net.minecraftforge.fml.ModList.lambda$static$0(ModList.java:81) at net.minecraftforge.fml.LifecycleEventProvider.dispatch(LifecycleEventProvider.java:71) at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:173) at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$21(ModLoader.java:165) at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:915) at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:165) at net.minecraftforge.fml.server.ServerModLoader.begin(ServerModLoader.java:45) at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:121) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:585) at java.lang.Thread.run(Thread.java:748) [17:04:59.842] [Server thread/ERROR] [ne.mi.fm.ja.FMLModContainer/LOADING]: Caught exception during event RegistryEvent.Register<minecraft:enchantment> dispatch for modid oxur_qole java.lang.NullPointerException: Cannot get config value without assigned Config object present at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:787) ~[server-1.14.3-extra.jar:?] {} at net.minecraftforge.common.ForgeConfigSpec$ConfigValue.get(ForgeConfigSpec.java:682) ~[?:?] {} at de.oxur.qole.enchantments.Enchantments$RegistrationHandler.registerEnchantments(Enchantments.java:30) ~[?:1.0] {} at net.minecraftforge.eventbus.ASMEventHandler_0_RegistrationHandler_registerEnchantments_Register.invoke(.dynamic) ~[?:?] {} at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80) ~[eventbus-0.10.3-milestone.0.1+1a5fa31-service.jar:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258) ~[eventbus-0.10.3-milestone.0.1+1a5fa31-service.jar:?] {} at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106) ~[?:27.0] {} at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) ~[?:1.8.0_211] {} at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) ~[?:1.8.0_211] {} at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112) ~[?:?] {} at net.minecraftforge.fml.ModList.lambda$dispatchSynchronousEvent$4(ModList.java:110) ~[?:?] {} at java.util.ArrayList.forEach(ArrayList.java:1257) ~[?:1.8.0_211] {} at net.minecraftforge.fml.ModList.dispatchSynchronousEvent(ModList.java:110) ~[?:?] {} at net.minecraftforge.fml.ModList.lambda$static$0(ModList.java:81) ~[?:?] {} at net.minecraftforge.fml.LifecycleEventProvider.dispatch(LifecycleEventProvider.java:71) ~[?:?] {} at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:173) ~[?:?] {} at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$21(ModLoader.java:165) ~[?:?] {} at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:915) [?:?] {} at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:165) [?:?] {} at net.minecraftforge.fml.server.ServerModLoader.begin(ServerModLoader.java:45) [?:?] {} at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:121) [?:?] {pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:585) [?:?] {pl:accesstransformer:B,pl:runtimedistcleaner:A} at java.lang.Thread.run(Thread.java:748) [?:1.8.0_211] {} [17:04:59.863] [Server thread/FATAL] [ne.mi.fm.ModLoader/LOADING]: Failed to complete lifecycle event LOAD_REGISTRIES, 1 errors found [17:04:59.864] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception net.minecraftforge.fml.LoadingFailedException: null at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:177) ~[?:?] {} at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$21(ModLoader.java:165) ~[?:?] {} at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:915) ~[?:?] {} at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:165) ~[?:?] {} at net.minecraftforge.fml.server.ServerModLoader.begin(ServerModLoader.java:45) ~[?:?] {} at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:121) ~[?:?] {pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:585) [?:?] {pl:accesstransformer:B,pl:runtimedistcleaner:A} at java.lang.Thread.run(Thread.java:748) [?:1.8.0_211] {} [17:04:59.896] [Server thread/ERROR] [minecraft/MinecraftServer]: This crash report has been saved to: C:\Users\USERNAME\Documents\Forge\server\.\crash-reports\crash-2019-07-18_17.04.59-server.txt [17:04:59.920] [Server thread/INFO] [minecraft/MinecraftServer]: Stopping server [17:04:59.920] [Server thread/INFO] [minecraft/MinecraftServer]: Saving worlds [17:04:59.929] [Server thread/ERROR] [minecraft/MinecraftServer]: Exception stopping the server java.lang.IllegalArgumentException: Can not hotload overworld. This must be loaded at all times by main Server. at org.apache.commons.lang3.Validate.isTrue(Validate.java:158) ~[server-1.14.3-extra.jar:?] {} at net.minecraftforge.common.DimensionManager.initWorld(DimensionManager.java:201) ~[?:?] {} at net.minecraftforge.common.DimensionManager.getWorld(DimensionManager.java:170) ~[?:?] {} at net.minecraft.server.MinecraftServer.func_71218_a(MinecraftServer.java:958) ~[?:?] {pl:accesstransformer:B,pl:runtimedistcleaner:A} at net.minecraft.server.MinecraftServer.func_213211_a(MinecraftServer.java:508) ~[?:?] {pl:accesstransformer:B,pl:runtimedistcleaner:A} at net.minecraft.server.MinecraftServer.func_71260_j(MinecraftServer.java:540) ~[?:?] {pl:accesstransformer:B,pl:runtimedistcleaner:A} at net.minecraft.server.dedicated.DedicatedServer.func_71260_j(DedicatedServer.java:540) ~[?:?] {pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:645) [?:?] {pl:accesstransformer:B,pl:runtimedistcleaner:A} at java.lang.Thread.run(Thread.java:748) [?:1.8.0_211] {} Config class (Don't bother about the SERVER variable, but config COMMON type. I was playing around with the different types of configs, thats all): package de.oxur.qole; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.config.ModConfig; import org.apache.commons.lang3.tuple.Pair; public class QoLEModConfig { private static final ForgeConfigSpec serverSpec; public static final Server SERVER; static { final Pair<Server, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure(Server::new); serverSpec = specPair.getRight(); SERVER = specPair.getLeft(); } public static void register(final ModLoadingContext context) { context.registerConfig(ModConfig.Type.COMMON, serverSpec); } public static class Server { public final ForgeConfigSpec.BooleanValue enableVeinminer; Server(final ForgeConfigSpec.Builder builder) { builder.comment("Enable and disable enchantments").push("enchantments"); enableVeinminer = builder .comment("Enables or disables the veinminer enchantment") .translation("oxur_qole.config.common.enableVeinminer") .define("enableVeinminer", true); builder.pop(); } } } ModClass constructor: public QoLEMod() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); QoLEModConfig.register(ModLoadingContext.get()); } EventHandler responsible for registering the enchantment and causing the crash: @SubscribeEvent public static void registerEnchantments(final RegistryEvent.Register<Enchantment> event) { LOGGER.debug("Registering enchantments of {}", QoLEMod.MODID); IForgeRegistry<Enchantment> registry = event.getRegistry(); if(QoLEModConfig.SERVER.enableVeinminer.get()) { Enchantment enchantment = new VeinminerEnchantment(Enchantment.Rarity.UNCOMMON, EnchantmentType.DIGGER, EquipmentSlotType.MAINHAND).setRegistryName("veinminer"); registry.register(enchantment); } } Thanks in advance
  4. The source code for minecraft is located in the net.minecraft package. Vanilla Items and Blocks live directly in its subpackages item and block.
  5. Thanks for the clarification and explanation of whats going on! Though it does not solve the original problem for me I know now about this particular behavior and can consider it while coding. I did not see any option for editing the topics name, but for me this issue is solved and could be marked as such. Thanks again
  6. @PhilipChonacky As far as I understand this event only fires on the server. A quick test with some debug statements also verifies that. I tried to dig through all this network code for some time now, but it is hard to grasp as a newbie to the architecture. I have the suspicion though that my problem is connected to these two issues: https://github.com/MinecraftForge/MinecraftForge/issues/5802 https://github.com/MinecraftForge/MinecraftForge/issues/3272
  7. Maybe you run into the same problem as I did. I downloaded Optifine as well for 1.14.3, but putting the jar into the mods folder does not work anymore (I guess your logs could prove or disprove my theory). I don't know if I missed something, but for me it seems that OptiFine and Forge can not be run together anymore at the moment.
  8. How did you solve it in the end? Could you share the solution in case someone else runs into the same problem? BTW: I think it is a bit unfair to allege the people here of not helping or answering questions. Your other post is just 10 hours old and it is weekend.
  9. I just started the Minecraft development Instance with the debugger to verify that my event handler (the code from my first posting) fires before any logic that results in placing/removing my block from the world or the inventory. And indeed the handler runs and the interaction result is a pass. The following networking code is beyond my capabilities at the moment. So if anyone has any more ideas or hints I would appreciate it. Otherwise I will be trying to analyze the runtime behavior and share my results if they are of any note.
  10. Hm, in my original code I abort the event handling if the world is remote. Is that what you mean? In that case it would not help. Here is my original EventHandler code: @SubscribeEvent public void rightClickHarvest(PlayerInteractEvent.RightClickBlock event) { final PlayerEntity playerEntity = event.getEntityPlayer(); if(playerEntity == null) { return; } if(event.getWorld().isRemote) return; final BlockState blockState = event.getWorld().getBlockState(event.getPos()); if (!(blockState.getBlock() instanceof CropsBlock) || playerEntity.getHeldItemMainhand().canHarvestBlock(blockState) || playerEntity.getHeldItemOffhand().canHarvestBlock(blockState)) { return; } if (playerEntity.getHeldItem(event.getHand()).getItem() instanceof BlockItem) { event.setUseItem(Event.Result.DENY); event.setUseBlock(Event.Result.DENY); } if (event.getHand() != Hand.MAIN_HAND) { return; } if(canHarvest(blockState)) { playerEntity.swingArm(Hand.MAIN_HAND); if (!event.getWorld().isRemote) { harvest(blockState, event.getPos(), event.getWorld(), playerEntity); } } }
  11. Good day together, I am quite new to Forge and still learning its API. I was creating an EventHandler for the PlayerInteractEvent.RightClickBlock event to run some logic there. The ultimate goal is to implement right click crop harvesting as a little exercise to the event system. The harvesting itself is working without problems, though when I have a BlockItem (like dirt) in my main Hand and right click on the crop, the harvest logic runs, but also the dirt block is placed for a frame in the world and then vanishes as well as getting removed from my inventory. For debugging purposes I created this EventHandler: @SubscribeEvent(priority = EventPriority.HIGHEST) public void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) { final PlayerEntity playerEntity = event.getEntityPlayer(); if (playerEntity == null) { return; } if (playerEntity.getHeldItem(event.getHand()).getItem() instanceof BlockItem) { event.setUseItem(Event.Result.DENY); event.setUseBlock(Event.Result.DENY); } } I expected this code to prevent all kinds of block placing, but whenever I right-click with a BlockItem in my main hand to place it, it appears for a frame and then vanishes from the world (and my inventory). Did I misunderstand the use of the event.setUseBlock/Item methods? I would really appreciate some help Greetings SamuelYaron
×
×
  • Create New...

Important Information

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