Posted September 22, 201510 yr I so im trying to make a counter that will go up when you do certain tasks so right now I've only set it to count up when water is scooped into a bucket, after getting 5 water buckets the player will gain enhanced movement speed. The problem is when I create a new world the player in the new world also has the enhanced movement speed without completing the task, this is because the counter does not reset for the new world my question is how do I get this counter to reset thx! Event Handler Code: public class EMEventHandler { private int counter = 0; public World world; @SubscribeEvent public void bucketUse(FillBucketEvent event) { if (event.entityPlayer.getHeldItem().getItem() == Items.water_bucket) { counter++; System.out.println(counter); } } @SubscribeEvent public void counterUpdateEvent (LivingUpdateEvent event) { if (event.entity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer)event.entity; if(counter >= 5) { player.capabilities.setPlayerWalkSpeed(0.2F); } } } } Main Class Code: public class MMod { public static final String version = "0.01"; EMEventHandler eventhandler = new EMEventHandler(); @EventHandler public void preInit(FMLPreInitializationEvent event) { //some use FML bus FMLCommonHandler.instance().bus().register(eventhandler); //most events use MinecraftForge event bus MinecraftForge.EVENT_BUS.register(eventhandler); } @EventHandler public void init(FMLInitializationEvent event) { } @EventHandler public void postInit(FMLPostInitializationEvent event) { } }
September 22, 201510 yr Explanation: There is one instance of event handler class per game. All fields are shared between worlds and players. What you want/need: (guide) 1. Make sure you know good amount of java before starting (I am not taking about "I know what a for-loop is.") 2. To make it work on per-player basis you need to use IExtendedEntityProperties (IEEP). 3. After making your IEEP implementation, you need to assign it to player via EntityConstructing event. Note: IEEP is an object assigned to entity that can hold its own fields (e.g your counter). Note 2: MC has 2 logical sides: Server and client - every thread has its own enitity (meaning there are two EntityPlayers for each player). Same goes for EntityConstructing event - it will fire for both players and assign IEEP to each of them. That's why you need to synchronize those if you need client to also know what server knows. Tutorials: IEEP: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571567-1-7-2-1-6-4-eventhandler-and Packets: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2137055-1-7-x-1-8-customizing-packet-handling-with http://www.minecraftforge.net/forum/index.php/topic,20135.0.html 1.7.10 is no longer supported by forge, you are on your own.
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.