Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented LivingKnockBackEvent event and hook #4503

Merged
merged 10 commits into from
Dec 17, 2017
116 changes: 87 additions & 29 deletions patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
--- ../src-base/minecraft/net/minecraft/entity/EntityLivingBase.java
+++ ../src-work/minecraft/net/minecraft/entity/EntityLivingBase.java
@@ -201,10 +201,11 @@
@@ -1,7 +1,5 @@
package net.minecraft.entity;

-import com.google.common.base.Objects;
-import com.google.common.collect.Maps;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
@@ -9,7 +7,15 @@
import java.util.Map;
import java.util.Random;
import java.util.UUID;
+
import javax.annotation.Nullable;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have unused imports

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a patch, no touchy imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do I have to remove the unused imports or not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Minecraft vanilla files do not ever touch imports, ever ever ever. You have added several, REMOVE THEM.

+
+import com.google.common.base.Objects;
+import com.google.common.collect.Maps;
+
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
@@ -72,6 +78,7 @@
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
+import net.minecraftforge.event.entity.living.LivingKnockBackEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
@@ -201,10 +208,11 @@
{
float f = (float)MathHelper.func_76123_f(this.field_70143_R - 3.0F);

Expand All @@ -13,7 +45,7 @@
((WorldServer)this.field_70170_p).func_175739_a(EnumParticleTypes.BLOCK_DUST, this.field_70165_t, this.field_70163_u, this.field_70161_v, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, Block.func_176210_f(p_184231_4_));
}
}
@@ -281,7 +282,7 @@
@@ -281,7 +289,7 @@
}
}

