-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ACGaming:main' into tr-cleanup
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/mod/acgaming/universaltweaks/tweaks/entities/knockback/UTModernKnockback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package mod.acgaming.universaltweaks.tweaks.entities.knockback; | ||
|
||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.entity.SharedMonsterAttributes; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraftforge.event.entity.living.LivingKnockBackEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
|
||
import mod.acgaming.universaltweaks.UniversalTweaks; | ||
import mod.acgaming.universaltweaks.config.UTConfigGeneral; | ||
import mod.acgaming.universaltweaks.config.UTConfigTweaks; | ||
|
||
@Mod.EventBusSubscriber | ||
public class UTModernKnockback | ||
{ | ||
@SubscribeEvent | ||
public static void utModernKnockback(LivingKnockBackEvent event) | ||
{ | ||
if (!UTConfigTweaks.ENTITIES.utModernKnockbackToggle) return; | ||
if (UTConfigGeneral.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTModernKnockback ::: Living knock back event"); | ||
event.setCanceled(true); | ||
EntityLivingBase entity = event.getEntityLiving(); | ||
double strength = event.getStrength(); | ||
double xRatio = event.getRatioX(); | ||
double zRatio = event.getRatioZ(); | ||
strength = strength * (1.0D - entity.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).getAttributeValue()); | ||
if (strength > 0.0F) | ||
{ | ||
entity.isAirBorne = true; | ||
float f = MathHelper.sqrt(xRatio * xRatio + zRatio * zRatio); | ||
entity.motionX /= 2.0D; | ||
entity.motionZ /= 2.0D; | ||
entity.motionX -= xRatio / f * strength; | ||
entity.motionZ -= zRatio / f * strength; | ||
if (entity.onGround) | ||
{ | ||
entity.motionY /= 2.0D; | ||
entity.motionY += strength; | ||
if (entity.motionY > 0.4D) entity.motionY = 0.4D; | ||
} | ||
} | ||
} | ||
} |