Skip to content

Commit

Permalink
Merge branch 'ACGaming:main' into tr-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jchung01 authored Mar 17, 2024
2 parents 95a674a + efaf968 commit cb5f645
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ All changes are toggleable via config files.
* **Mending Overpowered:** If mending fix is enabled, repairs entire damaged inventory with XP
* **Mending:** Only repairs damaged equipment with XP
* **Mob Despawn Improvement:** Mobs carrying picked up items will drop their equipment and despawn properly
* **Modern Knockback:** Backports 1.16+ knockback to 1.12: Knockback resistance is now a scale instead of a probability
* **More Banner Layers:** Sets the amount of applicable pattern layers for banners
* **Mute Advancement Errors:** Silences advancement errors
* **Mute Ore Dictionary Errors:** Silences ore dictionary errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ public static class EntitiesCategory
@Config.Comment("Mobs carrying picked up items will drop their equipment and despawn properly")
public boolean utMobDespawnToggle = true;

@Config.Name("Modern Knockback")
@Config.Comment("Backports 1.16+ knockback to 1.12: Knockback resistance is now a scale instead of a probability")
public boolean utModernKnockbackToggle = true;

@Config.RequiresMcRestart
@Config.Name("No Portal Spawning")
@Config.Comment("Prevents zombie pigmen spawning from nether portals")
Expand Down
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;
}
}
}
}

0 comments on commit cb5f645

Please sign in to comment.