Jump to content

Recommended Posts

Posted

(Look at bottom for solution)

 

I have been using attributes to modify player health / speed. But I have ran into an issue, if the player already has the same attribute instance with a modifier, and I try to apply mine, it will crash. I have been able to dig into the code to figure out if an attribute has already been applied. If it isn't applied, I apply my own new attribute, if not I need to modify the existing one, the problem is I don't know how to do this last part even after looking at the attribute classes / code for the longest time. Hopefully someone here is more knowledgeable than me in this subject and would be willing to help me. here is a segment of code that I am working with.

 

final AttributeModifier speed1 = new AttributeModifier(player.getPersistentID(), "Emblem Speed Boost", 0.25D, 1);

AttributeInstance attributeinstance = player.func_110148_a(SharedMonsterAttributes.field_111263_d);
		if(attributeinstance.func_111127_a(speed1.func_111167_a())!= null){

			//The modifier for the modifier needs to be in this clause!
			System.out.println("Conditions are true");
		}
		else{
			System.out.println("Conditions are NOT true");
		attributeinstance.func_111121_a(speed1);
		}

 

Thanks in advance.

 

~Noah

This is the creator of the Rareores mod! Be sure to check it out at

Posted

Can anyone help me out? I don't have much time on my hands to mod recently and this is the only thing keeping me from releasing my final version of my mod.

This is the creator of the Rareores mod! Be sure to check it out at

Posted

Okay, so after tinkering around with the above mentioned function, I found out that it does modify an attribute. After this I quickly got started on using it. But ran into a weird error that I can't seem to figure out. The conditionals determine if a new one should be added, or if it should be modified. But for some reason the player start going about 50x faster than he should and I don;t know why. I use a hashmap to keep data for each player if he should loose the attribute or not.

 

My code

 

PlayerTickhandler
________________________________________________________________
public HashMap<String, Integer> useMap = new HashMap<String, Integer>();

if(useMap.get(player.username) == null){
            useMap.put(player.username, 0);
        }

if(player.inventory.hasItem(mod_rareores.ItemEmblemSpeed.itemID) && useMap.get(player.username) == 0){
		AttributeInstance attributeinstance = player.func_110148_a(SharedMonsterAttributes.field_111263_d);
		if(attributeinstance.func_111127_a(speed1.func_111167_a())!= null){
			attributeinstance.func_111128_a(1.25);
			useMap.put(player.username,1 );
			System.out.println("Part1works 1");
		}
		else if(attributeinstance.func_111127_a(speed1.func_111167_a())== null){
		attributeinstance.func_111121_a(speed1);
		useMap.put(player.username,1 );
		System.out.println("Part1works 2");
		}

		player.jumpMovementFactor *=1.25;

	}
	if(!player.inventory.hasItem(mod_rareores.ItemEmblemSpeed.itemID) && useMap.get(player.username) == 1){
		AttributeInstance attributeinstance = player.func_110148_a(SharedMonsterAttributes.field_111263_d);
		attributeinstance.func_111128_a(0.;
		useMap.put(player.username,0 );
		System.out.println("Part2works");
	}

This is the creator of the Rareores mod! Be sure to check it out at

Posted

All I know is that you can set the player's walk speed with a simple call to

		thePlayer.capabilities.setPlayerWalkSpeed(float)

Default value is 0.1F.

I know that this may have the side effect of a FOV change but I guess that is all right since the player is running... fast... :)

Posted

All I know is that you can set the player's walk speed with a simple call to

		thePlayer.capabilities.setPlayerWalkSpeed(float)

Default value is 0.1F.

I know that this may have the side effect of a FOV change but I guess that is all right since the player is running... fast... :)

 

Isn't this just client side though?

This is the creator of the Rareores mod! Be sure to check it out at

Posted

well specificly "thePlayer" is a field in Minecraft class .. but obviously theres also a couple of place were you can have reference to EntityPlayer objects

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

If you use it on the server, even with an instance of entityplayer, you get a java.lang.NoSuchMethodError , AKA it's not serverside

This is the creator of the Rareores mod! Be sure to check it out at

  • 3 weeks later...
Posted

Okay so I pushed this aside for awhile to get other things done, but this is the last thing I need to do. Can anyone help?

This is the creator of the Rareores mod! Be sure to check it out at

Posted

