From f681dd04560a954801d6f49bde512d797681f76d Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Wed, 26 Jan 2022 18:33:58 +0800 Subject: [PATCH] Update upstream --- .../server/commands/TimeCommandMixin.java | 14 ++++++++ .../mixin/core/world/entity/EntityMixin.java | 19 +++++++++- .../core/world/entity/LivingEntityMixin.java | 2 -- .../world/entity/animal/DolphinMixin.java | 11 ++++++ .../entity/animal/axolotl/AxolotlMixin.java | 36 +++++++++++++++++++ .../Evoker_EvokerSummonSpellGoalMixin.java | 20 +++++++++++ .../StructureTemplateMixin.java | 33 +++++++++++++++++ .../resources/META-INF/accesstransformer.cfg | 2 ++ .../main/resources/mixins.arclight.core.json | 3 ++ 9 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/axolotl/AxolotlMixin.java create mode 100644 arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Evoker_EvokerSummonSpellGoalMixin.java create mode 100644 arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/levelgen/structure/templatesystem/StructureTemplateMixin.java diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/TimeCommandMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/TimeCommandMixin.java index 7e8be259..44ce1f9c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/TimeCommandMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/TimeCommandMixin.java @@ -1,6 +1,8 @@ package io.izzel.arclight.common.mixin.core.server.commands; import io.izzel.arclight.common.bridge.core.world.server.ServerWorldBridge; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.commands.TimeCommand; import net.minecraft.server.level.ServerLevel; import org.bukkit.Bukkit; @@ -9,9 +11,21 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; +import java.util.List; + @Mixin(TimeCommand.class) public class TimeCommandMixin { + @Redirect(method = "setTime", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getAllLevels()Ljava/lang/Iterable;")) + private static Iterable arclight$useSourceLevel1(MinecraftServer server, CommandSourceStack source) { + return List.of(source.getLevel()); + } + + @Redirect(method = "addTime", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getAllLevels()Ljava/lang/Iterable;")) + private static Iterable arclight$useSourceLevel2(MinecraftServer server, CommandSourceStack source) { + return List.of(source.getLevel()); + } + @Redirect(method = "addTime", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setDayTime(J)V")) private static void arclight$addTimeEvent(ServerLevel serverWorld, long time) { TimeSkipEvent event = new TimeSkipEvent(((ServerWorldBridge) serverWorld).bridge$getWorld(), TimeSkipEvent.SkipReason.COMMAND, time - serverWorld.getDayTime()); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java index 0ed6a9d1..6455b6ed 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java @@ -214,6 +214,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, @Shadow public abstract void gameEvent(GameEvent p_146853_, @org.jetbrains.annotations.Nullable Entity p_146854_); @Shadow public abstract void setTicksFrozen(int p_146918_); @Shadow public abstract void setSharedFlagOnFire(boolean p_146869_); + @Shadow public abstract int getMaxAirSupply(); // @formatter:on private static final int CURRENT_LEVEL = 2; @@ -224,6 +225,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, public boolean forceExplosionKnockback; // SPIGOT-949 public boolean persistentInvisibility = false; public BlockPos lastLavaContact; + public int maxAirTicks = getDefaultMaxAirSupply(); private CraftEntity bukkitEntity; @@ -272,6 +274,15 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, return isChunkLoaded(); } + public int getDefaultMaxAirSupply() { + return Entity.TOTAL_AIR_SUPPLY; + } + + @Inject(method = "getMaxAirSupply", cancellable = true, at = @At("RETURN")) + private void arclight$useBukkitMaxAir(CallbackInfoReturnable cir) { + cir.setReturnValue(this.maxAirTicks); + } + @Inject(method = "setPose", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/network/syncher/SynchedEntityData;set(Lnet/minecraft/network/syncher/EntityDataAccessor;Ljava/lang/Object;)V")) public void arclight$setPose$EntityPoseChangeEvent(Pose poseIn, CallbackInfo callbackInfo) { if (poseIn == this.getPose()) { @@ -523,6 +534,9 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, if (this.persistentInvisibility) { compound.putBoolean("Bukkit.invisible", this.persistentInvisibility); } + if (maxAirTicks != getDefaultMaxAirSupply()) { + compound.putInt("Bukkit.MaxAirSupply", getMaxAirSupply()); + } } @Inject(method = "saveWithoutId", at = @At(value = "RETURN")) @@ -578,6 +592,9 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, this.setInvisible(bukkitInvisible); this.persistentInvisibility = bukkitInvisible; } + if (compound.contains("Bukkit.MaxAirSupply")) { + maxAirTicks = compound.getInt("Bukkit.MaxAirSupply"); + } // CraftBukkit end } @@ -920,7 +937,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, return null; } ServerLevel worldFinal = world = ((CraftWorld) event.getTo().getWorld()).getHandle(); - blockpos1 = new BlockPos(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()); + blockpos1 = worldFinal.getWorldBorder().clampToBounds(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()); return this.getExitPortal(world, blockpos1, flag2, worldborder, event.getSearchRadius(), event.getCanCreatePortal(), event.getCreationRadius()).map((result) -> { BlockState blockstate = this.level.getBlockState(this.portalEntrancePos); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java index 858e43fd..be92be19 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java @@ -185,7 +185,6 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt // @formatter:on public int expToDrop; - public int maxAirTicks; public boolean forceDrops; public CraftAttributeMap craftAttributes; public boolean collides; @@ -199,7 +198,6 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt @Inject(method = "", at = @At("RETURN")) private void arclight$init(EntityType type, Level worldIn, CallbackInfo ci) { - this.maxAirTicks = 300; this.collides = true; this.craftAttributes = new CraftAttributeMap(this.attributes); this.entityData.set(DATA_HEALTH_ID, (float) this.getAttributeValue(Attributes.MAX_HEALTH)); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/DolphinMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/DolphinMixin.java index c63b1033..a42b4ba0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/DolphinMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/DolphinMixin.java @@ -8,6 +8,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; import net.minecraft.world.entity.animal.Dolphin; import net.minecraft.world.entity.item.ItemEntity; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Dolphin.class) public abstract class DolphinMixin extends PathfinderMobMixin { @@ -18,4 +19,14 @@ public abstract class DolphinMixin extends PathfinderMobMixin { ci.cancel(); } } + + @Inject(method = "getMaxAirSupply", cancellable = true, at = @At("RETURN")) + private void arclight$useBukkitMaxAir(CallbackInfoReturnable cir) { + cir.setReturnValue(this.maxAirTicks); + } + + @Override + public int getDefaultMaxAirSupply() { + return Dolphin.TOTAL_AIR_SUPPLY; + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/axolotl/AxolotlMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/axolotl/AxolotlMixin.java new file mode 100644 index 00000000..4b7926b3 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/axolotl/AxolotlMixin.java @@ -0,0 +1,36 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal.axolotl; + +import io.izzel.arclight.common.bridge.core.entity.MobEntityBridge; +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.world.entity.animal.Dolphin; +import net.minecraft.world.entity.animal.axolotl.Axolotl; +import net.minecraft.world.entity.player.Player; +import org.bukkit.event.entity.EntityPotionEffectEvent; +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.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Axolotl.class) +public abstract class AxolotlMixin extends AnimalMixin { + + @Shadow @Final private static int AXOLOTL_TOTAL_AIR_SUPPLY; + + @Inject(method = "getMaxAirSupply", cancellable = true, at = @At("RETURN")) + private void arclight$useBukkitMaxAir(CallbackInfoReturnable cir) { + cir.setReturnValue(this.maxAirTicks); + } + + @Override + public int getDefaultMaxAirSupply() { + return AXOLOTL_TOTAL_AIR_SUPPLY; + } + + @Inject(method = "applySupportingEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)Z")) + private void arclight$cause(Player player, CallbackInfo ci) { + ((MobEntityBridge) player).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.AXOLOTL); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Evoker_EvokerSummonSpellGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Evoker_EvokerSummonSpellGoalMixin.java new file mode 100644 index 00000000..ae72472b --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Evoker_EvokerSummonSpellGoalMixin.java @@ -0,0 +1,20 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import io.izzel.arclight.common.bridge.core.world.WorldBridge; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.monster.Evoker; +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 org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(targets = "net.minecraft.world.entity.monster.Evoker$EvokerSummonSpellGoal") +public class Evoker_EvokerSummonSpellGoalMixin { + + @Inject(method = "performSpellCasting", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)V")) + private void arclight$reason(CallbackInfo ci, ServerLevel level) { + ((WorldBridge) level).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SPELL); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/levelgen/structure/templatesystem/StructureTemplateMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/levelgen/structure/templatesystem/StructureTemplateMixin.java new file mode 100644 index 00000000..3c0a1239 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/levelgen/structure/templatesystem/StructureTemplateMixin.java @@ -0,0 +1,33 @@ +package io.izzel.arclight.common.mixin.core.world.level.levelgen.structure.templatesystem; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; +import org.bukkit.craftbukkit.v.persistence.CraftPersistentDataContainer; +import org.bukkit.craftbukkit.v.persistence.CraftPersistentDataTypeRegistry; +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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(StructureTemplate.class) +public class StructureTemplateMixin { + + private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry(); + public CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); + + @Inject(method = "save", at = @At("RETURN")) + private void arclight$savePdc(CompoundTag tag, CallbackInfoReturnable cir) { + if (!this.persistentDataContainer.isEmpty()) { + tag.put("BukkitValues", this.persistentDataContainer.toTagCompound()); + } + } + + @Inject(method = "load", at = @At("RETURN")) + private void arclight$loadPdc(CompoundTag tag, CallbackInfo ci) { + var base = tag.get("BukkitValues"); + if (base instanceof CompoundTag compoundTag) { + this.persistentDataContainer.putAll(compoundTag); + } + } +} diff --git a/arclight-common/src/main/resources/META-INF/accesstransformer.cfg b/arclight-common/src/main/resources/META-INF/accesstransformer.cfg index 2b94e4bd..8543f5e4 100644 --- a/arclight-common/src/main/resources/META-INF/accesstransformer.cfg +++ b/arclight-common/src/main/resources/META-INF/accesstransformer.cfg @@ -3,6 +3,8 @@ public net.minecraft.server.level.PlayerRespawnLogic m_183928_(Lnet/minecraft/se public net.minecraft.world.entity.npc.Villager m_35524_()V # releaseAllPois public net.minecraft.world.entity.Entity f_19861_ # onGround public net.minecraft.world.level.block.ChestBlock$2$1 +public net.minecraft.world.entity.animal.horse.SkeletonHorse f_30892_ # trapTime +public net.minecraft.world.entity.monster.Vindicator f_34071_ # Here's Johnny! # Arclight 1.17 public net.minecraft.world.entity.Entity f_19851_ public net.minecraft.world.entity.raid.Raider$HoldGroundAttackGoal diff --git a/arclight-common/src/main/resources/mixins.arclight.core.json b/arclight-common/src/main/resources/mixins.arclight.core.json index 6802eb6a..8d93e982 100644 --- a/arclight-common/src/main/resources/mixins.arclight.core.json +++ b/arclight-common/src/main/resources/mixins.arclight.core.json @@ -150,6 +150,7 @@ "world.entity.animal.Turtle_LayEggGoalMixin", "world.entity.animal.TurtleMixin", "world.entity.animal.WolfMixin", + "world.entity.animal.axolotl.AxolotlMixin", "world.entity.animal.horse.AbstractHorseMixin", "world.entity.animal.horse.LlamaMixin", "world.entity.animal.horse.TraderLlamaEntity_FollowTraderGoalMixin", @@ -171,6 +172,7 @@ "world.entity.monster.EnderMan_EndermanLeaveBlockGoalMixin", "world.entity.monster.EnderMan_EndermanTakeBlockGoalMixin", "world.entity.monster.EnderManMixin", + "world.entity.monster.Evoker_EvokerSummonSpellGoalMixin", "world.entity.monster.Ghast_GhastShootFireballGoalMixin", "world.entity.monster.HuskMixin", "world.entity.monster.Illusioner_BlindnessSpellGoalMixin", @@ -431,6 +433,7 @@ "world.level.entity.PersistentEntitySectionManagerMixin", "world.level.gameevent.vibrations.VibrationListenerMixin", "world.level.levelgen.ChunkGeneratorMixin", + "world.level.levelgen.structure.templatesystem.StructureTemplateMixin", "world.level.portal.PortalForcerMixin", "world.level.saveddata.maps.MapDataMixin", "world.level.saveddata.maps.MapItemSavedData_HoldingPlayerMixin",