Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10] Use Events


daniel0916
 Share

Recommended Posts

Hello guys,

 

i'm a beginner in Forge Development and i have a problem with using events.

 

Code:

@Mod(modid = Test.MODID, version = Test.VERSION)
public class Test {
    public static final String MODID = "Test";
    public static final String VERSION = "1.0";
    
    @EventHandler
    public void init(FMLInitializationEvent event) {
    	MinecraftForge.EVENT_BUS.register(new CommandListener());
    	
    	//FMLCommonHandler.instance().bus().register(new ExecuteEvent());
    }
}

 

public class CommandListener {

public void onCommand(CommandEvent event) {
	System.out.println(event.command);
}
}

 

I don't get the message. What's wrong?

 

Thanks for reading my question.

 

Greetings

Daniel

Link to comment
Share on other sites

Depends what event are you talking about. There are few (use, interact, mouse click, more...).

 

Most of events are executed on both sides. Some are only on server and some will work only on client (and in most cases send info to server using vanilla packet).

 

What exacly do you need?

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Not really.

If you want event to be called for EVERY item:

PlayerUseItemEvent

This event is separated in sub-phase events, make sure you picked right one.

 

Simply check side for event to be launched on client.

 

If you'd have your OWN items, you can @Override Item#onItemRightClick(...)

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Okay, but the event doesn't get called.

 

@SubscribeEvent
public void onItemUse(PlayerUseItemEvent event) {
	System.out.println(event.item.getItem());
	System.out.println(Item.getIdFromItem(event.item.getItem()));
}

 

MinecraftForge.EVENT_BUS.register(new Events());

 

"This event is separated in sub-phase events, make sure you picked right one."

What do you mean with this exactly?

 

Edit: Ah, okay. I understand it now.

 

Edit2: Okay, the event is working when i block with the sword but i need a event which get called when i make right-click with a compass.

Link to comment
Share on other sites

PlayerInteractEvent then.

 

* This event is fired whenever a player interacts in
* Minecraft#rightClickMouse(),

 

I used it only once, very long time ago and I remember having problems with certain clicking (the righclick wasnt always calling event).

It probably changed now.

 

For certain I know that Client will always get called no matter on what you click since it's called directly from Minecraft#rightClickMouse().

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Extend CommandBase or wider implement ICommand.

In execute() you write what should happen.

getName() is your command. e.g "test" will give you /test.

 

AS for registering:

Server:

@EventHandler
public void serverLoad(FMLServerStartingEvent event)
{
	event.registerServerCommand(new CommandTest());
}

and Client:

ClientCommandHandler.instance.registerCommand(new CommandTest());

 

Note: For client registration MUST be done in ClientProxy.

Also: server will NEVER receive client commands (they are totally local).

 

