porl Posted June 9, 2013 Posted June 9, 2013 Hi all Is there an easy way to allow my mod to modify the behaviour of blocks in general without modifying the base class? I want to be able to adjust speed depending on block type an entity is on (like soul sand). I saw the event onEntityCollidedWithBlock is used for soul sand, but can I hook that in the general case for all blocks? Also, if I can do this can I stop the soul sand's version of the event from triggering? I don't want to be having to modify soul sand as a special case if possible. Thanks for the help. Quote
endershadow Posted June 9, 2013 Posted June 9, 2013 actually, all you would need to do is give it a normal collision box. it's slightly lower than a normal block, hence why you sink into it. Quote
porl Posted June 10, 2013 Author Posted June 10, 2013 Is there a way to do this without editing the base class though? Quote
endershadow Posted June 10, 2013 Posted June 10, 2013 I think you can use reflection to replace the vanilla blocks with custom blocks, but that may cause incompatibilities with other mods if you change too much. Quote
porl Posted June 10, 2013 Author Posted June 10, 2013 Thanks, I'll look into that. I'm still learning about what can be done with reflection. Quote
endershadow Posted June 10, 2013 Posted June 10, 2013 I can help you with replacing vanilla blocks if you want. Quote
porl Posted June 10, 2013 Author Posted June 10, 2013 Any advice is always welcome! I'm trying to learn how to mod and I thought I'd do something that I wanted a while back. Basically I want to be able to make the "base speed" of different blocks variable - eg. stone is faster to move across than sand and so on. Would it be better to just replace the base classes since in theory I'd like it to be able to work with any block (from mods etc)? Quote
endershadow Posted June 10, 2013 Posted June 10, 2013 it would be better to extend the corresponding block class, and then replace the original block in Block.blocksList with the new one. Quote
porl Posted June 10, 2013 Author Posted June 10, 2013 Would that work if I want it configurable for every type of block though? Say for instance someone has a mod that adds hundreds of different blocks. I'd like to be able to have in a config file a list of block ids (or some way to reference them) and a speed multiplier that gets assigned to each block. Obviously the default would be one for all blocks but I imagine it would get quite messy if I was overriding many blocks (most of which I may not know about since they are from other mods). Am I missing some "easy" way that this would work with replacing them with the custom block? My understanding is that I am needing to override the onEntityCollidedWithBlock for all blocks. Is there another way to do this? Quote
Draco18s Posted June 10, 2013 Posted June 10, 2013 actually, all you would need to do is give it a normal collision box. it's slightly lower than a normal block, hence why you sink into it. Just FYI: There's two different functions going on here that result in Soul Sand's behavior. 1) Soul Sand's collision box is smaller than a full cube. This is required (minimum 1% smaller) for soul sand's effect to work 2) Soul Sand's on-collision function, which actually slows the player (cactus does damage, etc*). *Web actually works differently Quote 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.
Ernio Posted June 10, 2013 Posted June 10, 2013 You could use something close to event handler - i mean, do the tick and when block below you == something, then set player speed to something. I am sure I can find those methods, because I've been making a road block (sadly mine was full ModBlock so i used just call for EntityWalking or something like this, yours are vanilia ones, thats why you would need to use ticks). And other way is to of course make Reflection and stuff proposed before. Quote 1.7.10 is no longer supported by forge, you are on your own.
porl Posted June 10, 2013 Author Posted June 10, 2013 If I did it by tick would it be overridden by, say, the default soul sand behaviour? If I was to use reflection is there a way that I could keep it flexible enough that someone could put in a config something like MARBLE 1.2 where MARBLE is some block from a mod (that my mod has no knowledge of) and 1.2 is a speed? Obviously there may need to be another way to represent it but that's the basic idea I'm after. Thanks for all the advice guys, I really appreciate it. Quote
endershadow Posted June 10, 2013 Posted June 10, 2013 you could make it so they add the block ID followed by the speed in the config. Quote
porl Posted June 10, 2013 Author Posted June 10, 2013 That would be perfect but could that work (with other mods) using reflection? I can see how to do it easily (in theory anyway) if I can modify the block class (and the soul sand class to remove it's special case) but as that is a no-no I'd like to know how to do it properly but still keep the flexibility of someone being able to put in a block id of any block from any mod and the speed adjustment work. Quote
endershadow Posted June 10, 2013 Posted June 10, 2013 it should. maybe you can add attributes to it to modify the speed of the player? Quote
porl Posted June 10, 2013 Author Posted June 10, 2013 I think I'm confusing myself now. Using reflection, can I do this without actually changing the block for a custom block class? If I changed the block to a custom one I wouldn't be able to know what special functions/events etc the block I'm replacing would need (due to being possibly from another mod) so I don't think that would work. That's not a definitive statement by the way, I'm happy to be proven wrong. Quote
ObsequiousNewt Posted June 10, 2013 Posted June 10, 2013 I think I'm confusing myself now. Using reflection, can I do this without actually changing the block for a custom block class? If I changed the block to a custom one I wouldn't be able to know what special functions/events etc the block I'm replacing would need (due to being possibly from another mod) so I don't think that would work. That's not a definitive statement by the way, I'm happy to be proven wrong. >_> <_< Yes, but you shouldn't. Quote BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech.
porl Posted June 11, 2013 Author Posted June 11, 2013 Is there any "correct" way to do what I am wanting then? If the other methods are "dodgy" anyway then I think I'd prefer to go dodgy all the way and just modify the base classes but I'd like to do the right thing if possible. Quote
ObsequiousNewt Posted June 11, 2013 Posted June 11, 2013 The funny thing is, it seems like "block placed" and "block destroyed" are two of the most common and most wanted events, but I can't seem to find any sort of associated event. Which makes me think that it's some other, stupidly obvious method, which is why I'm afraid to post it on the hook suggestions, either for fear of "There's already a method stop bugging me lockban!" or "I'm going to implement one stop bugging me lockban!" Quote BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech.
porl Posted June 11, 2013 Author Posted June 11, 2013 I thought "lockban" was someone's name for a second there haha What are the actual problems with modifying a base class (other than it being incompatible if I were to change things too much)? In essence I am just adding one event method to all blocks so I assume that isn't the problem itself. Assuming no change I make has any issue with other mods that don't also modify the class itself (obviously if two mods both change the same file there would be issues) are there any other issues to watch for? Quote
ObsequiousNewt Posted June 11, 2013 Posted June 11, 2013 If you want to make such an event, you should actually submit a PR to Forge itself. I suspect many modders would want such an event. Funny actually, that Bukkit has one but Forge doesn't. Quote BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech.
porl Posted June 11, 2013 Author Posted June 11, 2013 I'm still not understanding how the event could override the soul-sand case without modifying base classes though. If there was a way to "unregister" the soul-sand "onEntityCollidedWithBlock" and register a hook for all blocks for "onEntityWalking" (and possibly "onEntityCollidedWithBlock" if necessary) then this would be ideal. Is this what you are suggesting I request the ability to do? Without the ability to remove the soul-sand's event I don't think it would work. Quote
endershadow Posted June 11, 2013 Posted June 11, 2013 in pull requests, you are able to modify base classes. that's how forge adds all of the abilities it adds. it modifies the original code. hence why you need to put minecraft forge in the jar file. Quote
porl Posted June 11, 2013 Author Posted June 11, 2013 Ah, I understand. What would the pull request involve though, in my case? I assume what I am trying to do isn't general enough to wind up in the forge core. Quote
Chibill Posted June 12, 2013 Posted June 12, 2013 Make your mod edit the players walkin speed NBT data Tag. Quote
Recommended Posts
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.