Jump to content

Can someone explain to me what 'events' are? [SOLVED]


EliteCreature

Recommended Posts

It's a big question. Maybe anyone has his own opinion. I'm trying to talk about mine.

 

'Event' is something that happened or is happening. When the zombie hit you, it's an event(And we would know that it's LivingAttackEvent and LivingHurtEvent).

 

As the mod required, you may want to know about what event is happenning. If we want to make zombie very very strong, we can catch the 'event' that when the damage is count(LivingHurtEvent), and change the damage to make the zombie stronger(there is other way to do this of course). Or we could apply special effect to the player when he's hit by zombie. To know when the player is hit, you need events.

 

And many other events, like LivingDeathEvent. To catch this event allow you to do something when someone(Zombie, Player or other living) died. And do something you want after this, like bury them. To know when someone die, you need events.

 

To catch the event, add an annotation before the method, and register it. The class is as below.

 

public class EventTest {
@ForgeSubscribe(priority = EventPriority.LOW,receiveCanceled = true)
public void test1(LivingFallEvent event)
{
    if(event.entityLiving instanceof EntityPlayer)
    {
        EntityPlayer entityPlayer = (EntityPlayer)event.entityLiving;
        entityPlayer.sendChatToPlayer(ChatMessageComponent.func_111066_d("Falling Star!You fell "+event.distance+ " meters.That's cool,man!");
    }
}
}

 

And registe it with

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

 

So when someone fall to the ground, he will receive a message how far he fall.

 

And you can set event.distance to 0.0f or 24.f to get rid of the falling damage or make the player die when fall, no matter how far he falls.

 

And there are many feature of event, like result, priority, cancelable and so on.

Maybe you should figure it out yourself.

Link to comment
Share on other sites

Hi

 

Forge events are a way for the vanilla+forge code to call your code when something happens.  This lets you customise the game behaviour without having to modify the vanilla code yourself.

 

For example - PlayerSleepInBedEvent

If you register a listener for this event (say thePlayerSleptInBed()), then your method thePlayerSleptInBed will be called whenever a player sleeps in a bed.

 

Forge uses a bit of a mishmash of events, handlers, hooks, and other techniques to enable your code to get itself called when particular things happen.  Events is just one of those.

 

A useful link:

http://www.minecraftforge.net/wiki/Event_Reference

 

-TGG

Link to comment
Share on other sites

Another thing to note is that events is NOT a forge concept.

Events is a programming concept, as are much of the confusing forge and minecraft stuff.

It's a good idea to search around for general peogramming information on such concepts as well as to learn about the specifics of forge ;)

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Ho installato Forge 1.20.2, ho cliccato col tasto sinistro due volte su installer.jar, non si apre e crea solo un file .log Il file contiene: JVM info: Oracle Corporation - 1.8.0_401 - 25.401-b10 java.net.preferIPv4Stack=true Current Time: 27/02/2024 18:18:10 Host: files.minecraftforge.net [51.79.83.165] Host: maven.minecraftforge.net [51.79.83.165] Host: libraries.minecraft.net [13.107.213.45, 13.107.246.45] Host: launchermeta.mojang.com [13.107.246.45, 13.107.213.45] Host: piston-meta.mojang.com [13.107.246.45, 13.107.213.45] java.net.UnknownHostException: authserver.mojang.com     at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)     at java.net.InetAddress$2.lookupAllHostAddr(Unknown Source)     at java.net.InetAddress.getAddressesFromNameService(Unknown Source)     at java.net.InetAddress.getAllByName0(Unknown Source)     at java.net.InetAddress.getAllByName(Unknown Source)     at java.net.InetAddress.getAllByName(Unknown Source)     at net.minecraftforge.installer.DownloadUtils.getIps(DownloadUtils.java:290)     at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:120) Exception in thread "main"  java.lang.NullPointerException     at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:120)
    • Suddenly the installer stopped working, both forge and neoforge, I've tested it on almost all versions of java and it didn't solve my problem.] Here is the log that appears after trying to open the file: JVM info: Oracle Corporation - 21.0.2 - 21.0.2+13-LTS-58 java.net.preferIPv4Stack=true Current Time: 27/02/2024 13:55:14 Host: maven.neoforged.net [172.67.165.187, 104.21.89.226] Host: libraries.minecraft.net [13.107.246.33, 13.107.213.33] Host: launchermeta.mojang.com [13.107.246.33, 13.107.213.33] Host: piston-meta.mojang.com [13.107.246.33, 13.107.213.33] java.net.UnknownHostException: Este host nᅢᆪo ᅢᄅ conhecido (authserver.mojang.com)     at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)     at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:52)     at java.base/java.net.InetAddress$PlatformResolver.lookupByName(InetAddress.java:1211)     at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1828)     at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:1139)     at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1818)     at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1688)     at net.minecraftforge.installer.DownloadUtils.getIps(DownloadUtils.java:296)     at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:124) Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.util.List.stream()" because the return value of "net.minecraftforge.installer.DownloadUtils.getIps(String)" is null     at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:124)   If anyone knows how to solve this please tell me.
  • Topics

×
×
  • Create New...

Important Information

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