EDIT: Note 2: Registering command for server doesn't require you to ALSO register it for client. You do it either for client only, or for Server (which is server+client)

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

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
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • C:\Users\namno\Desktop\Nobec>REM Forge requires a configured set of both JVM and program arguments. C:\Users\namno\Desktop\Nobec>REM Add custom JVM arguments to the user_jvm_args.txt C:\Users\namno\Desktop\Nobec>REM Add custom program arguments {such as nogui} to this file in the next line before the  or C:\Users\namno\Desktop\Nobec>REM  pass them to this script directly C:\Users\namno\Desktop\Nobec>java @user_jvm_args.txt @libraries/net/minecraftforge/forge/1.18-38.0.14/win_args.txt [16:52:53] [main/INFO]: ModLauncher running: args [--launchTarget, forgeserver, --fml.forgeVersion, 38.0.14, --fml.mcVersion, 1.18, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20211130.085255] [16:52:53] [main/INFO]: ModLauncher 9.0.7+91+master.8569cdf starting: java version 17.0.1 by Eclipse Adoptium [16:52:53] [main/INFO]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/namno/Desktop/Nobec/libraries/org/spongepowered/mixin/0.8.5/mixin-0.8.5.jar%2318! Service=ModLauncher Env=SERVER Exception in thread "main" java.lang.RuntimeException: Failed to load FML config from C:\Users\namno\Desktop\Nobec\config\fml.toml         at MC-BOOTSTRAP/fmlloader@1.18-38.0.14/net.minecraftforge.fml.loading.FMLConfig.loadFrom(FMLConfig.java:63)         at MC-BOOTSTRAP/fmlloader@1.18-38.0.14/net.minecraftforge.fml.loading.FMLConfig.load(FMLConfig.java:76)         at MC-BOOTSTRAP/fmlloader@1.18-38.0.14/net.minecraftforge.fml.loading.FMLServiceProvider.initialize(FMLServiceProvider.java:79)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.0.7/cpw.mods.modlauncher.TransformationServiceDecorator.onInitialize(TransformationServiceDecorator.java:68)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.0.7/cpw.mods.modlauncher.TransformationServicesHandler.lambda$initialiseTransformationServices$7(TransformationServicesHandler.java:93)         at java.base/java.util.HashMap$Values.forEach(HashMap.java:1065)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.0.7/cpw.mods.modlauncher.TransformationServicesHandler.initialiseTransformationServices(TransformationServicesHandler.java:93)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.0.7/cpw.mods.modlauncher.TransformationServicesHandler.initializeTransformationServices(TransformationServicesHandler.java:52)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.0.7/cpw.mods.modlauncher.Launcher.run(Launcher.java:87)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.0.7/cpw.mods.modlauncher.Launcher.main(Launcher.java:77)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.0.7/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.0.7/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23)         at cpw.mods.bootstraplauncher@0.1.17/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:90) Caused by: com.electronwill.nightconfig.core.io.ParsingException: Not enough data available         at MC-BOOTSTRAP/com.electronwill.nightconfig.core@3.6.4/com.electronwill.nightconfig.core.io.ParsingException.notEnoughData(ParsingException.java:22)         at MC-BOOTSTRAP/com.electronwill.nightconfig.core@3.6.4/com.electronwill.nightconfig.core.io.ReaderInput.directReadChar(ReaderInput.java:36)         at MC-BOOTSTRAP/com.electronwill.nightconfig.core@3.6.4/com.electronwill.nightconfig.core.io.AbstractInput.readChar(AbstractInput.java:49)         at MC-BOOTSTRAP/com.electronwill.nightconfig.core@3.6.4/com.electronwill.nightconfig.core.io.AbstractInput.readCharsUntil(AbstractInput.java:123)         at MC-BOOTSTRAP/com.electronwill.nightconfig.toml@3.6.4/com.electronwill.nightconfig.toml.TableParser.parseKey(TableParser.java:166)         at MC-BOOTSTRAP/com.electronwill.nightconfig.toml@3.6.4/com.electronwill.nightconfig.toml.TableParser.parseDottedKey(TableParser.java:145)         at MC-BOOTSTRAP/com.electronwill.nightconfig.toml@3.6.4/com.electronwill.nightconfig.toml.TableParser.parseNormal(TableParser.java:55)         at MC-BOOTSTRAP/com.electronwill.nightconfig.toml@3.6.4/com.electronwill.nightconfig.toml.TomlParser.parse(TomlParser.java:44)         at MC-BOOTSTRAP/com.electronwill.nightconfig.toml@3.6.4/com.electronwill.nightconfig.toml.TomlParser.parse(TomlParser.java:37)         at MC-BOOTSTRAP/com.electronwill.nightconfig.core@3.6.4/com.electronwill.nightconfig.core.io.ConfigParser.parse(ConfigParser.java:113)         at MC-BOOTSTRAP/com.electronwill.nightconfig.core@3.6.4/com.electronwill.nightconfig.core.io.ConfigParser.parse(ConfigParser.java:219)         at MC-BOOTSTRAP/com.electronwill.nightconfig.core@3.6.4/com.electronwill.nightconfig.core.io.ConfigParser.parse(ConfigParser.java:202)         at MC-BOOTSTRAP/com.electronwill.nightconfig.core@3.6.4/com.electronwill.nightconfig.core.file.WriteSyncFileConfig.load(WriteSyncFileConfig.java:73)         at MC-BOOTSTRAP/com.electronwill.nightconfig.core@3.6.4/com.electronwill.nightconfig.core.file.AutoreloadFileConfig.load(AutoreloadFileConfig.java:41)         at MC-BOOTSTRAP/com.electronwill.nightconfig.core@3.6.4/com.electronwill.nightconfig.core.file.AutosaveCommentedFileConfig.load(AutosaveCommentedFileConfig.java:85)         at MC-BOOTSTRAP/fmlloader@1.18-38.0.14/net.minecraftforge.fml.loading.FMLConfig.loadFrom(FMLConfig.java:59)         ... 12 more C:\Users\namno\Desktop\Nobec>pause Press any key to continue . . . I have java 17 i dont know whats the problem  
    • Also note after updating you need to regenerate the gradle dependencies 
    • Use debugger to check which code is running and what the return values are
    • im trying to figure out how to change my mod's forge version but i cant seem to find the forge version in the build.gradle . build.gradle: buildscript { repositories { // These repositories are only for Gradle plugins, put any other repositories in the repository block further below maven { url = 'https://maven.minecraftforge.net' } mavenCentral() } dependencies { classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true } } apply plugin: 'net.minecraftforge.gradle' group = 'net.mikeyypants' version = '1.0-SNAPSHOT' java { archivesBaseName = 'TestMod' toolchain.languageVersion = JavaLanguageVersion.of(17) } minecraft { // The mappings can be changed at any time and must be in the following format. // Channel: Version: // snapshot YYYYMMDD Snapshot are built nightly. // stable # Stables are built at the discretion of the MCP team. // official MCVersion Official field/method names from Mojang mapping files // // You must be aware of the Mojang license when using the 'official' mappings. // See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md // // Use non-default mappings at your own risk. They may not always work. // Simply re-run your setup task after changing the mappings to update your workspace. mappings channel: 'official', version: '1.18' // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Default run configurations. // These can be tweaked, removed, or duplicated as needed. runs { client { workingDirectory project.file('run') // Recommended logging data for a userdev environment // The markers can be added/removed as needed separated by commas. // "SCAN": For mods scan. // "REGISTRIES": For firing of registry events. // "REGISTRYDUMP": For getting the contents of all registries. property 'forge.logging.markers', 'REGISTRIES' // Recommended logging level for the console // You can set various levels here. // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels property 'forge.logging.console.level', 'debug' mods { testmod { source sourceSets.main } } } server { workingDirectory project.file('run') // Recommended logging data for a userdev environment // The markers can be added/removed as needed separated by commas. // "SCAN": For mods scan. // "REGISTRIES": For firing of registry events. // "REGISTRYDUMP": For getting the contents of all registries. property 'forge.logging.markers', 'REGISTRIES' // Recommended logging level for the console // You can set various levels here. // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels property 'forge.logging.console.level', 'debug' mods { testmod { source sourceSets.main } } } data { workingDirectory project.file('run') // Recommended logging data for a userdev environment // The markers can be added/removed as needed separated by commas. // "SCAN": For mods scan. // "REGISTRIES": For firing of registry events. // "REGISTRYDUMP": For getting the contents of all registries. property 'forge.logging.markers', 'REGISTRIES' // Recommended logging level for the console // You can set various levels here. // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels property 'forge.logging.console.level', 'debug' // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. args '--mod', 'testmod', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') mods { testmod { source sourceSets.main } } } } } // Include resources generated by data generators. sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { // Put repositories for dependencies here // ForgeGradle automatically adds the Forge maven and Maven Central for you // If you have mod jar dependencies in ./libs, you can declare them as a repository like so: // flatDir { // dir 'libs' // } } dependencies { // Specify the version of Minecraft to use. If this is any group other than 'net.minecraft' it is assumed // that the dep is a ForgeGradle 'patcher' dependency, and its patches will be applied. // The userdev artifact is a special name and will get all sorts of transformations applied to it. minecraft 'net.minecraftforge:forge:1.18-38.0.8' // Real mod deobf dependency examples - these get remapped to your current mappings // compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency // runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}") // Adds the full JEI mod as a runtime dependency // implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency // Examples using mod jars from ./libs // implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}") // For more info... // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html // http://www.gradle.org/docs/current/userguide/dependency_management.html } // Example for how to get properties into the manifest for reading at runtime. jar { manifest { attributes([ "Specification-Title" : "testmod", //"Specification-Vendor": "testmod authors", "Specification-Version" : "1", // We are version 1 of ourselves "Implementation-Title" : project.name, "Implementation-Version" : project.jar.archiveVersion, //"Implementation-Vendor": "testmod authors", "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } } jar.finalizedBy('reobfJar')  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.