Expand All @@ -22,7 +54,7 @@
{
this.func_184210_p();
}
@@ -380,7 +381,7 @@
@@ -380,7 +388,7 @@
if (!this.field_70170_p.field_72995_K && (this.func_70684_aJ() || this.field_70718_bc > 0 && this.func_146066_aG() && this.field_70170_p.func_82736_K().func_82766_b("doMobLoot")))
{
int i = this.func_70693_a(this.field_70717_bb);
Expand All @@ -31,15 +63,15 @@
while (i > 0)
{
int j = EntityXPOrb.func_70527_a(i);
@@ -442,6 +443,7 @@
@@ -442,6 +450,7 @@
{
this.field_70755_b = p_70604_1_;
this.field_70756_c = this.field_70173_aa;
+ net.minecraftforge.common.ForgeHooks.onLivingSetAttackTarget(this, p_70604_1_);
}

public EntityLivingBase func_110144_aD()
@@ -670,8 +672,10 @@
@@ -670,8 +679,10 @@
else
{
Collection<PotionEffect> collection = this.field_70713_bf.values();
Expand All @@ -52,7 +84,7 @@
this.func_82142_c(this.func_70644_a(MobEffects.field_76441_p));
}
}
@@ -819,6 +823,8 @@
@@ -819,6 +830,8 @@

public void func_70691_i(float p_70691_1_)
{
Expand All @@ -61,15 +93,15 @@
float f = this.func_110143_aJ();

if (f > 0.0F)
@@ -839,6 +845,7 @@
@@ -839,6 +852,7 @@

public boolean func_70097_a(DamageSource p_70097_1_, float p_70097_2_)
{
+ if (!net.minecraftforge.common.ForgeHooks.onLivingAttack(this, p_70097_1_, p_70097_2_)) return false;
if (this.func_180431_b(p_70097_1_))
{
return false;
@@ -927,9 +934,9 @@
@@ -927,9 +941,9 @@
this.field_70718_bc = 100;
this.field_70717_bb = (EntityPlayer)entity1;
}
Expand All @@ -81,7 +113,7 @@

if (entitywolf.func_70909_n())
{
@@ -1127,7 +1134,7 @@
@@ -1127,7 +1141,7 @@

public void func_70669_a(ItemStack p_70669_1_)
{
Expand All @@ -90,7 +122,7 @@

for (int i = 0; i < 5; ++i)
{
@@ -1139,12 +1146,17 @@
@@ -1139,12 +1153,17 @@
vec3d1 = vec3d1.func_178789_a(-this.field_70125_A * 0.017453292F);
vec3d1 = vec3d1.func_178785_b(-this.field_70177_z * 0.017453292F);
vec3d1 = vec3d1.func_72441_c(this.field_70165_t, this.field_70163_u + (double)this.func_70047_e(), this.field_70161_v);
Expand All @@ -109,7 +141,7 @@
if (!this.field_70729_aU)
{
Entity entity = p_70645_1_.func_76346_g();
@@ -1165,18 +1177,26 @@
@@ -1165,18 +1184,26 @@

if (!this.field_70170_p.field_72995_K)
{
Expand Down Expand Up @@ -141,7 +173,33 @@
}

this.field_70170_p.func_72960_a(this, (byte)3);
@@ -1253,15 +1273,7 @@
@@ -1195,19 +1222,22 @@

public void func_70653_a(Entity p_70653_1_, float p_70653_2_, double p_70653_3_, double p_70653_5_)
{
+ LivingKnockBackEvent event = net.minecraftforge.common.ForgeHooks.onLivingKnockBack(this, p_70653_1_, p_70653_2_, p_70653_3_, p_70653_5_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use a fully qualified name, rather than an import here; net.minecraftforge.event.entity.living.LivingKnockBackEvent event = ...

+ if(event.isCanceled()) return;
+ p_70653_2_ = event.getStrength(); p_70653_3_ = event.getRatioX(); p_70653_5_ = event.getRatioZ();
if (this.field_70146_Z.nextDouble() >= this.func_110148_a(SharedMonsterAttributes.field_111266_c).func_111126_e())
{
this.field_70160_al = true;
float f = MathHelper.func_76133_a(p_70653_3_ * p_70653_3_ + p_70653_5_ * p_70653_5_);
this.field_70159_w /= 2.0D;
this.field_70179_y /= 2.0D;
- this.field_70159_w -= p_70653_3_ / (double)f * (double)p_70653_2_;
- this.field_70179_y -= p_70653_5_ / (double)f * (double)p_70653_2_;
+ this.field_70159_w -= p_70653_3_ / (double)f * (double) p_70653_2_;
+ this.field_70179_y -= p_70653_5_ / (double)f * (double) p_70653_2_;

if (this.field_70122_E)
{
this.field_70181_x /= 2.0D;
- this.field_70181_x += (double)p_70653_2_;
+ this.field_70181_x += (double) p_70653_2_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have added a space here (double) p_70653_2_ which causes additional lines in the patch file that do precisely nothing.


if (this.field_70181_x > 0.4000000059604645D)
{
@@ -1253,15 +1283,7 @@
BlockPos blockpos = new BlockPos(i, j, k);
IBlockState iblockstate = this.field_70170_p.func_180495_p(blockpos);
Block block = iblockstate.func_177230_c();
Expand All @@ -158,7 +216,7 @@
}
}

@@ -1287,6 +1299,9 @@
@@ -1287,6 +1309,9 @@

public void func_180430_e(float p_180430_1_, float p_180430_2_)
{
Expand All @@ -168,7 +226,7 @@
super.func_180430_e(p_180430_1_, p_180430_2_);
PotionEffect potioneffect = this.func_70660_b(MobEffects.field_76430_j);
float f = potioneffect == null ? 0.0F : (float)(potioneffect.func_76458_c() + 1);
@@ -1303,7 +1318,7 @@
@@ -1303,7 +1328,7 @@

if (iblockstate.func_185904_a() != Material.field_151579_a)
{
Expand All @@ -177,7 +235,7 @@
this.func_184185_a(soundtype.func_185842_g(), soundtype.func_185843_a() * 0.5F, soundtype.func_185847_b() * 0.75F);
}
}
@@ -1380,17 +1395,20 @@
@@ -1380,17 +1405,20 @@
{
if (!this.func_180431_b(p_70665_1_))
{
Expand All @@ -199,7 +257,7 @@
this.func_110149_m(this.func_110139_bj() - p_70665_2_);
}
}
@@ -1447,6 +1465,11 @@
@@ -1447,6 +1475,11 @@

public void func_184609_a(EnumHand p_184609_1_)
{
Expand All @@ -211,7 +269,7 @@
if (!this.field_82175_bq || this.field_110158_av >= this.func_82166_i() / 2 || this.field_110158_av < 0)
{
this.field_110158_av = -1;
@@ -1694,7 +1717,7 @@
@@ -1694,7 +1727,7 @@

if (!this.field_70170_p.func_184143_b(axisalignedbb1))
{
Expand All @@ -220,7 +278,7 @@
{
this.func_70634_a(d11, this.field_70163_u + 1.0D, d12);
return;
@@ -1702,14 +1725,14 @@
@@ -1702,14 +1735,14 @@

BlockPos blockpos = new BlockPos(d11, this.field_70163_u - 1.0D, d12);

Expand All @@ -237,15 +295,15 @@
{
d1 = d11;
d13 = this.field_70163_u + 2.0D;
@@ -1781,6 +1804,7 @@
@@ -1781,6 +1814,7 @@
}

this.field_70160_al = true;
+ net.minecraftforge.common.ForgeHooks.onLivingJump(this);
}

protected void func_70629_bd()
@@ -1874,7 +1898,8 @@
@@ -1874,7 +1908,8 @@

if (this.field_70122_E)
{
Expand All @@ -255,7 +313,7 @@
}

float f7 = 0.16277136F / (f6 * f6 * f6);
@@ -1894,7 +1919,8 @@
@@ -1894,7 +1929,8 @@

if (this.field_70122_E)
{
Expand All @@ -265,15 +323,15 @@
}

if (this.func_70617_f_())
@@ -2054,6 +2080,7 @@
@@ -2054,6 +2090,7 @@

public void func_70071_h_()
{
+ if (net.minecraftforge.common.ForgeHooks.onLivingUpdate(this)) return;
super.func_70071_h_();
this.func_184608_ct();

@@ -2096,7 +2123,9 @@
@@ -2096,7 +2133,9 @@

if (!ItemStack.func_77989_b(itemstack1, itemstack))
{
Expand All @@ -283,7 +341,7 @@

if (!itemstack.func_190926_b())
{
@@ -2575,6 +2604,40 @@
@@ -2575,6 +2614,40 @@
this.field_70752_e = true;
}

Expand Down Expand Up @@ -324,7 +382,7 @@
public abstract EnumHandSide func_184591_cq();

public boolean func_184587_cr()
@@ -2595,12 +2658,19 @@
@@ -2595,12 +2668,19 @@

if (itemstack == this.field_184627_bm)
{
Expand All @@ -345,7 +403,7 @@
{
this.func_71036_o();
}
@@ -2618,8 +2688,10 @@
@@ -2618,8 +2698,10 @@

if (!itemstack.func_190926_b() && !this.func_184587_cr())
{
Expand All @@ -357,7 +415,7 @@

if (!this.field_70170_p.field_72995_K)
{
@@ -2700,7 +2772,9 @@
@@ -2700,7 +2782,9 @@
if (!this.field_184627_bm.func_190926_b() && this.func_184587_cr())
{
this.func_184584_a(this.field_184627_bm, 16);
Expand All @@ -368,7 +426,7 @@
this.func_184602_cy();
}
}
@@ -2724,7 +2798,8 @@
@@ -2724,7 +2808,8 @@
{
if (!this.field_184627_bm.func_190926_b())
{
Expand All @@ -378,7 +436,7 @@
}

this.func_184602_cy();
@@ -2852,6 +2927,31 @@
@@ -2852,6 +2937,31 @@
return true;
}

Expand Down
24 changes: 16 additions & 8 deletions src/main/java/net/minecraftforge/common/ForgeHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've reorganized the imports here, these lines have shifted place. Don't do this, it makes the patch files larger for no reason.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a forge class. Imports should be added but not organized, its entirely up to the users IDE as to how they are ordered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I don't have to organize them?

Copy link
Contributor

@Draco18s Draco18s Nov 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, don't organize them. (And you're right @covers1624 it's a Forge class, not a patch, I missed that, but it still needs to be fixed).


import com.google.common.collect.Lists;
import com.google.common.collect.Queues;
import com.google.common.collect.Sets;
Expand Down Expand Up @@ -96,10 +102,10 @@
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.GameType;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.storage.loot.LootEntry;
import net.minecraft.world.storage.loot.LootTable;
import net.minecraft.world.storage.loot.LootTableManager;
Expand All @@ -120,6 +126,7 @@
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.event.entity.living.LivingFallEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.living.LivingKnockBackEvent;
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
import net.minecraftforge.event.entity.living.LootingLevelEvent;
import net.minecraftforge.event.entity.player.AnvilRepairEvent;
Expand All @@ -141,12 +148,6 @@
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.RegistryManager;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;

public class ForgeHooks
{
//TODO: Loot tables?
Expand Down Expand Up @@ -559,6 +560,13 @@ public static boolean onLivingAttack(EntityLivingBase entity, DamageSource src,
return !MinecraftForge.EVENT_BUS.post(new LivingAttackEvent(entity, src, amount));
}

public static LivingKnockBackEvent onLivingKnockBack(EntityLivingBase target, Entity attacker, float strength, double ratioX, double ratioZ)
{
LivingKnockBackEvent event = new LivingKnockBackEvent(target, attacker, strength, ratioX, ratioZ);
MinecraftForge.EVENT_BUS.post(event);
return event;
}

public static float onLivingHurt(EntityLivingBase entity, DamageSource src, float amount)
{
LivingHurtEvent event = new LivingHurtEvent(entity, src, amount);
Expand Down