Jump to content

clubmax27

Members
  • Posts

    2
  • Joined

  • Last visited

Recent Profile Visitors

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

clubmax27's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Yes I am doing a client-only mod, it only checks if the player takes damage, and what amout of damage Thanks to DavidM, I managed to get it working, but now I have a second, more complicated problem. I'm now using LivingAttackEvent event to detect when i take damage, I check if the entity taking damage is my own character, and then I log the amout of damage taken. This method works great with all "singleplayer" methods of taking damage, like fall damage, mobs, fire ... But when an other player hits me, the amout of damage that LivingAttackEvent logs is 0.0 damage, even with a diamond sword. Is that a bug from forge or am I doing this wrong ? Here's the code i'm using : @SubscribeEvent public void onEntityAttacked(LivingAttackEvent event) { if (event != null && event.getEntity() != null) { Entity victimentity = event.getEntity(); Entity sourceentity = event.getSource().getTrueSource(); String playerName = ""; playerName = (String)(victimentity.getDisplayName().getString()); if (victimentity.getDisplayName().getString().equals("Superburger90")) { System.out.println("Player attacked ! damage : " + event.getAmount()); } } }
  2. Hello, this is my first try at making a mod on Minecraft, and I'm facing a problem. I'm using forge's 1.16.1 example mod that i modified to suit my needs. My mod is very simple, I just want to execute some code when the player takes damage. For that, I'm using the LivingDamageEvent event, and it works exactly as i want in singleplayer. However, when I join a multiplayer server, it seems like my mod is turned off automatically for some reason. The FMLServerStartingEvent doesn't trigger because I don't see anything in the launcher_log.txt after I close minecraft, and same for LivingDamageEvent. Is there a reason for that ? Here's the code i'm using, it's just a modified version of forge's example mod : package com.example.examplemod; import net.minecraft.block.Blocks; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingDamageEvent; import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import java.io.IOException; import java.io.InputStream; import java.net.URL; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; // The value here should match an entry in the META-INF/mods.toml file @Mod("examplemod") public class examplemod { // Directly reference a log4j logger. private static final Logger LOGGER = LogManager.getLogger(); public examplemod() { // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); // Register the doClientStuff method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { // some preinit code LOGGER.info("HELLO FROM PREINIT"); LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName()); } @SuppressWarnings("resource") private void doClientStuff(final FMLClientSetupEvent event) { // do something that can only be done on the client LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings); } // You can use SubscribeEvent and let the Event Bus discover methods to call @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { // do something when the server starts LOGGER.info("HELLO from server starting"); } public class MyForgeEventHandler { @SubscribeEvent public void pickupItem(EntityItemPickupEvent event) { System.out.println("Item picked up!"); } } @SubscribeEvent public void onPlayerHurt(LivingDamageEvent event) throws IOException { System.out.println("Player attacked ! damage : " + event.getAmount()); #Execute some code here ... } }
×
×
  • Create New...

Important Information

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