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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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