1.16: entities part 4

This commit is contained in:
IzzelAliz 2020-08-26 15:21:18 +08:00
parent 90bf29ed3d
commit d18632c55c
20 changed files with 217 additions and 305 deletions

View File

@ -0,0 +1,10 @@
package io.izzel.arclight.common.bridge.world;
import net.minecraft.entity.player.ServerPlayerEntity;
import java.util.Set;
public interface TrackedEntityBridge {
void bridge$setTrackedPlayers(Set<ServerPlayerEntity> trackedPlayers);
}

View File

@ -195,6 +195,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge,
@Shadow public abstract boolean isInLava();
@Shadow protected abstract void setOnFireFromLava();
@Shadow protected boolean firstUpdate;
@Shadow public abstract boolean isSilent();
// @formatter:on
private static final int CURRENT_LEVEL = 2;

View File

@ -2,23 +2,22 @@ package io.izzel.arclight.common.mixin.core.entity;
import io.izzel.arclight.common.bridge.entity.EntityTypeBridge;
import io.izzel.arclight.common.bridge.world.IWorldWriterBridge;
import io.izzel.arclight.common.bridge.world.WorldBridge;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.event.ForgeEventFactory;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import javax.annotation.Nullable;
@ -29,17 +28,34 @@ public abstract class EntityTypeMixin<T extends Entity> implements EntityTypeBri
@Shadow @Nullable public abstract T create(ServerWorld worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean p_220349_7_, boolean p_220349_8_);
// @formatter:on
@Inject(method = "spawn(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/nbt/CompoundNBT;Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;", at = @At("HEAD"))
public void arclight$spawnReason(ServerWorld worldIn, CompoundNBT compound, ITextComponent customName, PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean p_220342_7_, boolean p_220342_8_, CallbackInfoReturnable<T> cir) {
((WorldBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SPAWNER_EGG);
@Inject(method = "spawn(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/nbt/CompoundNBT;Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V"))
private void arclight$spawnReason(ServerWorld worldIn, CompoundNBT compound, ITextComponent customName, PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean p_220342_7_, boolean p_220342_8_, CallbackInfoReturnable<T> cir) {
CreatureSpawnEvent.SpawnReason spawnReason = ((IWorldWriterBridge) worldIn).bridge$getAddEntityReason();
if (spawnReason == null) {
((IWorldWriterBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SPAWNER_EGG);
}
}
public T spawnCreature(ServerWorld worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean flag, boolean flag1, CreatureSpawnEvent.SpawnReason spawnReason) {
T t = this.create(worldIn, compound, customName, playerIn, pos, reason, flag, flag1);
if (t instanceof MobEntity && ForgeEventFactory.doSpecialSpawn((MobEntity) t, worldIn, pos.getX(), pos.getY(), pos.getZ(), null, reason)) {
return null;
@Inject(method = "spawn(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/nbt/CompoundNBT;Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;",
cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At("RETURN"),
slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V")))
private void arclight$returnIfSuccess(ServerWorld worldIn, CompoundNBT compound, ITextComponent customName, PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean p_220342_7_, boolean p_220342_8_, CallbackInfoReturnable<T> cir, T t) {
if (t != null) {
cir.setReturnValue(t.removed ? null : t);
}
return ((IWorldWriterBridge) worldIn).bridge$addEntity(t, spawnReason) ? t : null;
}
public T spawnCreature(ServerWorld worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean p_220342_7_, boolean p_220342_8_, CreatureSpawnEvent.SpawnReason spawnReason) {
T t = this.create(worldIn, compound, customName, playerIn, pos, reason, p_220342_7_, p_220342_8_);
if (t != null) {
if (t instanceof net.minecraft.entity.MobEntity && net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn((net.minecraft.entity.MobEntity) t, worldIn, pos.getX(), pos.getY(), pos.getZ(), null, reason))
return null;
((IWorldWriterBridge) worldIn).bridge$pushAddEntityReason(spawnReason);
worldIn.func_242417_l(t);
return t.removed ? null : t;
}
return null;
}
@Override

View File

@ -298,6 +298,12 @@ public abstract class MobEntityMixin extends LivingEntityMixin implements MobEnt
}
}
@Inject(method = "func_233656_b_", at = @At("RETURN"))
private <T extends MobEntity> void arclight$cleanReason(EntityType<T> p_233656_1_, boolean p_233656_2_, CallbackInfoReturnable<T> cir) {
((WorldBridge) this.world).bridge$pushAddEntityReason(null);
this.arclight$transform = null;
}
public <T extends MobEntity> T a(EntityType<T> entityType, boolean flag, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
((WorldBridge) this.world).bridge$pushAddEntityReason(spawnReason);
bridge$pushTransformReason(transformReason);

View File

@ -1,66 +0,0 @@
package io.izzel.arclight.common.mixin.core.entity.ai.goal;
import io.izzel.arclight.common.bridge.entity.LivingEntityBridge;
import io.izzel.arclight.common.bridge.entity.passive.AnimalEntityBridge;
import net.minecraft.entity.AgeableEntity;
import net.minecraft.entity.ai.goal.BreedGoal;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.passive.TameableEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.world.World;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.event.entity.EntityBreedEvent;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.Random;
@Mixin(BreedGoal.class)
public class BreedGoalMixin {
// @formatter:off
@Shadow @Final protected AnimalEntity animal;
@Shadow protected AnimalEntity targetMate;
@Shadow @Final protected World world;
// @formatter:on
private transient int arclight$exp;
@Inject(method = "spawnBaby", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD,
at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/entity/passive/AnimalEntity;getLoveCause()Lnet/minecraft/entity/player/ServerPlayerEntity;"))
public void arclight$persist(CallbackInfo ci, AgeableEntity ageableEntity) {
if (ageableEntity instanceof TameableEntity && ((TameableEntity) ageableEntity).isTamed()) {
((LivingEntityBridge) ageableEntity).bridge$setPersist(true);
}
ServerPlayerEntity playerEntity = this.animal.getLoveCause();
if (playerEntity == null && this.targetMate.getLoveCause() != null) {
playerEntity = this.targetMate.getLoveCause();
}
arclight$exp = this.animal.getRNG().nextInt(7) + 1;
EntityBreedEvent event = CraftEventFactory.callEntityBreedEvent(ageableEntity, this.animal, this.targetMate, playerEntity, ((AnimalEntityBridge) this.animal).bridge$getBreedItem(), arclight$exp);
if (event.isCancelled()) {
ci.cancel();
return;
}
arclight$exp = event.getExperience();
}
@Inject(method = "spawnBaby", cancellable = true, at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Random;nextInt(I)I"))
public void arclight$returnIfFail(CallbackInfo ci) {
if (arclight$exp <= 0) {
ci.cancel();
}
}
@Redirect(method = "spawnBaby", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Random;nextInt(I)I"))
public int arclight$setExp(Random random, int bound) {
return arclight$exp - 1;
}
}

View File

@ -38,7 +38,7 @@ public abstract class WitherEntityMixin extends CreatureEntityMixin {
@Shadow public abstract int getWatchedTargetId(int head);
@Shadow public abstract void updateWatchedTargetId(int targetOffset, int newId);
@Shadow protected abstract void launchWitherSkullToEntity(int p_82216_1_, LivingEntity p_82216_2_);
@Shadow @Final private static EntityPredicate field_213798_bB;
@Shadow @Final private static EntityPredicate ENEMY_CONDITION;
@Shadow private int blockBreakCounter;
@Shadow @Final public ServerBossInfo bossInfo;
// @formatter:on
@ -56,9 +56,11 @@ public abstract class WitherEntityMixin extends CreatureEntityMixin {
ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), 7.0F, false);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
this.world.createExplosion((WitherEntity) (Object) this, this.posX, this.getPosYEye(), this.posZ, event.getRadius(), event.getFire(), explosion$mode);
this.world.createExplosion((WitherEntity) (Object) this, this.getPosX(), this.getPosYEye(), this.getPosZ(), event.getRadius(), event.getFire(), explosion$mode);
}
if (!this.isSilent()) {
this.world.playBroadcastSound(1023, this.getPosition(), 0);
}
this.world.playBroadcastSound(1023, new BlockPos((WitherEntity) (Object) this), 0);
}
this.setInvulTime(j1);
@ -80,9 +82,9 @@ public abstract class WitherEntityMixin extends CreatureEntityMixin {
if (k3 > 15) {
float f = 10.0F;
float f1 = 5.0F;
double d0 = MathHelper.nextDouble(this.rand, this.posX - 10.0D, this.posX + 10.0D);
double d1 = MathHelper.nextDouble(this.rand, this.posY - 5.0D, this.posY + 5.0D);
double d2 = MathHelper.nextDouble(this.rand, this.posZ - 10.0D, this.posZ + 10.0D);
double d0 = MathHelper.nextDouble(this.rand, this.getPosX() - 10.0D, this.getPosX() + 10.0D);
double d1 = MathHelper.nextDouble(this.rand, this.getPosY() - 5.0D, this.getPosY() + 5.0D);
double d2 = MathHelper.nextDouble(this.rand, this.getPosZ() - 10.0D, this.getPosZ() + 10.0D);
this.launchWitherSkullToCoords(i + 1, d0, d1, d2, true);
this.idleHeadUpdates[i - 1] = 0;
}
@ -103,7 +105,7 @@ public abstract class WitherEntityMixin extends CreatureEntityMixin {
this.updateWatchedTargetId(i, 0);
}
} else {
List<LivingEntity> list = this.world.getTargettableEntitiesWithinAABB(LivingEntity.class, field_213798_bB, (WitherEntity) (Object) this, this.getBoundingBox().grow(20.0D, 8.0D, 20.0D));
List<LivingEntity> list = this.world.getTargettableEntitiesWithinAABB(LivingEntity.class, ENEMY_CONDITION, (WitherEntity) (Object) this, this.getBoundingBox().grow(20.0D, 8.0D, 20.0D));
for (int j2 = 0; j2 < 10 && !list.isEmpty(); ++j2) {
LivingEntity livingentity = list.get(this.rand.nextInt(list.size()));
@ -137,9 +139,9 @@ public abstract class WitherEntityMixin extends CreatureEntityMixin {
if (this.blockBreakCounter > 0) {
--this.blockBreakCounter;
if (this.blockBreakCounter == 0 && ForgeEventFactory.getMobGriefingEvent(this.world, (WitherEntity) (Object) this)) {
int i1 = MathHelper.floor(this.posY);
int l1 = MathHelper.floor(this.posX);
int i2 = MathHelper.floor(this.posZ);
int i1 = MathHelper.floor(this.getPosY());
int l1 = MathHelper.floor(this.getPosX());
int i2 = MathHelper.floor(this.getPosZ());
boolean flag = false;
for (int k2 = -1; k2 <= 1; ++k2) {
@ -161,7 +163,7 @@ public abstract class WitherEntityMixin extends CreatureEntityMixin {
}
if (flag) {
this.world.playEvent(null, 1022, new BlockPos((WitherEntity) (Object) this), 0);
this.world.playEvent(null, 1022, this.getPosition(), 0);
}
}
}

View File

@ -1,15 +1,14 @@
package io.izzel.arclight.common.mixin.core.entity.item;
import io.izzel.arclight.common.bridge.world.WorldBridge;
import io.izzel.arclight.common.mixin.core.entity.projectile.ThrowableEntityMixin;
import net.minecraft.entity.item.EnderPearlEntity;
import net.minecraft.util.math.RayTraceResult;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import io.izzel.arclight.common.mixin.core.entity.projectile.ThrowableEntityMixin;
@Mixin(EnderPearlEntity.class)
public abstract class EnderPearlEntityMixin extends ThrowableEntityMixin {
@ -18,14 +17,4 @@ public abstract class EnderPearlEntityMixin extends ThrowableEntityMixin {
private void arclight$spawnEndermite(RayTraceResult result, CallbackInfo ci) {
((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.ENDER_PEARL);
}
@Inject(method = "onImpact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z"))
private void arclight$entityDamage(RayTraceResult result, CallbackInfo ci) {
CraftEventFactory.entityDamage = (EnderPearlEntity) (Object) this;
}
@Inject(method = "onImpact", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/LivingEntity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z"))
private void arclight$entityDamageReset(RayTraceResult result, CallbackInfo ci) {
CraftEventFactory.entityDamage = null;
}
}

View File

@ -1,6 +1,5 @@
package io.izzel.arclight.common.mixin.core.entity.item;
import io.izzel.arclight.api.ArclightVersion;
import io.izzel.arclight.common.mixin.core.entity.EntityMixin;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
@ -45,11 +44,6 @@ public abstract class TNTEntityMixin extends EntityMixin {
*/
@Overwrite
public void tick() {
if (ArclightVersion.lesserThan(ArclightVersion.v1_15)) {
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
}
if (!this.hasNoGravity()) {
this.setMotion(this.getMotion().add(0.0D, -0.04D, 0.0D));
}
@ -67,11 +61,12 @@ public abstract class TNTEntityMixin extends EntityMixin {
}
this.remove();
} else {
this.handleWaterMovement();
this.func_233566_aG_();
if (this.world.isRemote) {
this.world.addParticle(ParticleTypes.SMOKE, this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D);
this.world.addParticle(ParticleTypes.SMOKE, this.getPosX(), this.getPosY() + 0.5D, this.getPosZ(), 0.0D, 0.0D, 0.0D);
}
}
}
/**
@ -83,7 +78,7 @@ public abstract class TNTEntityMixin extends EntityMixin {
ExplosionPrimeEvent event = new ExplosionPrimeEvent((Explosive) this.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
this.world.createExplosion((TNTEntity) (Object) this, this.posX, this.posY + this.getHeight() / 16.0f, this.posZ, event.getRadius(), event.getFire(), Explosion.Mode.BREAK);
this.world.createExplosion((TNTEntity) (Object) this, this.getPosX(), this.getPosY() + this.getHeight() / 16.0f, this.getPosZ(), event.getRadius(), event.getFire(), Explosion.Mode.BREAK);
}
}
}

View File

@ -6,6 +6,7 @@ import net.minecraft.entity.merchant.villager.VillagerEntity;
import net.minecraft.entity.monster.WitchEntity;
import net.minecraft.entity.passive.IronGolemEntity;
import net.minecraft.item.MerchantOffer;
import net.minecraft.world.server.ServerWorld;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.entity.Villager;
@ -39,17 +40,17 @@ public abstract class VillagerEntityMixin extends AbstractVillagerEntityMixin {
}
}
@Inject(method = "onStruckByLightning", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z"))
private void arclight$transformWitch(LightningBoltEntity lightningBolt, CallbackInfo ci, WitchEntity witchEntity) {
@Inject(method = "func_241841_a", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V"))
private void arclight$transformWitch(ServerWorld serverWorld, LightningBoltEntity lightningBolt, CallbackInfo ci, WitchEntity witchEntity) {
if (CraftEventFactory.callEntityTransformEvent((VillagerEntity) (Object) this, witchEntity, EntityTransformEvent.TransformReason.LIGHTNING).isCancelled()) {
ci.cancel();
} else {
((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.LIGHTNING);
((WorldBridge) serverWorld).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.LIGHTNING);
}
}
@Inject(method = "trySpawnGolem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z"))
private void arclight$ironGolemReason(CallbackInfoReturnable<IronGolemEntity> cir) {
((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.VILLAGE_DEFENSE);
@Inject(method = "trySpawnGolem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V"))
private void arclight$ironGolemReason(ServerWorld world, CallbackInfoReturnable<IronGolemEntity> cir) {
((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.VILLAGE_DEFENSE);
}
}

View File

@ -1,6 +1,7 @@
package io.izzel.arclight.common.mixin.core.entity.monster;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin;
import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.AbstractRaiderEntity;
import net.minecraft.entity.player.PlayerEntity;
@ -15,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(AbstractRaiderEntity.class)
public class AbstractRaiderEntityMixin {
public abstract class AbstractRaiderEntityMixin extends CreatureEntityMixin {
@Inject(method = "onDeath", locals = LocalCapture.CAPTURE_FAILHARD, require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z"))
private void arclight$raid(DamageSource cause, CallbackInfo ci, Entity entity, Raid raid, ItemStack itemStack, PlayerEntity playerEntity) {

View File

@ -1,6 +1,5 @@
package io.izzel.arclight.common.mixin.core.entity.monster;
import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin;
import net.minecraft.entity.monster.WitchEntity;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.spongepowered.asm.mixin.Mixin;
@ -9,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(WitchEntity.class)
public abstract class WitchEntityMixin extends CreatureEntityMixin {
public abstract class WitchEntityMixin extends AbstractRaiderEntityMixin {
@Inject(method = "livingTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/WitchEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z"))
private void arclight$reason(CallbackInfo ci) {

View File

@ -4,20 +4,22 @@ import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.entity.MobEntityBridge;
import io.izzel.arclight.common.bridge.world.WorldBridge;
import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin;
import io.izzel.arclight.mixin.Eject;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ILivingEntityData;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.merchant.villager.VillagerEntity;
import net.minecraft.entity.monster.ZombieEntity;
import net.minecraft.entity.monster.ZombieVillagerEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.DamageSource;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.IWorld;
import net.minecraft.world.IServerWorld;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.event.entity.living.ZombieEvent;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.entity.Zombie;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
@ -34,20 +36,22 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(ZombieEntity.class)
public abstract class ZombieEntityMixin extends CreatureEntityMixin {
@Inject(method = "func_213698_b", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD,
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z"))
private void arclight$drown(EntityType<? extends ZombieEntity> p_213698_1_, CallbackInfo ci, ZombieEntity zombieEntity) {
if (CraftEventFactory.callEntityTransformEvent((ZombieEntity) (Object) this, zombieEntity, EntityTransformEvent.TransformReason.DROWNED).isCancelled()) {
((Zombie) getBukkitEntity()).setConversionTime(-1);
ci.cancel();
} else {
@Inject(method = "func_234341_c_", at = @At("HEAD"))
private void arclight$transformReason(EntityType<? extends ZombieEntity> entityType, CallbackInfo ci) {
this.bridge$pushTransformReason(EntityTransformEvent.TransformReason.DROWNED);
((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.DROWNED);
}
@Inject(method = "func_234341_c_", locals = LocalCapture.CAPTURE_FAILHARD, at = @At("RETURN"))
private void arclight$stopConversion(EntityType<? extends ZombieEntity> entityType, CallbackInfo ci, ZombieEntity zombieEntity) {
if (zombieEntity == null) {
((Zombie) this.bridge$getBukkitEntity()).setConversionTime(-1);
}
}
@Inject(method = "attackEntityFrom", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z"))
private void arclight$spawnWithReason(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir, LivingEntity livingEntity, int i, int j, int k, net.minecraftforge.event.entity.living.ZombieEvent.SummonAidEvent event, ZombieEntity zombieEntity) {
((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.REINFORCEMENTS);
@Inject(method = "attackEntityFrom", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/ZombieEntity;onInitialSpawn(Lnet/minecraft/world/IServerWorld;Lnet/minecraft/world/DifficultyInstance;Lnet/minecraft/entity/SpawnReason;Lnet/minecraft/entity/ILivingEntityData;Lnet/minecraft/nbt/CompoundNBT;)Lnet/minecraft/entity/ILivingEntityData;"))
private void arclight$spawnWithReason(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir, ServerWorld world, LivingEntity livingEntity, int i, int j, int k, ZombieEvent.SummonAidEvent event, ZombieEntity zombieEntity) {
((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.REINFORCEMENTS);
if (livingEntity != null) {
((MobEntityBridge) zombieEntity).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.REINFORCEMENT_TARGET, true);
}
@ -62,22 +66,17 @@ public abstract class ZombieEntityMixin extends CreatureEntityMixin {
}
}
@Redirect(method = "onKillEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/merchant/villager/VillagerEntity;remove()V"))
private void arclight$transformPre(VillagerEntity villagerEntity) {
}
@Inject(method = "onKillEntity", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z"))
private void arclight$transformInfection(LivingEntity entityLivingIn, CallbackInfo ci, VillagerEntity villagerEntity, ZombieVillagerEntity zombieVillagerEntity) {
if (CraftEventFactory.callEntityTransformEvent(villagerEntity, zombieVillagerEntity, EntityTransformEvent.TransformReason.INFECTION).isCancelled()) {
@Eject(method = "func_241847_a", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/merchant/villager/VillagerEntity;func_233656_b_(Lnet/minecraft/entity/EntityType;Z)Lnet/minecraft/entity/MobEntity;"))
private <T extends MobEntity> T arclight$transform(VillagerEntity villagerEntity, EntityType<T> entityType, boolean flag, CallbackInfo ci) {
T t = this.a(entityType, flag, EntityTransformEvent.TransformReason.INFECTION, CreatureSpawnEvent.SpawnReason.INFECTION);
if (t == null) {
ci.cancel();
} else {
villagerEntity.remove();
((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.INFECTION);
}
return t;
}
@Inject(method = "onInitialSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/IWorld;addEntity(Lnet/minecraft/entity/Entity;)Z"))
private void arclight$mount(IWorld worldIn, DifficultyInstance difficultyIn, SpawnReason reason, ILivingEntityData spawnDataIn, CompoundNBT dataTag, CallbackInfoReturnable<ILivingEntityData> cir) {
@Inject(method = "onInitialSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/IServerWorld;addEntity(Lnet/minecraft/entity/Entity;)Z"))
private void arclight$mount(IServerWorld worldIn, DifficultyInstance difficultyIn, SpawnReason reason, ILivingEntityData spawnDataIn, CompoundNBT dataTag, CallbackInfoReturnable<ILivingEntityData> cir) {
((WorldBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.MOUNT);
}
}

View File

@ -1,19 +0,0 @@
package io.izzel.arclight.common.mixin.core.entity.monster;
import io.izzel.arclight.common.bridge.entity.MobEntityBridge;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MobEntity;
import org.bukkit.event.entity.EntityTargetEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(targets = "net.minecraft.entity.monster.ZombiePigmanEntity.HurtByAggressorGoal")
public class ZombiePigmanEntity_HurtByAggressorGoalMixin {
@Inject(method = "setAttackTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;setAttackTarget(Lnet/minecraft/entity/LivingEntity;)V"))
private void arclight$reason(MobEntity mobIn, LivingEntity targetIn, CallbackInfo ci) {
((MobEntityBridge) mobIn).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.TARGET_ATTACKED_NEARBY_ENTITY, true);
}
}

View File

@ -1,11 +1,10 @@
package io.izzel.arclight.common.mixin.core.entity.monster;
import io.izzel.arclight.common.bridge.entity.LivingEntityBridge;
import io.izzel.arclight.common.bridge.world.WorldBridge;
import net.minecraft.entity.merchant.villager.VillagerEntity;
import io.izzel.arclight.mixin.Eject;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.monster.ZombieVillagerEntity;
import net.minecraft.world.server.ServerWorld;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.entity.ZombieVillager;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityPotionEffectEvent;
@ -13,9 +12,7 @@ import org.bukkit.event.entity.EntityTransformEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.UUID;
@ -33,19 +30,15 @@ public abstract class ZombieVillagerEntityMixin extends ZombieEntityMixin {
bridge$pushEffectCause(EntityPotionEffectEvent.Cause.CONVERSION);
}
@Redirect(method = "cureZombie", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/ZombieVillagerEntity;remove()V"))
private void arclight$transformPre(ZombieVillagerEntity zombieVillagerEntity) {
}
@Inject(method = "cureZombie", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;addEntity(Lnet/minecraft/entity/Entity;)Z"))
private void arclight$transform(ServerWorld world, CallbackInfo ci, VillagerEntity villagerEntity) {
if (CraftEventFactory.callEntityTransformEvent((ZombieVillagerEntity)(Object)this, villagerEntity, EntityTransformEvent.TransformReason.CURED).isCancelled()) {
((ZombieVillager) getBukkitEntity()).setConversionTime(-1);
@Eject(method = "cureZombie", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/ZombieVillagerEntity;func_233656_b_(Lnet/minecraft/entity/EntityType;Z)Lnet/minecraft/entity/MobEntity;"))
private <T extends MobEntity> T arclight$cure(ZombieVillagerEntity zombieVillagerEntity, EntityType<T> entityType, boolean flag, CallbackInfo ci) {
T t = this.a(entityType, flag, EntityTransformEvent.TransformReason.CURED, CreatureSpawnEvent.SpawnReason.CURED);
if (t == null) {
((ZombieVillager) this.bridge$getBukkitEntity()).setConversionTime(-1);
ci.cancel();
} else {
this.remove();
((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.CURED);
((LivingEntityBridge) villagerEntity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.CONVERSION);
}
((LivingEntityBridge) t).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.CONVERSION);
}
return t;
}
}

View File

@ -3,6 +3,7 @@ package io.izzel.arclight.common.mixin.core.entity.passive;
import io.izzel.arclight.common.bridge.entity.passive.TurtleEntityBridge;
import net.minecraft.entity.effect.LightningBoltEntity;
import net.minecraft.entity.passive.TurtleEntity;
import net.minecraft.world.server.ServerWorld;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@ -31,13 +32,13 @@ public abstract class TurtleEntityMixin extends AnimalEntityMixin implements Tur
forceDrops = false;
}
@Inject(method = "onStruckByLightning", at = @At("HEAD"))
private void arclight$lightning(LightningBoltEntity lightningBolt, CallbackInfo ci) {
@Inject(method = "func_241841_a", at = @At("HEAD"))
private void arclight$lightning(ServerWorld p_241841_1_, LightningBoltEntity lightningBolt, CallbackInfo ci) {
CraftEventFactory.entityDamage = lightningBolt;
}
@Inject(method = "onStruckByLightning", at = @At("RETURN"))
private void arclight$lightningReset(LightningBoltEntity lightningBolt, CallbackInfo ci) {
@Inject(method = "func_241841_a", at = @At("RETURN"))
private void arclight$lightningReset(ServerWorld p_241841_1_, LightningBoltEntity lightningBolt, CallbackInfo ci) {
CraftEventFactory.entityDamage = null;
}
}

View File

@ -32,7 +32,7 @@ public abstract class TurtleEntity_LayEggGoalMixin extends MoveToBlockGoal {
@Overwrite
public void tick() {
super.tick();
BlockPos blockpos = new BlockPos(this.turtle);
BlockPos blockpos = this.turtle.getPosition();
if (!this.turtle.isInWater() && this.getIsAboveDestination()) {
if (((TurtleEntityBridge) this.turtle).bridge$getDigging() < 1) {
((TurtleEntityBridge) this.turtle).bridge$setDigging(true);

View File

@ -1,15 +1,12 @@
package io.izzel.arclight.common.mixin.core.entity.passive;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.goal.SitGoal;
import net.minecraft.entity.passive.WolfEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
@ -19,38 +16,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(WolfEntity.class)
public abstract class WolfEntityMixin extends TameableEntityMixin {
// @formatter:off
@Shadow public abstract void setAngry(boolean angry);
@Shadow public abstract boolean isAngry();
// @formatter:on
@Override
public boolean setGoalTarget(LivingEntity entityliving, EntityTargetEvent.TargetReason reason, boolean fire) {
if (!super.setGoalTarget(entityliving, reason, fire)) {
return false;
}
entityliving = getAttackingEntity();
if (entityliving == null) {
this.setAngry(false);
} else if (!this.isTamed()) {
this.setAngry(true);
}
return true;
}
@Inject(method = "readAdditional", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundNBT;contains(Ljava/lang/String;I)Z"))
private void arclight$angry(CompoundNBT compound, CallbackInfo ci) {
if (this.getAttackTarget() == null && this.isAngry()) {
this.setAngry(false);
}
}
@Redirect(method = "livingTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/WolfEntity;setAngry(Z)V"))
private void arclight$fixError(WolfEntity wolfEntity, boolean angry) {
}
@Redirect(method = "attackEntityFrom", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ai/goal/SitGoal;setSitting(Z)V"))
private void arclight$handledBy(SitGoal sitGoal, boolean sitting) {
@Redirect(method = "attackEntityFrom", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/WolfEntity;func_233687_w_(Z)V"))
private void arclight$handledBy(WolfEntity wolfEntity, boolean p_233687_1_) {
}
@Inject(method = "setTamed", at = @At("RETURN"))
@ -60,13 +27,13 @@ public abstract class WolfEntityMixin extends TameableEntityMixin {
}
}
@Inject(method = "processInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/WolfEntity;heal(F)V"))
private void arclight$healReason(PlayerEntity player, Hand hand, CallbackInfoReturnable<Boolean> cir) {
@Inject(method = "func_230254_b_", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/WolfEntity;heal(F)V"))
private void arclight$healReason(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResultType> cir) {
bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.EATING);
}
@Inject(method = "processInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/WolfEntity;setAttackTarget(Lnet/minecraft/entity/LivingEntity;)V"))
private void arclight$attackReason(PlayerEntity player, Hand hand, CallbackInfoReturnable<Boolean> cir) {
@Inject(method = "func_230254_b_", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/WolfEntity;setAttackTarget(Lnet/minecraft/entity/LivingEntity;)V"))
private void arclight$attackReason(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResultType> cir) {
bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.FORGOT_TARGET, true);
}
}

View File

@ -4,7 +4,6 @@ import io.izzel.arclight.common.bridge.entity.LivingEntityBridge;
import net.minecraft.entity.Entity;
import net.minecraft.entity.projectile.WitherSkullEntity;
import net.minecraft.util.math.EntityRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import org.bukkit.Bukkit;
@ -20,14 +19,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(WitherSkullEntity.class)
public abstract class WitherSkullEntityMixin extends DamagingProjectileEntityMixin {
@Inject(method = "onImpact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;heal(F)V"))
private void arclight$heal(RayTraceResult result, CallbackInfo ci) {
((LivingEntityBridge) this.shootingEntity).bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.WITHER);
@Inject(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;heal(F)V"))
private void arclight$heal(EntityRayTraceResult result, CallbackInfo ci) {
((LivingEntityBridge) this.func_234616_v_()).bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.WITHER);
}
@Inject(method = "onImpact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z"))
private void arclight$effect(RayTraceResult result, CallbackInfo ci) {
((LivingEntityBridge) ((EntityRayTraceResult) result).getEntity()).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK);
@Inject(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z"))
private void arclight$effect(EntityRayTraceResult result, CallbackInfo ci) {
((LivingEntityBridge) result.getEntity()).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK);
}
@Redirect(method = "onImpact", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;createExplosion(Lnet/minecraft/entity/Entity;DDDFZLnet/minecraft/world/Explosion$Mode;)Lnet/minecraft/world/Explosion;"))

View File

@ -39,4 +39,14 @@ public interface IServerWorldMixin extends IWorld, IWorldBridge, WorldBridge {
this.addEntity(next);
}
}
default boolean addAllEntities(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
Iterator<Entity> iterator = entity.getSelfAndPassengers().iterator();
while (iterator.hasNext()) {
Entity next = iterator.next();
bridge$pushAddEntityReason(reason);
this.addEntity(next);
}
return !entity.removed;
}
}

View File

@ -1,11 +1,13 @@
package io.izzel.arclight.common.mixin.core.world;
import com.google.common.collect.Lists;
import com.mojang.datafixers.util.Pair;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import io.izzel.arclight.common.bridge.world.TrackedEntityBridge;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.ai.attributes.AttributeMap;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.ai.attributes.ModifiableAttributeInstance;
import net.minecraft.entity.item.ItemFrameEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.projectile.AbstractArrowEntity;
@ -27,7 +29,7 @@ import net.minecraft.network.play.server.SSetPassengersPacket;
import net.minecraft.network.play.server.SSpawnMobPacket;
import net.minecraft.potion.EffectInstance;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.TrackedEntity;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.storage.MapData;
@ -45,6 +47,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
@ -52,7 +55,7 @@ import java.util.Set;
import java.util.function.Consumer;
@Mixin(TrackedEntity.class)
public abstract class TrackedEntityMixin {
public abstract class TrackedEntityMixin implements TrackedEntityBridge {
// @formatter:off
@Shadow @Final private Entity trackedEntity;
@ -72,7 +75,7 @@ public abstract class TrackedEntityMixin {
@Shadow private long encodedPosZ;
@Shadow private boolean onGround;
@Shadow @Final private boolean sendVelocityUpdates;
@Shadow private Vec3d velocity;
@Shadow private Vector3d velocity;
@Shadow private int encodedRotationYawHead;
@Shadow protected abstract void sendPacket(IPacket<?> p_219451_1_);
// @formatter:on
@ -93,6 +96,11 @@ public abstract class TrackedEntityMixin {
this.trackedPlayers = set;
}
@Override
public void bridge$setTrackedPlayers(Set<ServerPlayerEntity> trackedPlayers) {
this.trackedPlayers = trackedPlayers;
}
/**
* @author IzzelAliz
* @reason
@ -105,15 +113,15 @@ public abstract class TrackedEntityMixin {
this.sendPacket(new SSetPassengersPacket(this.trackedEntity));
}
if (this.trackedEntity instanceof ItemFrameEntity) {
ItemFrameEntity entityitemframe = (ItemFrameEntity) this.trackedEntity;
ItemStack itemstack = entityitemframe.getDisplayedItem();
if (this.updateCounter % 10 == 0 && itemstack.getItem() instanceof FilledMapItem) {
MapData worldmap = FilledMapItem.getMapData(itemstack, this.world);
for (ServerPlayerEntity entityplayer : this.trackedPlayers) {
worldmap.updateVisiblePlayers(entityplayer, itemstack);
IPacket<?> packet = ((FilledMapItem) itemstack.getItem()).getUpdatePacket(itemstack, this.world, entityplayer);
if (packet != null) {
entityplayer.connection.sendPacket(packet);
ItemFrameEntity itemframeentity = (ItemFrameEntity) this.trackedEntity;
ItemStack itemstack = itemframeentity.getDisplayedItem();
MapData mapdata = FilledMapItem.getMapData(itemstack, this.world);
if (this.updateCounter % 10 == 0 && mapdata != null) {
for (ServerPlayerEntity serverplayerentity : this.trackedPlayers) {
mapdata.updateVisiblePlayers(serverplayerentity, itemstack);
IPacket<?> ipacket = ((FilledMapItem) itemstack.getItem()).getUpdatePacket(itemstack, this.world, serverplayerentity);
if (ipacket != null) {
serverplayerentity.connection.sendPacket(ipacket);
}
}
}
@ -121,72 +129,72 @@ public abstract class TrackedEntityMixin {
}
if (this.updateCounter % this.updateFrequency == 0 || this.trackedEntity.isAirBorne || this.trackedEntity.getDataManager().isDirty()) {
if (this.trackedEntity.isPassenger()) {
int i = MathHelper.floor(this.trackedEntity.rotationYaw * 256.0f / 360.0f);
int j = MathHelper.floor(this.trackedEntity.rotationPitch * 256.0f / 360.0f);
boolean flag = Math.abs(i - this.encodedRotationYaw) >= 1 || Math.abs(j - this.encodedRotationPitch) >= 1;
if (flag) {
this.packetConsumer.accept(new SEntityPacket.LookPacket(this.trackedEntity.getEntityId(), (byte) i, (byte) j, this.trackedEntity.onGround));
this.encodedRotationYaw = i;
this.encodedRotationPitch = j;
int i1 = MathHelper.floor(this.trackedEntity.rotationYaw * 256.0F / 360.0F);
int l1 = MathHelper.floor(this.trackedEntity.rotationPitch * 256.0F / 360.0F);
boolean flag2 = Math.abs(i1 - this.encodedRotationYaw) >= 1 || Math.abs(l1 - this.encodedRotationPitch) >= 1;
if (flag2) {
this.packetConsumer.accept(new SEntityPacket.LookPacket(this.trackedEntity.getEntityId(), (byte) i1, (byte) l1, this.trackedEntity.isOnGround()));
this.encodedRotationYaw = i1;
this.encodedRotationPitch = l1;
}
this.updateEncodedPosition();
this.sendMetadata();
this.riding = true;
} else {
++this.ticksSinceAbsoluteTeleport;
int i = MathHelper.floor(this.trackedEntity.rotationYaw * 256.0f / 360.0f);
int j = MathHelper.floor(this.trackedEntity.rotationPitch * 256.0f / 360.0f);
Vec3d vec3d = this.trackedEntity.getPositionVec().subtract(SEntityPacket.func_218744_a(this.encodedPosX, this.encodedPosY, this.encodedPosZ));
boolean flag2 = vec3d.lengthSquared() >= 7.62939453125E-6;
IPacket<?> packet2 = null;
boolean flag3 = flag2 || this.updateCounter % 60 == 0;
boolean flag4 = Math.abs(i - this.encodedRotationYaw) >= 1 || Math.abs(j - this.encodedRotationPitch) >= 1;
if (flag3) {
int l = MathHelper.floor(this.trackedEntity.rotationYaw * 256.0F / 360.0F);
int k1 = MathHelper.floor(this.trackedEntity.rotationPitch * 256.0F / 360.0F);
Vector3d vector3d = this.trackedEntity.getPositionVec().subtract(SEntityPacket.func_218744_a(this.encodedPosX, this.encodedPosY, this.encodedPosZ));
boolean flag3 = vector3d.lengthSquared() >= (double) 7.6293945E-6F;
IPacket<?> ipacket1 = null;
boolean flag4 = flag3 || this.updateCounter % 60 == 0;
boolean flag = Math.abs(l - this.encodedRotationYaw) >= 1 || Math.abs(k1 - this.encodedRotationPitch) >= 1;
if (flag4) {
this.updateEncodedPosition();
}
if (flag4) {
this.encodedRotationYaw = i;
this.encodedRotationPitch = j;
if (flag) {
this.encodedRotationYaw = l;
this.encodedRotationPitch = k1;
}
if (this.updateCounter > 0 || this.trackedEntity instanceof AbstractArrowEntity) {
long k = SEntityPacket.func_218743_a(vec3d.x);
long l = SEntityPacket.func_218743_a(vec3d.y);
long i2 = SEntityPacket.func_218743_a(vec3d.z);
boolean flag5 = k < -32768L || k > 32767L || l < -32768L || l > 32767L || i2 < -32768L || i2 > 32767L;
if (!flag5 && this.ticksSinceAbsoluteTeleport <= 400 && !this.riding && this.onGround == this.trackedEntity.onGround) {
if ((!flag3 || !flag4) && !(this.trackedEntity instanceof AbstractArrowEntity)) {
if (flag3) {
packet2 = new SEntityPacket.RelativeMovePacket(this.trackedEntity.getEntityId(), (short) k, (short) l, (short) i2, this.trackedEntity.onGround);
} else if (flag4) {
packet2 = new SEntityPacket.LookPacket(this.trackedEntity.getEntityId(), (byte) i, (byte) j, this.trackedEntity.onGround);
long i = SEntityPacket.func_218743_a(vector3d.x);
long j = SEntityPacket.func_218743_a(vector3d.y);
long k = SEntityPacket.func_218743_a(vector3d.z);
boolean flag1 = i < -32768L || i > 32767L || j < -32768L || j > 32767L || k < -32768L || k > 32767L;
if (!flag1 && this.ticksSinceAbsoluteTeleport <= 400 && !this.riding && this.onGround == this.trackedEntity.isOnGround()) {
if ((!flag4 || !flag) && !(this.trackedEntity instanceof AbstractArrowEntity)) {
if (flag4) {
ipacket1 = new SEntityPacket.RelativeMovePacket(this.trackedEntity.getEntityId(), (short) ((int) i), (short) ((int) j), (short) ((int) k), this.trackedEntity.isOnGround());
} else if (flag) {
ipacket1 = new SEntityPacket.LookPacket(this.trackedEntity.getEntityId(), (byte) l, (byte) k1, this.trackedEntity.isOnGround());
}
} else {
packet2 = new SEntityPacket.MovePacket(this.trackedEntity.getEntityId(), (short) k, (short) l, (short) i2, (byte) i, (byte) j, this.trackedEntity.onGround);
ipacket1 = new SEntityPacket.MovePacket(this.trackedEntity.getEntityId(), (short) ((int) i), (short) ((int) j), (short) ((int) k), (byte) l, (byte) k1, this.trackedEntity.isOnGround());
}
} else {
this.onGround = this.trackedEntity.onGround;
this.onGround = this.trackedEntity.isOnGround();
this.ticksSinceAbsoluteTeleport = 0;
packet2 = new SEntityTeleportPacket(this.trackedEntity);
ipacket1 = new SEntityTeleportPacket(this.trackedEntity);
}
}
if ((this.sendVelocityUpdates || this.trackedEntity.isAirBorne || (this.trackedEntity instanceof LivingEntity && ((LivingEntity) this.trackedEntity).isElytraFlying())) && this.updateCounter > 0) {
Vec3d vec3d2 = this.trackedEntity.getMotion();
double d0 = vec3d2.squareDistanceTo(this.velocity);
if (d0 > 1.0E-7 || (d0 > 0.0 && vec3d2.lengthSquared() == 0.0)) {
this.velocity = vec3d2;
if ((this.sendVelocityUpdates || this.trackedEntity.isAirBorne || this.trackedEntity instanceof LivingEntity && ((LivingEntity) this.trackedEntity).isElytraFlying()) && this.updateCounter > 0) {
Vector3d vector3d1 = this.trackedEntity.getMotion();
double d0 = vector3d1.squareDistanceTo(this.velocity);
if (d0 > 1.0E-7D || d0 > 0.0D && vector3d1.lengthSquared() == 0.0D) {
this.velocity = vector3d1;
this.packetConsumer.accept(new SEntityVelocityPacket(this.trackedEntity.getEntityId(), this.velocity));
}
}
if (packet2 != null) {
this.packetConsumer.accept(packet2);
if (ipacket1 != null) {
this.packetConsumer.accept(ipacket1);
}
this.sendMetadata();
this.riding = false;
}
int i = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f);
if (Math.abs(i - this.encodedRotationYawHead) >= 1) {
this.packetConsumer.accept(new SEntityHeadLookPacket(this.trackedEntity, (byte) i));
this.encodedRotationYawHead = i;
int j1 = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0F / 360.0F);
if (Math.abs(j1 - this.encodedRotationYawHead) >= 1) {
this.packetConsumer.accept(new SEntityHeadLookPacket(this.trackedEntity, (byte) j1));
this.encodedRotationYawHead = j1;
}
this.trackedEntity.isAirBorne = false;
}
@ -216,11 +224,12 @@ public abstract class TrackedEntityMixin {
a(consumer, playerEntity);
}
public void a(final Consumer<IPacket<?>> consumer, final ServerPlayerEntity entityplayer) {
public void a(Consumer<IPacket<?>> consumer, ServerPlayerEntity entityplayer) {
MobEntity entityinsentient;
if (this.trackedEntity.removed) {
return;
}
final IPacket<?> packet = this.trackedEntity.createSpawnPacket();
IPacket<?> packet = this.trackedEntity.createSpawnPacket();
this.encodedRotationYawHead = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f);
consumer.accept(packet);
if (!this.trackedEntity.getDataManager().isEmpty()) {
@ -228,8 +237,7 @@ public abstract class TrackedEntityMixin {
}
boolean flag = this.sendVelocityUpdates;
if (this.trackedEntity instanceof LivingEntity) {
final AttributeMap attributemapserver = (AttributeMap) ((LivingEntity) this.trackedEntity).getAttributes();
final Collection<IAttributeInstance> collection = attributemapserver.getWatchedAttributes();
Collection<ModifiableAttributeInstance> collection = ((LivingEntity) this.trackedEntity).getAttributeManager().getWatchedInstances();
if (this.trackedEntity.getEntityId() == entityplayer.getEntityId()) {
((ServerPlayerEntityBridge) this.trackedEntity).bridge$getBukkitEntity().injectScaledMaxHealth(collection, false);
}
@ -245,18 +253,21 @@ public abstract class TrackedEntityMixin {
consumer.accept(new SEntityVelocityPacket(this.trackedEntity.getEntityId(), this.velocity));
}
if (this.trackedEntity instanceof LivingEntity) {
for (final EquipmentSlotType enumitemslot : EquipmentSlotType.values()) {
final ItemStack itemstack = ((LivingEntity) this.trackedEntity).getItemStackFromSlot(enumitemslot);
if (!itemstack.isEmpty()) {
consumer.accept(new SEntityEquipmentPacket(this.trackedEntity.getEntityId(), enumitemslot, itemstack));
ArrayList<Pair<EquipmentSlotType, ItemStack>> list = Lists.newArrayList();
for (EquipmentSlotType enumitemslot : EquipmentSlotType.values()) {
ItemStack itemstack = ((LivingEntity) this.trackedEntity).getItemStackFromSlot(enumitemslot);
if (itemstack.isEmpty()) continue;
list.add(Pair.of(enumitemslot, itemstack.copy()));
}
if (!list.isEmpty()) {
consumer.accept(new SEntityEquipmentPacket(this.trackedEntity.getEntityId(), list));
}
}
this.encodedRotationYawHead = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f);
consumer.accept(new SEntityHeadLookPacket(this.trackedEntity, (byte) this.encodedRotationYawHead));
if (this.trackedEntity instanceof LivingEntity) {
final LivingEntity entityliving = (LivingEntity) this.trackedEntity;
for (final EffectInstance mobeffect : entityliving.getActivePotionEffects()) {
LivingEntity entityliving = (LivingEntity) this.trackedEntity;
for (EffectInstance mobeffect : entityliving.getActivePotionEffects()) {
consumer.accept(new SPlayEntityEffectPacket(this.trackedEntity.getEntityId(), mobeffect));
}
}
@ -266,16 +277,13 @@ public abstract class TrackedEntityMixin {
if (this.trackedEntity.isPassenger()) {
consumer.accept(new SSetPassengersPacket(this.trackedEntity.getRidingEntity()));
}
if (this.trackedEntity instanceof MobEntity) {
MobEntity mobentity = (MobEntity) this.trackedEntity;
if (mobentity.getLeashed()) {
consumer.accept(new SMountEntityPacket(mobentity, mobentity.getLeashHolder()));
}
if (this.trackedEntity instanceof MobEntity && (entityinsentient = (MobEntity) this.trackedEntity).getLeashed()) {
consumer.accept(new SMountEntityPacket(entityinsentient, entityinsentient.getLeashHolder()));
}
}
@Inject(method = "sendMetadata", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/TrackedEntity;sendPacket(Lnet/minecraft/network/IPacket;)V"))
private void arclight$sendScaledHealth(CallbackInfo ci, EntityDataManager entitydatamanager, AttributeMap attributemap, Set<IAttributeInstance> set) {
private void arclight$sendScaledHealth(CallbackInfo ci, EntityDataManager entitydatamanager, Set<ModifiableAttributeInstance> set) {
if (this.trackedEntity instanceof ServerPlayerEntity) {
((ServerPlayerEntityBridge) this.trackedEntity).bridge$getBukkitEntity().injectScaledMaxHealth(set, false);
}