Files
MinecraftForge/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch
T

753 lines
37 KiB
Diff

--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -118,12 +_,14 @@
import net.minecraft.world.scores.PlayerTeam;
import org.slf4j.Logger;
-public abstract class LivingEntity extends Entity {
+public abstract class LivingEntity extends Entity implements net.minecraftforge.common.extensions.IForgeLivingEntity {
private static final Logger f_201943_ = LogUtils.getLogger();
private static final UUID f_20929_ = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
private static final UUID f_20959_ = UUID.fromString("87f46a96-686f-4796-b035-22e16ee9e038");
private static final UUID f_147184_ = UUID.fromString("1eaf83ff-7207-4596-b37a-d7a07b3ec4ce");
+ private static final UUID SLOW_FALLING_ID = UUID.fromString("A5B6CF2A-2F7C-31EF-9022-7C3E7D5E6ABA");
private static final AttributeModifier f_20960_ = new AttributeModifier(f_20929_, "Sprinting speed boost", (double)0.3F, AttributeModifier.Operation.MULTIPLY_TOTAL);
+ private static final AttributeModifier SLOW_FALLING = new AttributeModifier(SLOW_FALLING_ID, "Slow falling acceleration reduction", -0.07, AttributeModifier.Operation.ADDITION); // Add -0.07 to 0.08 so we get the vanilla default of 0.01
public static final int f_147166_ = 2;
public static final int f_147167_ = 4;
public static final int f_147168_ = 98;
@@ -274,7 +_,7 @@
}
public static AttributeSupplier.Builder m_21183_() {
- return AttributeSupplier.m_22244_().m_22266_(Attributes.f_22276_).m_22266_(Attributes.f_22278_).m_22266_(Attributes.f_22279_).m_22266_(Attributes.f_22284_).m_22266_(Attributes.f_22285_);
+ return AttributeSupplier.m_22244_().m_22266_(Attributes.f_22276_).m_22266_(Attributes.f_22278_).m_22266_(Attributes.f_22279_).m_22266_(Attributes.f_22284_).m_22266_(Attributes.f_22285_).m_22266_(net.minecraftforge.common.ForgeMod.SWIM_SPEED.get()).m_22266_(net.minecraftforge.common.ForgeMod.NAMETAG_DISTANCE.get()).m_22266_(net.minecraftforge.common.ForgeMod.ENTITY_GRAVITY.get()).m_22266_(net.minecraftforge.common.ForgeMod.STEP_HEIGHT_ADDITION.get());
}
protected void m_7840_(double p_20990_, boolean p_20991_, BlockState p_20992_, BlockPos p_20993_) {
@@ -292,13 +_,15 @@
if (!p_20992_.m_60795_()) {
double d0 = Math.min((double)(0.2F + f / 15.0F), 2.5D);
int i = (int)(150.0D * d0);
- ((ServerLevel)this.f_19853_).m_8767_(new BlockParticleOption(ParticleTypes.f_123794_, p_20992_), this.m_20185_(), this.m_20186_(), this.m_20189_(), i, 0.0D, 0.0D, 0.0D, (double)0.15F);
+ if (!p_20992_.addLandingEffects((ServerLevel)this.f_19853_, p_20993_, p_20992_, this, i))
+ ((ServerLevel)this.f_19853_).m_8767_(new BlockParticleOption(ParticleTypes.f_123794_, p_20992_).setPos(p_20993_), this.m_20185_(), this.m_20186_(), this.m_20189_(), i, 0.0D, 0.0D, 0.0D, (double)0.15F);
}
}
super.m_7840_(p_20990_, p_20991_, p_20992_, p_20993_);
}
+ @Deprecated //FORGE: Use canDrownInFluidType instead
public boolean m_6040_() {
return this.m_6336_() == MobType.f_21641_;
}
@@ -337,8 +_,8 @@
}
}
- if (this.m_204029_(FluidTags.f_13131_) && !this.f_19853_.m_8055_(new BlockPos(this.m_20185_(), this.m_20188_(), this.m_20189_())).m_60713_(Blocks.f_50628_)) {
- boolean flag1 = !this.m_6040_() && !MobEffectUtil.m_19588_(this) && (!flag || !((Player)this).m_150110_().f_35934_);
+ if (!this.getEyeInFluidType().isAir() && !this.f_19853_.m_8055_(new BlockPos(this.m_20185_(), this.m_20188_(), this.m_20189_())).m_60713_(Blocks.f_50628_)) {
+ boolean flag1 = this.canDrownInFluidType(this.getEyeInFluidType()) && !MobEffectUtil.m_19588_(this) && (!flag || !((Player)this).m_150110_().f_35934_);
if (flag1) {
this.m_20301_(this.m_7302_(this.m_20146_()));
if (this.m_20146_() == -20) {
@@ -356,10 +_,11 @@
}
}
- if (!this.f_19853_.f_46443_ && this.m_20159_() && this.m_20202_() != null && !this.m_20202_().m_6146_()) {
+ if (!this.f_19853_.f_46443_ && this.m_20159_() && this.m_20202_() != null && !this.m_20202_().canBeRiddenUnderFluidType(this.getEyeInFluidType(), this)) {
this.m_8127_();
}
- } else if (this.m_20146_() < this.m_6062_()) {
+ } // Forge: Move to if statement since we need to increase the air supply if in bubble column or can't drown
+ if (this.m_20146_() < this.m_6062_() && (!this.canDrownInFluidType(this.getEyeInFluidType()) || this.f_19853_.m_8055_(new BlockPos(this.m_20185_(), this.m_20188_(), this.m_20189_())).m_60713_(Blocks.f_50628_))) {
this.m_20301_(this.m_7305_(this.m_20146_()));
}
@@ -372,7 +_,7 @@
}
}
- if (this.m_6084_() && (this.m_20071_() || this.f_146808_)) {
+ if (this.m_6084_() && (this.m_20071_() || this.f_146808_ || this.isInFluidType((fluidType, height) -> this.canFluidExtinguish(fluidType)))) {
if (!this.f_19853_.f_46443_ && this.f_146810_) {
this.m_146873_();
}
@@ -740,7 +_,7 @@
if (!mobeffectinstance.m_19552_(this, () -> {
this.m_141973_(mobeffectinstance, true, (Entity)null);
})) {
- if (!this.f_19853_.f_46443_) {
+ if (!this.f_19853_.f_46443_ && !net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.living.MobEffectEvent.Expired(this, mobeffectinstance))) {
iterator.remove();
this.m_7285_(mobeffectinstance);
}
@@ -790,8 +_,10 @@
this.m_6842_(false);
} else {
Collection<MobEffectInstance> collection = this.f_20945_.values();
- this.f_19804_.m_135381_(f_20963_, m_21179_(collection));
- this.f_19804_.m_135381_(f_20962_, PotionUtils.m_43564_(collection));
+ net.minecraftforge.event.entity.living.PotionColorCalculationEvent event = new net.minecraftforge.event.entity.living.PotionColorCalculationEvent(this, PotionUtils.m_43564_(collection), m_21179_(collection), collection);
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event);
+ this.f_19804_.m_135381_(f_20963_, event.areParticlesHidden());
+ this.f_19804_.m_135381_(f_20962_, event.getColor());
this.m_6842_(this.m_21023_(MobEffects.f_19609_));
}
@@ -827,7 +_,7 @@
d0 *= 0.5D;
}
}
-
+ d0 = net.minecraftforge.common.ForgeHooks.getEntityVisibilityMultiplier(this, p_20969_, d0);
return d0;
}
@@ -870,7 +_,9 @@
boolean flag;
for(flag = false; iterator.hasNext(); flag = true) {
- this.m_7285_(iterator.next());
+ MobEffectInstance effect = iterator.next();
+ if(net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.living.MobEffectEvent.Remove(this, effect))) continue;
+ this.m_7285_(effect);
iterator.remove();
}
@@ -904,6 +_,7 @@
return false;
} else {
MobEffectInstance mobeffectinstance = this.f_20945_.get(p_147208_.m_19544_());
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.living.MobEffectEvent.Added(this, mobeffectinstance, p_147208_, p_147209_));
if (mobeffectinstance == null) {
this.f_20945_.put(p_147208_.m_19544_(), p_147208_);
this.m_142540_(p_147208_, p_147209_);
@@ -918,6 +_,9 @@
}
public boolean m_7301_(MobEffectInstance p_21197_) {
+ net.minecraftforge.event.entity.living.MobEffectEvent.Applicable event = new net.minecraftforge.event.entity.living.MobEffectEvent.Applicable(this, p_21197_);
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event);
+ if (event.getResult() != net.minecraftforge.eventbus.api.Event.Result.DEFAULT) return event.getResult() == net.minecraftforge.eventbus.api.Event.Result.ALLOW;
if (this.m_6336_() == MobType.f_21641_) {
MobEffect mobeffect = p_21197_.m_19544_();
if (mobeffect == MobEffects.f_19605_ || mobeffect == MobEffects.f_19614_) {
@@ -950,6 +_,7 @@
}
public boolean m_21195_(MobEffect p_21196_) {
+ if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.living.MobEffectEvent.Remove(this, p_21196_))) return false;
MobEffectInstance mobeffectinstance = this.m_6234_(p_21196_);
if (mobeffectinstance != null) {
this.m_7285_(mobeffectinstance);
@@ -986,6 +_,8 @@
}
public void m_5634_(float p_21116_) {
+ p_21116_ = net.minecraftforge.event.ForgeEventFactory.onLivingHeal(this, p_21116_);
+ if (p_21116_ <= 0) return;
float f = this.m_21223_();
if (f > 0.0F) {
this.m_21153_(f + p_21116_);
@@ -1006,6 +_,7 @@
}
public boolean m_6469_(DamageSource p_21016_, float p_21017_) {
+ if (!net.minecraftforge.common.ForgeHooks.onLivingAttack(this, p_21016_, p_21017_)) return false;
if (this.m_6673_(p_21016_)) {
return false;
} else if (this.f_19853_.f_46443_) {
@@ -1024,9 +_,11 @@
boolean flag = false;
float f1 = 0.0F;
if (p_21017_ > 0.0F && this.m_21275_(p_21016_)) {
- this.m_7909_(p_21017_);
- f1 = p_21017_;
- p_21017_ = 0.0F;
+ net.minecraftforge.event.entity.living.ShieldBlockEvent ev = net.minecraftforge.common.ForgeHooks.onShieldBlock(this, p_21016_, p_21017_);
+ if(!ev.isCanceled()) {
+ if(ev.shieldTakesDamage()) this.m_7909_(p_21017_);
+ f1 = ev.getBlockedDamage();
+ p_21017_ -= ev.getBlockedDamage();
if (!p_21016_.m_19360_()) {
Entity entity = p_21016_.m_7640_();
if (entity instanceof LivingEntity) {
@@ -1036,6 +_,7 @@
flag = true;
}
+ }
this.f_20924_ = 1.5F;
boolean flag1 = true;
@@ -1070,11 +_,11 @@
if (entity1 instanceof Player) {
this.f_20889_ = 100;
this.f_20888_ = (Player)entity1;
- } else if (entity1 instanceof Wolf) {
- Wolf wolf = (Wolf)entity1;
- if (wolf.m_21824_()) {
+ } else if (entity1 instanceof net.minecraft.world.entity.TamableAnimal) {
+ net.minecraft.world.entity.TamableAnimal tamableEntity = (net.minecraft.world.entity.TamableAnimal)entity1;
+ if (tamableEntity.m_21824_()) {
this.f_20889_ = 100;
- LivingEntity livingentity = wolf.m_21826_();
+ LivingEntity livingentity = tamableEntity.m_21826_();
if (livingentity != null && livingentity.m_6095_() == EntityType.f_20532_) {
this.f_20888_ = (Player)livingentity;
} else {
@@ -1147,7 +_,7 @@
if (this instanceof ServerPlayer) {
CriteriaTriggers.f_10574_.m_35174_((ServerPlayer)this, p_21016_, f, p_21017_, flag);
if (f1 > 0.0F && f1 < 3.4028235E37F) {
- ((ServerPlayer)this).m_36222_(Stats.f_12932_, Math.round(f1 * 10.0F));
+ ((ServerPlayer)this).m_6278_(Stats.f_12988_.m_12902_(Stats.f_12932_), Math.round(f1 * 10.0F));
}
}
@@ -1175,7 +_,7 @@
for(InteractionHand interactionhand : InteractionHand.values()) {
ItemStack itemstack1 = this.m_21120_(interactionhand);
- if (itemstack1.m_150930_(Items.f_42747_)) {
+ if (itemstack1.m_150930_(Items.f_42747_) && net.minecraftforge.common.ForgeHooks.onLivingUseTotem(this, p_21263_, itemstack1, interactionhand)) {
itemstack = itemstack1.m_41777_();
itemstack1.m_41774_(1);
break;
@@ -1185,7 +_,7 @@
if (itemstack != null) {
if (this instanceof ServerPlayer) {
ServerPlayer serverplayer = (ServerPlayer)this;
- serverplayer.m_36246_(Stats.f_12982_.m_12902_(Items.f_42747_));
+ serverplayer.m_6278_(Stats.f_12982_.m_12902_(Items.f_42747_), 1);
CriteriaTriggers.f_10551_.m_74431_(serverplayer, itemstack);
}
@@ -1254,6 +_,7 @@
}
public void m_6667_(DamageSource p_21014_) {
+ if (net.minecraftforge.common.ForgeHooks.onLivingDeath(this, p_21014_)) return;
if (!this.m_213877_() && !this.f_20890_) {
Entity entity = p_21014_.m_7639_();
LivingEntity livingentity = this.m_21232_();
@@ -1289,10 +_,10 @@
if (!this.f_19853_.f_46443_) {
boolean flag = false;
if (p_21269_ instanceof WitherBoss) {
- if (this.f_19853_.m_46469_().m_46207_(GameRules.f_46132_)) {
+ if (net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.f_19853_, p_21269_)) {
BlockPos blockpos = this.m_20183_();
BlockState blockstate = Blocks.f_50070_.m_49966_();
- if (this.f_19853_.m_8055_(blockpos).m_60795_() && blockstate.m_60710_(this.f_19853_, blockpos)) {
+ if (this.f_19853_.m_46859_(blockpos) && blockstate.m_60710_(this.f_19853_, blockpos)) {
this.f_19853_.m_7731_(blockpos, blockstate, 3);
flag = true;
}
@@ -1309,12 +_,9 @@
protected void m_6668_(DamageSource p_21192_) {
Entity entity = p_21192_.m_7639_();
- int i;
- if (entity instanceof Player) {
- i = EnchantmentHelper.m_44930_((LivingEntity)entity);
- } else {
- i = 0;
- }
+
+ int i = net.minecraftforge.common.ForgeHooks.getLootingLevel(this, entity, p_21192_);
+ this.captureDrops(new java.util.ArrayList<>());
boolean flag = this.f_20889_ > 0;
if (this.m_6125_() && this.f_19853_.m_46469_().m_46207_(GameRules.f_46135_)) {
@@ -1324,6 +_,10 @@
this.m_5907_();
this.m_21226_();
+
+ Collection<ItemEntity> drops = captureDrops(null);
+ if (!net.minecraftforge.common.ForgeHooks.onLivingDrops(this, p_21192_, drops, i, f_20889_ > 0))
+ drops.forEach(e -> f_19853_.m_7967_(e));
}
protected void m_5907_() {
@@ -1331,7 +_,8 @@
protected void m_21226_() {
if (this.f_19853_ instanceof ServerLevel && !this.m_217046_() && (this.m_6124_() || this.f_20889_ > 0 && this.m_6149_() && this.f_19853_.m_46469_().m_46207_(GameRules.f_46135_))) {
- ExperienceOrb.m_147082_((ServerLevel)this.f_19853_, this.m_20182_(), this.m_213860_());
+ int reward = net.minecraftforge.event.ForgeEventFactory.getExperienceDrop(this, this.f_20888_, this.m_213860_());
+ ExperienceOrb.m_147082_((ServerLevel)this.f_19853_, this.m_20182_(), reward);
}
}
@@ -1347,7 +_,8 @@
ResourceLocation resourcelocation = this.m_5743_();
LootTable loottable = this.f_19853_.m_7654_().m_129898_().m_79217_(resourcelocation);
LootContext.Builder lootcontext$builder = this.m_7771_(p_21022_, p_21021_);
- loottable.m_79148_(lootcontext$builder.m_78975_(LootContextParamSets.f_81415_), this::m_19983_);
+ LootContext ctx = lootcontext$builder.m_78975_(LootContextParamSets.f_81415_);
+ loottable.m_230922_(ctx).forEach(this::m_19983_);
}
protected LootContext.Builder m_7771_(boolean p_21105_, DamageSource p_21106_) {
@@ -1360,6 +_,11 @@
}
public void m_147240_(double p_147241_, double p_147242_, double p_147243_) {
+ net.minecraftforge.event.entity.living.LivingKnockBackEvent event = net.minecraftforge.common.ForgeHooks.onLivingKnockBack(this, (float) p_147241_, p_147242_, p_147243_);
+ if(event.isCanceled()) return;
+ p_147241_ = event.getStrength();
+ p_147242_ = event.getRatioX();
+ p_147243_ = event.getRatioZ();
p_147241_ *= 1.0D - this.m_21133_(Attributes.f_22278_);
if (!(p_147241_ <= 0.0D)) {
this.f_19812_ = true;
@@ -1421,15 +_,9 @@
} else {
BlockPos blockpos = this.m_20183_();
BlockState blockstate = this.m_146900_();
- if (blockstate.m_204336_(BlockTags.f_13082_)) {
- this.f_20957_ = Optional.of(blockpos);
- return true;
- } else if (blockstate.m_60734_() instanceof TrapDoorBlock && this.m_21176_(blockpos, blockstate)) {
- this.f_20957_ = Optional.of(blockpos);
- return true;
- } else {
- return false;
- }
+ Optional<BlockPos> ladderPos = net.minecraftforge.common.ForgeHooks.isLivingOnLadder(blockstate, f_19853_, blockpos, this);
+ if (ladderPos.isPresent()) this.f_20957_ = ladderPos;
+ return ladderPos.isPresent();
}
}
@@ -1449,6 +_,11 @@
}
public boolean m_142535_(float p_147187_, float p_147188_, DamageSource p_147189_) {
+ float[] ret = net.minecraftforge.common.ForgeHooks.onLivingFall(this, p_147187_, p_147188_);
+ if (ret == null) return false;
+ p_147187_ = ret[0];
+ p_147188_ = ret[1];
+
boolean flag = super.m_142535_(p_147187_, p_147188_, p_147189_);
int i = this.m_5639_(p_147187_, p_147188_);
if (i > 0) {
@@ -1472,9 +_,10 @@
int i = Mth.m_14107_(this.m_20185_());
int j = Mth.m_14107_(this.m_20186_() - (double)0.2F);
int k = Mth.m_14107_(this.m_20189_());
- BlockState blockstate = this.f_19853_.m_8055_(new BlockPos(i, j, k));
+ BlockPos pos = new BlockPos(i, j, k);
+ BlockState blockstate = this.f_19853_.m_8055_(pos);
if (!blockstate.m_60795_()) {
- SoundType soundtype = blockstate.m_60827_();
+ SoundType soundtype = blockstate.getSoundType(f_19853_, pos, this);
this.m_5496_(soundtype.m_56779_(), soundtype.m_56773_() * 0.5F, soundtype.m_56774_() * 0.75F);
}
@@ -1522,9 +_,9 @@
float f2 = f1 - p_21194_;
if (f2 > 0.0F && f2 < 3.4028235E37F) {
if (this instanceof ServerPlayer) {
- ((ServerPlayer)this).m_36222_(Stats.f_12934_, Math.round(f2 * 10.0F));
+ ((ServerPlayer)this).m_6278_(Stats.f_12988_.m_12902_(Stats.f_12934_), Math.round(f2 * 10.0F));
} else if (p_21193_.m_7639_() instanceof ServerPlayer) {
- ((ServerPlayer)p_21193_.m_7639_()).m_36222_(Stats.f_12930_, Math.round(f2 * 10.0F));
+ ((ServerPlayer)p_21193_.m_7639_()).m_6278_(Stats.f_12988_.m_12902_(Stats.f_12930_), Math.round(f2 * 10.0F));
}
}
}
@@ -1546,19 +_,22 @@
protected void m_6475_(DamageSource p_21240_, float p_21241_) {
if (!this.m_6673_(p_21240_)) {
+ p_21241_ = net.minecraftforge.common.ForgeHooks.onLivingHurt(this, p_21240_, p_21241_);
+ if (p_21241_ <= 0) return;
p_21241_ = this.m_21161_(p_21240_, p_21241_);
p_21241_ = this.m_6515_(p_21240_, p_21241_);
float f2 = Math.max(p_21241_ - this.m_6103_(), 0.0F);
this.m_7911_(this.m_6103_() - (p_21241_ - f2));
float f = p_21241_ - f2;
if (f > 0.0F && f < 3.4028235E37F && p_21240_.m_7639_() instanceof ServerPlayer) {
- ((ServerPlayer)p_21240_.m_7639_()).m_36222_(Stats.f_12929_, Math.round(f * 10.0F));
+ ((ServerPlayer)p_21240_.m_7639_()).m_6278_(Stats.f_12988_.m_12902_(Stats.f_12929_), Math.round(f * 10.0F));
}
+ f2 = net.minecraftforge.common.ForgeHooks.onLivingDamage(this, p_21240_, f2);
if (f2 != 0.0F) {
float f1 = this.m_21223_();
- this.m_21153_(f1 - f2);
this.m_21231_().m_19289_(p_21240_, f1, f2);
+ this.m_21153_(f1 - f2); // Forge: moved to fix MC-121048
this.m_7911_(this.m_6103_() - f2);
this.m_146850_(GameEvent.f_223706_);
}
@@ -1613,6 +_,8 @@
}
public void m_21011_(InteractionHand p_21012_, boolean p_21013_) {
+ ItemStack stack = this.m_21120_(p_21012_);
+ if (!stack.m_41619_() && stack.onEntitySwing(this)) return;
if (!this.f_20911_ || this.f_20913_ >= this.m_21304_() / 2 || this.f_20913_ < 0) {
this.f_20913_ = -1;
this.f_20911_ = true;
@@ -1972,14 +_,17 @@
}
this.f_19812_ = true;
+ net.minecraftforge.common.ForgeHooks.onLivingJump(this);
}
+ @Deprecated // FORGE: use sinkInFluid instead
protected void m_21208_() {
- this.m_20256_(this.m_20184_().m_82520_(0.0D, (double)-0.04F, 0.0D));
+ this.sinkInFluid(net.minecraftforge.common.ForgeMod.WATER_TYPE.get());
}
+ @Deprecated // FORGE: use jumpInFluid instead
protected void m_203347_(TagKey<Fluid> p_204043_) {
- this.m_20256_(this.m_20184_().m_82520_(0.0D, (double)0.04F, 0.0D));
+ this.m_20256_(this.m_20184_().m_82520_(0.0D, (double)0.04F * this.m_21051_(net.minecraftforge.common.ForgeMod.SWIM_SPEED.get()).m_22135_(), 0.0D));
}
protected float m_6108_() {
@@ -1993,14 +_,19 @@
public void m_7023_(Vec3 p_21280_) {
if (this.m_6142_() || this.m_6109_()) {
double d0 = 0.08D;
+ AttributeInstance gravity = this.m_21051_(net.minecraftforge.common.ForgeMod.ENTITY_GRAVITY.get());
boolean flag = this.m_20184_().f_82480_ <= 0.0D;
if (flag && this.m_21023_(MobEffects.f_19591_)) {
- d0 = 0.01D;
+ if (!gravity.m_22109_(SLOW_FALLING)) gravity.m_22118_(SLOW_FALLING);
this.m_183634_();
+ } else if (gravity.m_22109_(SLOW_FALLING)) {
+ gravity.m_22130_(SLOW_FALLING);
}
+ d0 = gravity.m_22135_();
FluidState fluidstate = this.f_19853_.m_6425_(this.m_20183_());
- if (this.m_20069_() && this.m_6129_() && !this.m_203441_(fluidstate)) {
+ if ((this.m_20069_() || (this.isInFluidType(fluidstate) && fluidstate.getFluidType() != net.minecraftforge.common.ForgeMod.LAVA_TYPE.get())) && this.m_6129_() && !this.m_203441_(fluidstate)) {
+ if (this.m_20069_() || (this.isInFluidType(fluidstate) && !this.moveInFluid(fluidstate, p_21280_, d0))) {
double d9 = this.m_20186_();
float f4 = this.m_20142_() ? 0.9F : this.m_6108_();
float f5 = 0.02F;
@@ -2022,6 +_,7 @@
f4 = 0.96F;
}
+ f5 *= (float)this.m_21051_(net.minecraftforge.common.ForgeMod.SWIM_SPEED.get()).m_22135_();
this.m_19920_(f5, p_21280_);
this.m_6478_(MoverType.SELF, this.m_20184_());
Vec3 vec36 = this.m_20184_();
@@ -2035,6 +_,7 @@
if (this.f_19862_ && this.m_20229_(vec32.f_82479_, vec32.f_82480_ + (double)0.6F - this.m_20186_() + d9, vec32.f_82481_)) {
this.m_20334_(vec32.f_82479_, (double)0.3F, vec32.f_82481_);
}
+ }
} else if (this.m_20077_() && this.m_6129_() && !this.m_203441_(fluidstate)) {
double d8 = this.m_20186_();
this.m_19920_(0.02F, p_21280_);
@@ -2100,7 +_,7 @@
}
} else {
BlockPos blockpos = this.m_20099_();
- float f2 = this.f_19853_.m_8055_(blockpos).m_60734_().m_49958_();
+ float f2 = this.f_19853_.m_8055_(this.m_20099_()).getFriction(f_19853_, this.m_20099_(), this);
float f3 = this.f_19861_ ? f2 * 0.91F : 0.91F;
Vec3 vec35 = this.m_21074_(p_21280_, f2);
double d2 = vec35.f_82480_;
@@ -2176,7 +_,7 @@
double d0 = Mth.m_14008_(p_21298_.f_82479_, (double)-0.15F, (double)0.15F);
double d1 = Mth.m_14008_(p_21298_.f_82481_, (double)-0.15F, (double)0.15F);
double d2 = Math.max(p_21298_.f_82480_, (double)-0.15F);
- if (d2 < 0.0D && !this.m_146900_().m_60713_(Blocks.f_50616_) && this.m_5791_() && this instanceof Player) {
+ if (d2 < 0.0D && !this.m_146900_().isScaffolding(this) && this.m_5791_() && this instanceof Player) {
d2 = 0.0D;
}
@@ -2204,6 +_,7 @@
}
public void m_8119_() {
+ if (net.minecraftforge.common.ForgeHooks.onLivingTick(this)) return;
super.m_8119_();
this.m_21329_();
this.m_21333_();
@@ -2355,6 +_,7 @@
ItemStack itemstack1 = this.m_6844_(equipmentslot);
if (!ItemStack.m_41728_(itemstack1, itemstack)) {
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent(this, equipmentslot, itemstack, itemstack1));
if (map == null) {
map = Maps.newEnumMap(EquipmentSlot.class);
}
@@ -2505,6 +_,8 @@
this.f_19853_.m_46473_().m_6180_("jump");
if (this.f_20899_ && this.m_6129_()) {
double d7;
+ net.minecraftforge.fluids.FluidType fluidType = this.getMaxHeightFluidType();
+ if (!fluidType.isAir()) d7 = this.getFluidTypeHeight(fluidType);
if (this.m_20077_()) {
d7 = this.m_204036_(FluidTags.f_13132_);
} else {
@@ -2515,15 +_,17 @@
double d8 = this.m_20204_();
if (!flag1 || this.f_19861_ && !(d7 > d8)) {
if (!this.m_20077_() || this.f_19861_ && !(d7 > d8)) {
+ if (fluidType.isAir() || this.f_19861_ && !(d7 > d8)) {
if ((this.f_19861_ || flag1 && d7 <= d8) && this.f_20954_ == 0) {
this.m_6135_();
this.f_20954_ = 10;
}
+ } else this.jumpInFluid(fluidType);
} else {
- this.m_203347_(FluidTags.f_13132_);
+ this.jumpInFluid(net.minecraftforge.common.ForgeMod.LAVA_TYPE.get());
}
} else {
- this.m_203347_(FluidTags.f_13131_);
+ this.jumpInFluid(net.minecraftforge.common.ForgeMod.WATER_TYPE.get());
}
} else {
this.f_20954_ = 0;
@@ -2578,6 +_,8 @@
boolean flag = this.m_20291_(7);
if (flag && !this.f_19861_ && !this.m_20159_() && !this.m_21023_(MobEffects.f_19620_)) {
ItemStack itemstack = this.m_6844_(EquipmentSlot.CHEST);
+ flag = itemstack.canElytraFly(this) && itemstack.elytraFlightTick(this, this.f_20937_);
+ if (false) //Forge: Moved to ElytraItem
if (itemstack.m_150930_(Items.f_42741_) && ElytraItem.m_41140_(itemstack)) {
flag = true;
int i = this.f_20937_ + 1;
@@ -2809,8 +_,16 @@
private void m_21329_() {
if (this.m_6117_()) {
- if (ItemStack.m_41758_(this.m_21120_(this.m_7655_()), this.f_20935_)) {
- this.f_20935_ = this.m_21120_(this.m_7655_());
+ ItemStack itemStack = this.m_21120_(this.m_7655_());
+ if (net.minecraftforge.common.ForgeHooks.canContinueUsing(this.f_20935_, itemStack)) this.f_20935_ = itemStack;
+ if (itemStack == this.f_20935_) {
+
+ if (!this.f_20935_.m_41619_()) {
+ f_20936_ = net.minecraftforge.event.ForgeEventFactory.onItemUseTick(this, f_20935_, f_20936_);
+ if (f_20936_ > 0)
+ f_20935_.onUsingTick(this, f_20936_);
+ }
+
this.m_142106_(this.f_20935_);
} else {
this.m_5810_();
@@ -2833,7 +_,7 @@
private boolean m_21332_() {
int i = this.m_21212_();
- FoodProperties foodproperties = this.f_20935_.m_41720_().m_41473_();
+ FoodProperties foodproperties = this.f_20935_.getFoodProperties(this);
boolean flag = foodproperties != null && foodproperties.m_38748_();
flag |= i <= this.f_20935_.m_41779_() - 7;
return flag && i % 4 == 0;
@@ -2863,8 +_,10 @@
public void m_6672_(InteractionHand p_21159_) {
ItemStack itemstack = this.m_21120_(p_21159_);
if (!itemstack.m_41619_() && !this.m_6117_()) {
+ int duration = net.minecraftforge.event.ForgeEventFactory.onItemUseStart(this, itemstack, itemstack.m_41779_());
+ if (duration <= 0) return;
this.f_20935_ = itemstack;
- this.f_20936_ = itemstack.m_41779_();
+ this.f_20936_ = duration;
if (!this.f_19853_.f_46443_) {
this.m_21155_(1, true);
this.m_21155_(2, p_21159_ == InteractionHand.OFF_HAND);
@@ -2925,6 +_,9 @@
vec31 = vec31.m_82496_(-this.m_146909_() * ((float)Math.PI / 180F));
vec31 = vec31.m_82524_(-this.m_146908_() * ((float)Math.PI / 180F));
vec31 = vec31.m_82520_(this.m_20185_(), this.m_20188_(), this.m_20189_());
+ if (this.f_19853_ instanceof ServerLevel) //Forge: Fix MC-2518 spawnParticle is nooped on server, need to use server specific variant
+ ((ServerLevel)this.f_19853_).m_8767_(new ItemParticleOption(ParticleTypes.f_123752_, p_21061_), vec31.f_82479_, vec31.f_82480_, vec31.f_82481_, 1, vec3.f_82479_, vec3.f_82480_ + 0.05D, vec3.f_82481_, 0.0D);
+ else
this.f_19853_.m_7106_(new ItemParticleOption(ParticleTypes.f_123752_, p_21061_), vec31.f_82479_, vec31.f_82480_, vec31.f_82481_, vec3.f_82479_, vec3.f_82480_ + 0.05D, vec3.f_82481_);
}
@@ -2938,7 +_,8 @@
} else {
if (!this.f_20935_.m_41619_() && this.m_6117_()) {
this.m_21137_(this.f_20935_, 16);
- ItemStack itemstack = this.f_20935_.m_41671_(this.f_19853_, this);
+ ItemStack copy = this.f_20935_.m_41777_();
+ ItemStack itemstack = net.minecraftforge.event.ForgeEventFactory.onItemUseFinish(this, copy, m_21212_(), this.f_20935_.m_41671_(this.f_19853_, this));
if (itemstack != this.f_20935_) {
this.m_21008_(interactionhand, itemstack);
}
@@ -2964,7 +_,11 @@
public void m_21253_() {
if (!this.f_20935_.m_41619_()) {
+ if (!net.minecraftforge.event.ForgeEventFactory.onUseItemStop(this, f_20935_, this.m_21212_())) {
+ ItemStack copy = this instanceof Player ? f_20935_.m_41777_() : null;
this.f_20935_.m_41674_(this.f_19853_, this, this.m_21212_());
+ if (copy != null && f_20935_.m_41619_()) net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem((Player)this, copy, m_7655_());
+ }
if (this.f_20935_.m_41781_()) {
this.m_21329_();
}
@@ -2989,7 +_,7 @@
public boolean m_21254_() {
if (this.m_6117_() && !this.f_20935_.m_41619_()) {
Item item = this.f_20935_.m_41720_();
- if (item.m_6164_(this.f_20935_) != UseAnim.BLOCK) {
+ if (item.m_6164_(this.f_20935_) != UseAnim.BLOCK && !this.f_20935_.canPerformAction(net.minecraftforge.common.ToolActions.SHIELD_BLOCK)) { // TODO 1.20 only use the tool action
return false;
} else {
return item.m_8105_(this.f_20935_) - this.f_20936_ >= 5;
@@ -3115,8 +_,8 @@
}
BlockState blockstate = this.f_19853_.m_8055_(p_21141_);
- if (blockstate.m_60734_() instanceof BedBlock) {
- this.f_19853_.m_7731_(p_21141_, blockstate.m_61124_(BedBlock.f_49441_, Boolean.valueOf(true)), 3);
+ if (blockstate.isBed(f_19853_, p_21141_, this)) {
+ blockstate.setBedOccupied(f_19853_, p_21141_, this, true);
}
this.m_20124_(Pose.SLEEPING);
@@ -3132,15 +_,15 @@
private boolean m_21334_() {
return this.m_21257_().map((p_147236_) -> {
- return this.f_19853_.m_8055_(p_147236_).m_60734_() instanceof BedBlock;
+ return net.minecraftforge.event.ForgeEventFactory.fireSleepingLocationCheck(this, p_147236_);
}).orElse(false);
}
public void m_5796_() {
this.m_21257_().filter(this.f_19853_::m_46805_).ifPresent((p_147228_) -> {
BlockState blockstate = this.f_19853_.m_8055_(p_147228_);
- if (blockstate.m_60734_() instanceof BedBlock) {
- this.f_19853_.m_7731_(p_147228_, blockstate.m_61124_(BedBlock.f_49441_, Boolean.valueOf(false)), 3);
+ if (blockstate.isBed(f_19853_, p_147228_, this)) {
+ blockstate.setBedOccupied(f_19853_, p_147228_, this, false);
Vec3 vec31 = BedBlock.m_49458_(this.m_6095_(), this.f_19853_, p_147228_, this.m_146908_()).orElseGet(() -> {
BlockPos blockpos = p_147228_.m_7494_();
return new Vec3((double)blockpos.m_123341_() + 0.5D, (double)blockpos.m_123342_() + 0.1D, (double)blockpos.m_123343_() + 0.5D);
@@ -3162,7 +_,9 @@
@Nullable
public Direction m_21259_() {
BlockPos blockpos = this.m_21257_().orElse((BlockPos)null);
- return blockpos != null ? BedBlock.m_49485_(this.f_19853_, blockpos) : null;
+ if (blockpos == null) return Direction.UP;
+ BlockState state = this.f_19853_.m_8055_(blockpos);
+ return !state.isBed(f_19853_, blockpos, this) ? Direction.UP : state.getBedDirection(f_19853_, blockpos);
}
public boolean m_5830_() {
@@ -3178,7 +_,7 @@
}
public ItemStack m_6298_(ItemStack p_21272_) {
- return ItemStack.f_41583_;
+ return net.minecraftforge.common.ForgeHooks.getProjectile(this, p_21272_, ItemStack.f_41583_);
}
public ItemStack m_5584_(Level p_21067_, ItemStack p_21068_) {
@@ -3198,7 +_,7 @@
private void m_21063_(ItemStack p_21064_, Level p_21065_, LivingEntity p_21066_) {
Item item = p_21064_.m_41720_();
if (item.m_41472_()) {
- for(Pair<MobEffectInstance, Float> pair : item.m_41473_().m_38749_()) {
+ for(Pair<MobEffectInstance, Float> pair : p_21064_.getFoodProperties(this).m_38749_()) {
if (!p_21065_.f_46443_ && pair.getFirst() != null && p_21065_.f_46441_.m_188501_() < pair.getSecond()) {
p_21066_.m_7292_(new MobEffectInstance(pair.getFirst()));
}
@@ -3234,6 +_,64 @@
this.m_21166_(p_21191_ == InteractionHand.MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND);
}
+ /* ==== FORGE START ==== */
+ /***
+ * Removes all potion effects that have curativeItem as a curative item for its effect
+ * @param curativeItem The itemstack we are using to cure potion effects
+ */
+ public boolean curePotionEffects(ItemStack curativeItem) {
+ if (this.f_19853_.f_46443_)
+ return false;
+ boolean ret = false;
+ Iterator<MobEffectInstance> itr = this.f_20945_.values().iterator();
+ while (itr.hasNext()) {
+ MobEffectInstance effect = itr.next();
+ if (effect.isCurativeItem(curativeItem) && !net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.living.MobEffectEvent.Remove(this, effect))) {
+ this.m_7285_(effect);
+ itr.remove();
+ ret = true;
+ this.f_20948_ = true;
+ }
+ }
+ return ret;
+ }
+
+ /**
+ * Returns true if the entity's rider (EntityPlayer) should face forward when mounted.
+ * currently only used in vanilla code by pigs.
+ *
+ * @param player The player who is riding the entity.
+ * @return If the player should orient the same direction as this entity.
+ */
+ public boolean shouldRiderFaceForward(Player player) {
+ return this instanceof net.minecraft.world.entity.animal.Pig;
+ }
+
+ private net.minecraftforge.common.util.LazyOptional<?>[] handlers = net.minecraftforge.items.wrapper.EntityEquipmentInvWrapper.create(this);
+
+ @Override
+ public <T> net.minecraftforge.common.util.LazyOptional<T> getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable Direction facing) {
+ if (this.m_6084_() && capability == net.minecraftforge.common.capabilities.ForgeCapabilities.ITEM_HANDLER) {
+ if (facing == null) return handlers[2].cast();
+ else if (facing.m_122434_().m_122478_()) return handlers[0].cast();
+ else if (facing.m_122434_().m_122479_()) return handlers[1].cast();
+ }
+ return super.getCapability(capability, facing);
+ }
+
+ @Override
+ public void invalidateCaps() {
+ super.invalidateCaps();
+ for (int x = 0; x < handlers.length; x++)
+ handlers[x].invalidate();
+ }
+
+ @Override
+ public void reviveCaps() {
+ super.reviveCaps();
+ handlers = net.minecraftforge.items.wrapper.EntityEquipmentInvWrapper.create(this);
+ }
+
public AABB m_6921_() {
if (this.m_6844_(EquipmentSlot.HEAD).m_150930_(Items.f_42683_)) {
float f = 0.5F;
@@ -3244,6 +_,8 @@
}
public static EquipmentSlot m_147233_(ItemStack p_147234_) {
+ final EquipmentSlot slot = p_147234_.getEquipmentSlot();
+ if (slot != null) return slot; // FORGE: Allow modders to set a non-default equipment slot for a stack; e.g. a non-armor chestplate-slot item
Item item = p_147234_.m_41720_();
if (!p_147234_.m_150930_(Items.f_42047_) && (!(item instanceof BlockItem) || !(((BlockItem)item).m_40614_() instanceof AbstractSkullBlock))) {
if (item instanceof ArmorItem) {
@@ -3251,7 +_,7 @@
} else if (p_147234_.m_150930_(Items.f_42741_)) {
return EquipmentSlot.CHEST;
} else {
- return p_147234_.m_150930_(Items.f_42740_) ? EquipmentSlot.OFFHAND : EquipmentSlot.MAINHAND;
+ return p_147234_.canPerformAction(net.minecraftforge.common.ToolActions.SHIELD_BLOCK) ? EquipmentSlot.OFFHAND : EquipmentSlot.MAINHAND;
}
} else {
return EquipmentSlot.HEAD;