Jump to content

maxssho13

Members
  • Posts

    4
  • Joined

  • Last visited

Posts posted by maxssho13

  1. This is my first time making a mod in Minecraft so I'm a little bit of a noob when it comes to all of this. Just as a proof of concept I wanted to make a mod that would see a mathematical expression in the chat and then make my user type the answer back. I imported this library mX parser in order to evaluate the mathematical expression. It was all going well in my dev version and working just as I wanted, so I built the mod and put it into my mods folder. I was absolutely ecstatic to see that my game hadn't crashed but unfortunately when I got into the game and tested to see if it would work it didn't. I narrowed it to down to being an issue with the library just not evaluating the function but I'm not sure why. 

     

    This is the code:

    import net.minecraft.client.Minecraft;
    import net.minecraft.init.Blocks;
    import net.minecraftforge.client.event.ClientChatReceivedEvent;
    import net.minecraftforge.common.MinecraftForge;
    import net.minecraftforge.fml.common.FMLCommonHandler;
    import net.minecraftforge.fml.common.Mod;
    import net.minecraftforge.fml.common.Mod.EventHandler;
    import net.minecraftforge.fml.common.event.FMLInitializationEvent;
    import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
    import org.mariuszgromada.math.mxparser.Expression;
    import org.mariuszgromada.*;
    
    
    @Mod(modid = TestMod.MODID, version = TestMod.VERSION)
    public class TestMod {
    
    	public static final String MODID = "TestMod";
        public static final String VERSION = "1.0";
        @EventHandler
        public void init(FMLInitializationEvent event) {
            FMLCommonHandler.instance().bus().register(this);
            MinecraftForge.EVENT_BUS.register(this);
        }
        
        @SubscribeEvent
        public void onChat(ClientChatReceivedEvent event) throws Exception {
        	String message = event.message.getUnformattedText();
        	
        	if (message.contains("Solve: ")) {
        		String[] splitArr = message.split(": ",2);
        	    System.out.println(splitArr[1]);
        	    Expression e = new Expression(splitArr[1]);
        	    double result = e.calculate();
        	    double waitTime = Math.random()+1;
        	    Thread.sleep((long)waitTime*1000);
        	    if (result - (int)result == 0) {
        	    	
        	    	Minecraft.getMinecraft().thePlayer.sendChatMessage(String.valueOf((int)result));
        	    } else {
        	    	Minecraft.getMinecraft().thePlayer.sendChatMessage(String.valueOf(result));
        	    }
        	}
        }
    }

     

  2. This is my first time making a mod in Minecraft so I'm a little bit of a noob when it comes to all of this. Just as a proof of concept I wanted to make a mod that would see a mathematical expression in the chat and then make my user type the answer back. I imported this library mX parser in order to evaluate the mathematical expression. It was all going well in my dev version and working just as I wanted, so I built the mod and put it into my mods folder. I was absolutely ecstatic to see that my game hadn't crashed but unfortunately when I got into the game and tested to see if it would work it didn't. I narrowed it to down to being an issue with the library just not evaluating the function but I'm not sure why. 

     

    This is the code:

    import net.minecraft.client.Minecraft;
    import net.minecraft.init.Blocks;
    import net.minecraftforge.client.event.ClientChatReceivedEvent;
    import net.minecraftforge.common.MinecraftForge;
    import net.minecraftforge.fml.common.FMLCommonHandler;
    import net.minecraftforge.fml.common.Mod;
    import net.minecraftforge.fml.common.Mod.EventHandler;
    import net.minecraftforge.fml.common.event.FMLInitializationEvent;
    import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
    import org.mariuszgromada.math.mxparser.Expression;
    import org.mariuszgromada.*;
    
    
    @Mod(modid = TestMod.MODID, version = TestMod.VERSION)
    public class TestMod {
    
    	public static final String MODID = "TestMod";
        public static final String VERSION = "1.0";
        @EventHandler
        public void init(FMLInitializationEvent event) {
            FMLCommonHandler.instance().bus().register(this);
            MinecraftForge.EVENT_BUS.register(this);
        }
        
        @SubscribeEvent
        public void onChat(ClientChatReceivedEvent event) throws Exception {
        	String message = event.message.getUnformattedText();
        	
        	if (message.contains("Solve: ")) {
        		String[] splitArr = message.split(": ",2);
        	    System.out.println(splitArr[1]);
        	    Expression e = new Expression(splitArr[1]);
        	    double result = e.calculate();
        	    double waitTime = Math.random()+1;
        	    Thread.sleep((long)waitTime*1000);
        	    if (result - (int)result == 0) {
        	    	
        	    	Minecraft.getMinecraft().thePlayer.sendChatMessage(String.valueOf((int)result));
        	    } else {
        	    	Minecraft.getMinecraft().thePlayer.sendChatMessage(String.valueOf(result));
        	    }
        	}
        }
    }

     

×
×
  • Create New...

Important Information

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