Okay so I pushed this aside for awhile to get other things done, but this is the last thing I need to do. Can anyone help?

 

What are you trying to do?

If you want a player obj on the server side you will need to specify at which time you need to get that player obj, then we can tell you which method to use. If it's a the time of something happening on the client side (aka. keypress for example) then you will need to send a packet from C to S which then the server can use to do things to the player.

If you guys dont get it.. then well ya.. try harder...

Posted

final AttributeModifier speed1 = new AttributeModifier(player.getPersistentID(), "Emblem Speed Boost", 0.25D, 1);

The last int argument deals with how the modifier is applied. Its range is in [0..2].

Either an added value, a multiplier, or an added multiplier.

Example:

choose 2 to apply a (1+0.25D) multiplier to the speed value.

 

You can use

attributeinstance.func_111124_b(AttributeModifier)

to remove a modifier.

Posted

Read the OP, I want the players speed to be modified when a player has an item, but if the player already has a speed attribute then I want to modify the existing attribute instead of over-writing it.

This is the creator of the Rareores mod! Be sure to check it out at

Posted

This is what i meant.

Remove the modifier, then apply it again with a new value.

 

Or apply another modifier.

 

Or calculate the complete modified value with

old = attributeInstance.func_111125_b();

and change it with

attributeInstance.func_111128_a(old*change);

 

There is currently no supported way to modify a part of the modifier in the applied collection.

You'll probably end up with a concurrent modification exception if you force it through reflection.

Posted

So essentially the attribute system sucks balls? Back in 1.5 I just needed ONE LINE OF CODE do do what I wanted, and now 60 lines only does it crudely. Would there be ANY way to modify player speed dynamically? Like if a different mod has the player speed at 1.5 times and I want to multiply it by 1.3 lets say, it will go upto 1.5 * 1.3 = 1.95. But doing it my previous way makes it so it removes the old modifier and replaces it with my new one so say 1.5 (/) to 1.3. Would it be possible if I could make my own specific mod attribute and not use vanilla ones, or is there some code elsewhere that modifies player speed? Because What Im doing now and what I was doing earlier is NOT going to work!

This is the creator of the Rareores mod! Be sure to check it out at

Posted

Keep in mind that the system is not only new, it's also a work in progress.

This is one of many steps needed towards the API they are working on.

If you guys dont get it.. then well ya.. try harder...

Posted

Keep in mind that the system is not only new, it's also a work in progress.

This is one of many steps needed towards the API they are working on.

 

Okay I understand that, but how Am I going to modify player speed then, I just can't remove the item, and IM not going to use potioneffects.

This is the creator of the Rareores mod! Be sure to check it out at

Posted

Man, if you want to keep it simple and don't care about modifiers,

AttributeInstance oldSpeed = player.func_110148_a(SharedMonsterAttributes.field_111263_d);
oldSpeed.func_111128_a(oldSpeed.func_111125_b()*change);

that is all.

Posted

found a much better way (At least IMHO)

if(player.inventory.hasItem(mod_rareores.ItemEmblemFlight.itemID) && useMap2.get(player.username) == 0){

		PlayerCapabilities cap = ObfuscationReflectionHelper.getPrivateValue(EntityPlayer.class, player, "capabilities", "field_71075_bZ");
		float speed = player.capabilities.getWalkSpeed();
		speed *=1.5;
		ObfuscationReflectionHelper.setPrivateValue(PlayerCapabilities.class, cap, speed ,"walkSpeed", "field_73357_f");
		useMap2.put(player.username,1 );

	}
	if(!player.inventory.hasItem(mod_rareores.ItemEmblemFlight.itemID) && useMap2.get(player.username) == 1){
		PlayerCapabilities cap = ObfuscationReflectionHelper.getPrivateValue(EntityPlayer.class, player, "capabilities", "field_71075_bZ");
		float speed = player.capabilities.getWalkSpeed();
		speed /=1.5;
		ObfuscationReflectionHelper.setPrivateValue(PlayerCapabilities.class, cap, speed ,"walkSpeed", "field_73357_f");
		useMap2.put(player.username,0 );
	}

This is the creator of the Rareores mod! Be sure to check it out at

Posted

Why anyone would change code and turn it into "work in progress" state, and thus increasing the amount of code used, is completely over my head. You're not supposed to change a running system...and you're specifically not supposed to change a running system wihtout proper documentation.

 

