Jump to content

Recommended Posts

Posted

Hey guys,

 

I've finished a class which be used to count killings.

 

package com.practise.request;


import net.minecraft.entity.passive.EntityChicken;
import net.minecraft.init.Items;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class KillingRequest {
public int KillingNumbers = 0;
public boolean ifFinished = false;

public KillingRequest() {
	FMLCommonHandler.instance().bus().register(this);
	MinecraftForge.EVENT_BUS.register(this);
}

@SubscribeEvent
public void KillingCount(LivingDeathEvent event){
	System.out.println("position.1,the killingNumbers is "+KillingNumbers);
	if((event.entity instanceof EntityChicken)){
		System.out.println("position.2,the killingNumbers is "+KillingNumbers);
		KillingNumbers += 1;
		System.out.println("position.3,the killingNumbers is "+KillingNumbers);
		if(KillingNumbers >= 5)
			ifFinished = true;

	}
}	
}

 

 

However, in the game, as soon as I kill a chicken, the console gives me this:

 

 

[16:03:41] [server thread/INFO]: Player483 joined the game

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:23]: position.1,the killingNumbers is 0

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:25]: position.2,the killingNumbers is 0

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:27]: position.3,the killingNumbers is 1

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:23]: position.1,the killingNumbers is 0

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:25]: position.2,the killingNumbers is 0

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:27]: position.3,the killingNumbers is 1

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:23]: position.1,the killingNumbers is 0

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:25]: position.2,the killingNumbers is 0

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:27]: position.3,the killingNumbers is 1

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:23]: position.1,the killingNumbers is 0

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:25]: position.2,the killingNumbers is 0

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:27]: position.3,the killingNumbers is 1

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:23]: position.1,the killingNumbers is 0

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:25]: position.2,the killingNumbers is 0

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:27]: position.3,the killingNumbers is 1

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:23]: position.1,the killingNumbers is 0

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:25]: position.2,the killingNumbers is 0

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:27]: position.3,the killingNumbers is 1

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:23]: position.1,the killingNumbers is 0

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:25]: position.2,the killingNumbers is 0

[16:03:51] [server thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:27]: position.3,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:23]: position.1,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:25]: position.2,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:27]: position.3,the killingNumbers is 2

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:23]: position.1,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:25]: position.2,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:27]: position.3,the killingNumbers is 2

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:23]: position.1,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:25]: position.2,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:27]: position.3,the killingNumbers is 2

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:23]: position.1,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:25]: position.2,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:27]: position.3,the killingNumbers is 2

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:23]: position.1,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:25]: position.2,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:27]: position.3,the killingNumbers is 2

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:23]: position.1,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:25]: position.2,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:27]: position.3,the killingNumbers is 2

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:23]: position.1,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:25]: position.2,the killingNumbers is 1

[16:03:51] [Client thread/INFO] [sTDOUT]: [com.practise.request.KillingRequest:KillingCount:27]: position.3,the killingNumbers is 2

[16:03:55] [server thread/INFO]: Saving and pausing game...

 

Does it mean I trigger this method several times when I kill only one chicken?

Posted

Death != Kill

 

Subscribing to events mean you listen to all such events. IN this case - you are listening to whenever EntityLivingBase dies (on client and on server).

 

What you need to do is to make it player specific.

 

1. Implement http://mcforge.readthedocs.io/en/latest/datastorage/capabilities/ in order to store killings and progress in player (and his NBT).

2. In event - check event.source.getEntity() - if it exist and is player, get that player's capability and increment kill.

3. Obviously, if you want more than one kill tracker you have to hold some lists.

4. This all is harder than you seem to be thinking (seeing your code, you don't really know much about internals).

1.7.10 is no longer supported by forge, you are on your own.

Posted

I read the document and checked my reference library, cannot find a package called "capabilities".

 

My forge version is 1.8, can use something else instead?

Posted

Don't vanilla stats already count all kills by each player?

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

You could use

IEntityExtendedProperties

, but you should just update. 1.8 is EOL.

It's IExtendedEntityProperties.

 

Don't vanilla stats already count all kills by each player?

It does, but only globals and all-time. If one want to start from some point, it's kinda useless (well, you can use time-stamp-like "kill-stamps").

 

And yeah - you should update to 1.8.9+ (and use capabilities)

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.

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.