Jump to content

[1.12.2]Why does the Robot class mousePress not work?


DarkShuper

Recommended Posts

The mousePress of EntityLivingHandler's onPLayerLiving method is not processed.

Help me!:(

"if (InfinitelyTrade.flag == 1)" is working.

 

 

※ This post uses Google Translate.

 

InfinitelyTrade.java (Main class)

package com.infinitelytrade.infinitely_trade;

import org.lwjgl.input.Keyboard;

import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@Mod(modid = InfinitelyTrade.MODID, name = InfinitelyTrade.NAME, version = InfinitelyTrade.VERSION)
public class InfinitelyTrade
{
    public static final String MODID = "infinitely_trade";
    public static final String NAME = "InfinitelyTrade Mod";
    public static final String VERSION = "1.12.2-1.0";
    
    public static int flag = 0;

    @SideOnly(Side.CLIENT)
    public static final KeyBinding inputKey = new KeyBinding("KEY_J", Keyboard.KEY_J, "Auto Swing");
    
    @Mod.EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
    	//MinecraftForge.EVENT_BUS.register(new EntityLivingHandler());
    }
    
    @Mod.EventHandler
    public void init(FMLInitializationEvent event)
    {
    	if(event.getSide() == Side.CLIENT) {
    		ClientRegistry.registerKeyBinding(inputKey);
    	}
    	
    	FMLCommonHandler.instance().bus().register(this);
    }
    
    @SideOnly(Side.CLIENT)
    @SubscribeEvent
    public void inputKetEvent(InputEvent.KeyInputEvent event) {

    	if(this.inputKey.isPressed()) {
    		if(flag == 0) {
    		flag = 1;
    		}else if(flag == 1) {
    			flag = 0;
    		}
    	}
    }
}

 

EntityLivingHandler.java

package com.infinitelytrade.infinitely_trade.events;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;

import com.infinitelytrade.infinitely_trade.InfinitelyTrade;

import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.village.MerchantRecipe;
import net.minecraft.village.MerchantRecipeList;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@Mod.EventBusSubscriber
public final class EntityLivingHandler {

	@SubscribeEvent
	public static void onEntityLiving(LivingEvent.LivingUpdateEvent event) {
		if(event.getEntityLiving().getEntityWorld().isRemote) {
			return;
		}

		if(event.getEntityLiving() instanceof EntityVillager) {

			EntityVillager villager = (EntityVillager) event.getEntityLiving();
			EntityPlayer player = null;
			MerchantRecipeList list = villager.getRecipes(player);

			if(list != null) {

				for(Object obj : list) {
					MerchantRecipe recipe = (MerchantRecipe) obj;

					if(recipe.isRecipeDisabled())
						recipe.increaseMaxTradeUses(999999);
				}
			}
		}
	}

	@SubscribeEvent
	public static void onPlayerLiving(LivingEvent.LivingUpdateEvent event) {
		if(event.getEntityLiving().getEntityWorld().isRemote)
			return;
		
		Robot robot = null;
		
			try {
				robot = new Robot();
			} catch (AWTException e) {
				e.printStackTrace();
			}

		if(event.getEntityLiving() instanceof EntityPlayer) {

			EntityPlayer player = (EntityPlayer) event.getEntityLiving();

			float swing_speed = player.getCooledAttackStrength(0.0F);

			//if(swing_speed < 1.0F && InfinitelyTrade.flag == 1) {
			if(InfinitelyTrade.flag == 1) {
				//player.sendMessage(new TextComponentString("この関数は動作しています"));
				robot.mousePress(InputEvent.getMaskForButton(1));
				robot.mouseRelease(InputEvent.getMaskForButton(1));
			}
		}
	}

}

 

Link to comment
Share on other sites

6 hours ago, DarkShuper said:

    @SideOnly(Side.CLIENT)
    @SubscribeEvent
    public void inputKetEvent(InputEvent.KeyInputEvent event) {

    	if(this.inputKey.isPressed()) {
    		if(flag == 0) {
    		flag = 1;
    		}else if(flag == 1) {
    			flag = 0;
    		}
    	}
    }

Just because you put an @SubscribeEvent annotation on this method doesn't mean you've told Forge that this class is an event handler class.

6 hours ago, DarkShuper said:

		Robot robot = null;
		
			try {
				robot = new Robot();
			} catch (AWTException e) {
				e.printStackTrace();
			}

...


			if(InfinitelyTrade.flag == 1) {
				//player.sendMessage(new TextComponentString("この関数は動作しています"));
				robot.mousePress(InputEvent.getMaskForButton(1));
				robot.mouseRelease(InputEvent.getMaskForButton(1));
			}

No. Just no.

That is not how you use InputEvent. 

You're creating a new robot every tick.

I have no idea what the Robot class does, but I doubt that this is going to ever work.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

19 hours ago, Draco18s said:

Just because you put an @SubscribeEvent annotation on this method doesn't mean you've told Forge that this class is an event handler class.

No. Just no.

That is not how you use InputEvent. 

You're creating a new robot every tick.

I have no idea what the Robot class does, but I doubt that this is going to ever work.

Nah...InputEvent is working...

The problem is that mousePress is not working.

 

And the Robot class is a class for keyboard and mouse automation.

 

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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