And don't even get me started about how you guys see new code as opportunity to make everything "easier and better".

 

Why would you change player.landMovementFactor to private and don't replace it with something proper and easy to use in the first place? That's just rubbish.

Posted

There's plenty of documentation for the Minecraft code, as well as proper names for everything and a lot of other things. All of this is provided by Mojang for the programmers working on the Minecraft project :P

 

Why anyone would change code and turn it into "work in progress" state, and thus increasing the amount of code used, is completely over my head.

Because the "wip" state is not noticeable for the end users.

The users will never see or know of how the code looks between 1.5 and 1.6 all they know are new features.

Therefore I see no problem in doing things this way :P

If you guys dont get it.. then well ya.. try harder...

Posted

New features are good, but why remove code that's already properly working?

To make it better, and minecraft's code needs A LOT of work in that regard.

 

Without changing over to the attribute system, the modding API would not be possible.

These changes are towards a bigger goal, and to be honest the Attribute system isn't that bad once you are used to it.

 

One at a time these changes may seem weird and just made to make a modders job tedious for no good reason, but if you look at it from a different standpoint the code is slowly being made into something which is easily expandable and therefore opens up a lot of possibilities for us as modders ;)

If you guys dont get it.. then well ya.. try harder...

Posted

Yeah, for now I was able to find something that worked, but one day when they document the attribute system and finish it up it will be alot nicer to work with.

This is the creator of the Rareores mod! Be sure to check it out at

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 am trying to make a mod, all it is, a config folder that tells another mod to not require a dependency, pretty simple right.. well, I dont want whoever downloads my mod to have to download 4 other mods and then decide if they want 2 more that they kinda really need.. i want to make my mod basically implement all of these mods, i really dont care how it does it, ive tried putting them in every file location you can think of, ive downloaded intellij, mcreator, and tried vmware but thats eh (had it from school). I downloaded them in hopes theyd create the correct file i needed but honestly im only more lost now. I have gotten my config file to work, if i put all these mods into my own mods folder and the config file into the config and it works (unvbelievably) but i want to share this to everyone else, lets just say this mod will legitimately get 7M downloads.  I tried putting them in a run folder then having it create all the contents in that for a game (mods,config..etc) then i drop the mods in and all the sudden i cant even open the game, like it literally works with my own world i play on, but i cant get it to work on any coding platform, they all have like built in java versions you cant switch, its a nightmare. I am on 1.20.1 I need Java 17 (i dont think the specific versions of 17 matter) I have even tried recreating the mods i want to implement and deleting import things like net.adamsandler.themodsname and replacing it with what mine is. that only creates other problems, where im at right now is i got the thing to start opening then it crashes, closest ive gotten it, then it just says this  exception in thread "main" cpw.mods.niofs.union.unionfilesystem$uncheckedioexception: java.util.zip.zipexception: zip end header not found caused by: java.util.zip.zipexception: zip end header not found basically saying theres something wrong with my java.exe file, so i tried downloading so many different versions of java and putting them all in so many different spots, nothing, someone online says its just a mod that isnt built right so i put the mod into an editor and bunch of errors came up, id post it but i deleted it on accident, i just need help integrating mods
    • Vanilla 1.16.5 Crash Report [#L2KYKaK] - mclo.gs  
    • Hello, probably the last update, if anyone has the same problem or this can be of any help, the answer was pretty simple, textures started rendering just using a Tesselator instead of a VertexConsumer given by a MultibufferSource and a RenderType, pretty simple
    • Finally circling back to this, and I think all of us were half right.  getChunk() does appear to immediately load the chunk, but what changed between 1.16 and 1.18 is that the list of entities is now stored in the server, not per chunk.  So while it was possible to load a chunk in 1.16 and immediately grab an entity out of it, 1.18 loads the chunk and submits a request to load its entities on the next tick (if I understand correctly).  All this to say, you can immediately access the chunk itself, however you have to wait an additional tick for its entities to load in. In my case what this means is that I do have to set up an interface to wait an additional tick before submitting the request to retrieve the entity.  However, other functions do appear to be available immediately.  Just depends on what you're trying to do. Thank you all for the help! 
    • I've already tried it without mods and it works.
  • Topics

×
×
  • Create New...

Important Information

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