VERSION I'M USING RIGHT NOW: MINECRAFT 1.16.3
Currently I'm developing a mod that changes the pvp and pve mechanics, adding a stamina system with the existir air system, overwriting it.
So far so good, I haven't had so much problems, but I'm sure there will be a lot more problems, because of my not enough knowledge of java and the forge api.
First I'm implementing a stamina mechanic which the "air" of the player will play a role here.
I put the max air number "99" to show it forever, even outside the water.
I "use" the air with each action, like jumping or sprinting.
My questions:
The sword swings, I'm not sure how to implement those, how do I detect a sword swing? Is that an event? I'll try detecting left clicks...
Because the approach I tried was, checking the "isSwingInProgress" and checking "swingProgress" but I only want it to happen 1 tick to make the player always waste 80 air in one step, and not 40 air in several random steps (depending on how fast is the swing of the sword, will either deplete much or less oxygen, not a reliable solution...)
Using air while charging bow, how? is there an event for that? or checking "holding right click" directly while char is holding a bow? which approach is the best?
What is the ideal place to learn about this mod API? if there is none, I just want to know, to not waste my time looking for it and to only focus on downloading examples.
If you have a source of an example mod that changes gameplay and not only adds blocks or items, I'd be really grateful to you.
This is the code of these first features:
@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event){
if(event.player.isSprinting()){
event.player.setAir(event.player.getAir() - 3);
}else if(!event.player.isSprinting() && !event.player.isSneaking()){
event.player.setAir(event.player.getAir());
}
if(event.player.getAir() <= 0){
event.player.attackEntityFrom(DamageSource.GENERIC, 1.0F);
if(event.player.getAir() < 0) {
event.player.setAir(0);
}
}else if(event.player.getAir() > event.player.getMaxAir()-1){
event.player.setAir(event.player.getMaxAir()-1);
}
if(event.player.isSwingInProgress && event.player.swingProgressInt == 3
&& event.player.prevSwingProgress != event.player.swingProgressInt){
event.player.setAir(event.player.getAir()-40);
}
if(enhanceLevel ==1){
((PlayerEntity) event.player).removePotionEffect(Effects.STRENGTH);
}else if(enhanceLevel == 2){
((PlayerEntity) event.player).addPotionEffect(new EffectInstance(Effects.STRENGTH,9999, 0));
}else if(enhanceLevel == 3){
((PlayerEntity) event.player).addPotionEffect(new EffectInstance(Effects.STRENGTH,9999, 1));
}
}
This is the code I used, I'm planning to refactor it today. The enhanceLevel is another mechanic but I'll leave it for later until I polish enough the custom breathing system.
I tried reading the documentation and I have seen a lot of times, it's not as documented as I expected. I don't know the reasons why the official documentation is just an introduction and not a whole explanation of each function, class, methods but at least I've read that the autocompletion will give you enough explanation of what is going to happen with each function, classes, methods, events...
The event system also has worked, but there are not enough events or maybe they are implemented somewhere else, like how I used "PlayerTickEvent".