#Messing with DamageTypes
206 messages · Page 1 of 1 (latest)
See the attack method in PlayerEntity
I've been looking around the attack method in PlayerEntity for a while now, but I do not see where it is declaring the damageType
I will do some searching around other classes to see if I can find specifically where it is declared
It's there
Is that not just a boolean that checks if the damage is originating from the attacking entity?
target.damage actually does something
All the boolean is there for is to check if the damage actually succeeded
Oh, alright then
So to recap, PlayerEntityMixin with an if checking for the enchantment, then target.damage(this.getDamageSources(DamageTypeClass.DAMAGE_TYPE), damage_float);
Okay, I have begun to see this task as a bit silly and not entirely sensible
However I have a new goal that 1) may be more attainable, and 2) may be able to be done in just the enchantment class
What about instead of changing the entire damage type of the weapon, I add extra damage (of a different damage type) on top of the regular attack damage
Say a diamond sword with the Enchantment FlameBound did the regular 7 playerAttack damage but also did 3 flameMagic damage on top of it?
This one is fine
Just modifyarg the damage call
Alright
Just to bring up what I said a few minutes ago, how feasible would it be to add more damage onto a weapon of a different type?
Probably modify the damage_float and subtract EnchantmentHelper.getattackdamage or whatever from it
Then add a new damage call and make the damage EnchantmentHelper.getattackdamage
Alright, I'll get both working (hopefully) and see which one I prefer
And as always, thank you for helping
I really hate to ping, but I still need some help. I have been unable to get the original plan working (changing the damage type when striking with the enchantment), but I would much rather divert my time to working on the new plan (adding extra damage of a new damage type). I hate to say this, but your earlier message (the one I am replying to) confuses me a bit. Could you explain it a bit differently for me, please?
Whenever you're back, this is what I've got so far and it does not work as intended
Since it looks like I'm not sleeping tonight I will keep at it
Decided to make some attributes revolving around the damage types, might make things a bit easier as well as a bit more satisfying with the interface
I've gotten some more done and it does something?
I know it did something as before I fixed an error it would crash the game when hitting a mob (it no longer crashes)
Plan 1:
@ModifyExpressionValue(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/damage/DamageSources;playerAttack(Lnet/minecraft/entity/player/PlayerEntity;)Lnet/minecraft/entity/damage/DamageSource;"))
private DamageSource weDoSomeChanging(DamageSource original){
if (EnchantmentHelper.getLevel(someEnchantment, yourStack) > 0) {
return this.getWorld().getDamageSources().magic(); // or something
}
return original;
}
What I did here is modify the player attack to another damage source when a certain condition is true
Do you want the damage to be proportional?
And you would probably need to reset the iframes before you applied the second damage
Well, it is good to see it done proper. Thank you for helping out on that end
So far my plan now is to add an attribute, which has been done, and then apply the attribute to the item
Messed around with inventoryTick for a bit before I passed out
Also with attack
Aaaand I broke something, reading the crash log hasn't helped much but I wonder if it is because I used @Inject, rather than @ModifyExpressionValue as you have taught me
First, you don't have to store the value in a boolean
Because you aren't going to do anything with the return value
Oh?
This one you don't need because you'll probably just account for the enchantment during the damage calculation
Yeah you can just call target.damage
But you'll have to reset the iframes afterward or else the regular damage isn't going to be applied correctly
Ohh, I suppose I was just trying to mimic the vanilla target.damage boolean
Yeah but vanilla actually does checks with that boolean, you don't which means you don't need that variable
Alright, based off of the crash log it is the modifyInventoryTick that caused the crash in the first place
Alright, thank you
I've put the damage type in the vanilla tag bypasses_cooldown.json, but it has not made the damage pass through iframes
That's because you're injecting at the getAttributeValue which means that the vanilla damage call is done after yours
Oh, hm
The easy fix for that is to reset the regen time and lastDamageTaken after you do the damage call
but that might lead to unintended consequences
Alright, can I do that within the WcmPlayerEntityMixin class or would I require a new class?
Oh? What would those unintended consequences be?
It's just a class, so you can add as many (handler) methods as you want
This would also make the regular damage bypass iframes
The field is inherited from LivingEntity I think
Oh alright
This one was for converting all damage to another damage type, but it doesn't seem like what you were going for
Yeah, it was the inital idea, and I thank you for getting it to function, but I came to the understanding that changing the entire damage type was a bit silly
If you were hit with a sword with an enchantment that changed the damage type to a fire damage type, but you were immune to fire, don't you think you'd still be hurt by the very physical sword?
All regular damage? Or just the sword's damage
I meant the damage dealt when you take damage and the condition that removes the iframes is true
So therefore attacks of the sword would bypass all iframes
Until then I suppose I will go for your idea, in the end it shouldn't be the biggest deal? (especially if I don't tell anyone about it c;)
And even if people find out they won't be doing insane amounts of damage
All this hassle has been over at most 3.5 extra damage
Wait, should I utilize the damage method or the onDamaged method in the LivingEntity class?
I suppose damage would make more sense
I got the iframe reset working! Buuut it isn't applying the damage, but I am certain I will be able to figure out why
I suppose I do not really need the attributes anymore, which is unfortunate as I thought it would be cool to have them. But if they are unneeded then they are unneeded
Alright, now it is only applying the damage I add on to the weapon through the enchantment
Hm, changed some stuff around and now it deals one damage or the other
If I spam, magic damage, if I don't, regular damage
But if I attack something that is immune to the IS_FIRE damage type tag, then it reverts to the regular damage
lol what
Can I see your mixin?
It's expected, as I put my damage type in the IS_FIRE damage type tag
But yeah, which mixin do you want to see?
PlayerEntityMixin is supposed to do the extra damage, and LivingEntityMixin is supposed to remove the iframes
modifyAttack and modifyDamage methods are shown
Your modifyDamage mixin is wrong
You're checking if the main hand stack of the thing sustaining the damage has the enchantment
It should be if the main hand stack of the thing doing the damage has the enchantment
Additionally, you could just do all the iframe logic in the player mixin
Yeah that makes a lot of sense now
Is this the appropriate way to great a variable checking for an attacker?
LivingEntity attacker = (LivingEntity) (Object) this;
I assume not because of this
where are you putting this
If you're putting it in the PlayerEntityMixin, just make the class abstract and have it extend LivingEntity
If you're trying to put it in the LivingEntityMixin, why are you trying to set the attacker as the one receiving the damage?
I was putting it in PlayerEntityMixin, sorry for the confusion
In PlayerEntityMixin are the playerEntity and target variables calling for the same entity?
Just double checking
That's not what I meant lol
After calling target.damage in the first handler method, you should also reset the target's iframes by setting their lastDamageTaken to 0
Oh
So just this?
I will give it a test
It appears I am still misinterpreting your words
Added the modifyDamage method and I am trying again
I feel as though something obvious is missing again, similar to how my LivingEntityMixin wasn't registered with the other mixins all that time ago
@ me whenever you're free and still wanna help me out with this! I'm gonna take a break as I have been running in circles all day so far
I did some more messing around, and I can return to the @Inject if I need to but so far this version does not yet afflict the custom damage type at all, even when spamming
No
Oh hello
It would be target.lastDamageTaken
You seem to be confusing the attacker and the target
This one should work pretty well
Should I then ignore this and return to the @Inject version?
Alright, I will return to that iteration and with the fix will see if it works
Sorry, I was busy for a little
You are all alright, do not worry!
This code however
Is not alright
@tacit eagle because target is not working, should with use the CallbackInfo?
Apologies for pinging, again
I am going to go on a walk to clear my head, and maybe grab an icecream.
I will be availiable for discussion the entire time but will be unable to write code
- You don't need to double cast to playerentity because all the methods you call will work with livingentity
Oh, thank you
- define "target is not working"
The cause should be because it is an Entity variable, and not a Living/Player Entity, that is what I remember the issue being but I can check again when I'm home
Alright, I have returend home
The symbol lasDamageTaken cannot be resolved at target.lastDamageTaken
Sorry, that's because lastDamageTaken is protected
!!accessor
io/github/mymod/mixin/MyClassAccess
@Mixin(MyClass.class)
public interface MyClassAccess {
@Invoker void callAccess();
@Accessor int getMyField();
}
to use it
public class Container {
public void slapHaykam(MyClass instance) {
((MyClassAccess)instance).callAccess();
}
}
Oh, that would make sense
Alright, a new interface and a new Container class?
You'll also have to set timeUntilRegen of the target to some number greater than 10
Alrighty
the container is the mixin in this case
Just make a new interface first
@random crypt: Unknown tag, use !tag to see all available tags
Hm
Interface is a basic java concept
They have some fundamental differences with classes, so I suggest you look them up
Thank you, I will keep a note of interfaces in case I run into them
When you get here, I suggest you set timeUntilRegen to 20 because that´s what vanilla does
Alright
Alright
For the @Accessor setLastDamageTaken, do I require an instance? Or would you rather me access timeUntilregen
I assumed lastDamageTaken at first, but you did mention timeUntilRegen a bit earlier, which is why I wish to ask before continuing forward
I would like to first extend my apologies for this frustrating adventure, it has been a couple days since we first started and I know I am not the most knowledgeable on Java
Wait I should be using @Invoke oh my goodness
what no
@random crypt Show your accessor
That's correct
Oh yay
I did something right :D
Anyways time to show something I'm doing wrong
((WcmLivingEntityAccess) ());
That is as far as I've gotten to utilizing it
Just cast the target to the accessor
Hm
target.setLastDamageTaken
?
That is very much so not what I am looking for is it
Yes, but you have to cast it
(this is a cast)
((this is the class you are casting to) this is the object you are casting)
yep
Took me a second there
But you also need to change the timeUntilRegen
Except I'm not exactly sure what to set the value to
Try setting it to 20, and if that doesn't work, do 0
Another @Accessor?
No
Hm
TimeUntilRegen is a public field
Yep
It crashed
What's the log
Changed target.timeUntilRegen to 0 just to check and it crashed again
Time to check the logs!
It is trying to invoke "net.minecraft.entity.player.PlayerEntity.getMainHandStack()" but it cannot because "playerEntity" is null
Add a null check then
PlayerEntity playerEntity = (PlayerEntity) (Object) ((LivingEntity) target).getAttacker();
I assume it is something with this
OH
You can't blind cast
Yeah, I changed it around
PlayerEntity playerEntity = (PlayerEntity) (Object) this;
AND IT WORKS
👍