diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEntityMixin.java index c1ea705c..a26d069f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEntityMixin.java @@ -4,14 +4,11 @@ import io.izzel.arclight.common.mod.server.entity.ArclightFakePlayer; import io.izzel.arclight.common.mod.server.entity.ArclightModChestedHorse; import io.izzel.arclight.common.mod.server.entity.ArclightModEntity; import io.izzel.arclight.common.mod.server.entity.ArclightModHorse; -import io.izzel.arclight.common.mod.server.entity.ArclightModLivingEntity; import io.izzel.arclight.common.mod.server.entity.ArclightModMinecart; import io.izzel.arclight.common.mod.server.entity.ArclightModMinecartContainer; import io.izzel.arclight.common.mod.server.entity.ArclightModMob; import io.izzel.arclight.common.mod.server.entity.ArclightModProjectile; import io.izzel.arclight.common.mod.server.entity.ArclightModRaider; -import io.izzel.arclight.common.mod.util.ResourceLocationUtil; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.AgeableMob; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.FlyingMob; @@ -26,15 +23,13 @@ import net.minecraft.world.entity.raid.Raider; import net.minecraft.world.entity.vehicle.AbstractMinecart; import net.minecraft.world.entity.vehicle.AbstractMinecartContainer; import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftAgeable; import org.bukkit.craftbukkit.v.entity.CraftEntity; import org.bukkit.craftbukkit.v.entity.CraftFlying; import org.bukkit.craftbukkit.v.entity.CraftGolem; +import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v.entity.CraftTameableAnimal; -import org.bukkit.entity.EntityType; -import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -42,31 +37,12 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.util.Locale; -import java.util.Objects; - @Mixin(value = CraftEntity.class, remap = false) public abstract class CraftEntityMixin implements org.bukkit.entity.Entity { @Shadow protected Entity entity; @Shadow @Final protected CraftServer server; - private EntityType arclight$type; - - @Override - public @NotNull EntityType getType() { - if (this.arclight$type == null) { - ResourceLocation location = ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()); - if (location == null) throw new IllegalArgumentException("Unregistered entity type " + entity.getType()); - if (location.getNamespace().equals("minecraft")) { - this.arclight$type = Objects.requireNonNull(EntityType.fromName(location.getPath().toUpperCase(Locale.ROOT))); - } else { - this.arclight$type = EntityType.valueOf(ResourceLocationUtil.standardize(location)); - } - } - return this.arclight$type; - } - @Inject(method = "getEntity", cancellable = true, at = @At("HEAD")) private static void arclight$fakePlayer(CraftServer server, Entity entity, CallbackInfoReturnable cir) { if (entity instanceof FakePlayer) { @@ -109,7 +85,7 @@ public abstract class CraftEntityMixin implements org.bukkit.entity.Entity { cir.setReturnValue(new ArclightModMob(server, (Mob) entity)); return; } - cir.setReturnValue(new ArclightModLivingEntity(server, (LivingEntity) entity)); + cir.setReturnValue(new CraftLivingEntity(server, (LivingEntity) entity)); return; } if (entity instanceof AbstractMinecart) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerPlayNetHandlerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerPlayNetHandlerMixin.java index 4b80d1e6..2eb492f9 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerPlayNetHandlerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerPlayNetHandlerMixin.java @@ -11,6 +11,7 @@ import io.izzel.arclight.common.bridge.core.network.play.TimestampedPacket; import io.izzel.arclight.common.bridge.core.server.MinecraftServerBridge; import io.izzel.arclight.common.bridge.core.server.management.PlayerInteractionManagerBridge; import io.izzel.arclight.common.bridge.core.server.management.PlayerListBridge; +import io.izzel.arclight.common.bridge.core.world.WorldBridge; import io.izzel.arclight.common.mod.ArclightConstants; import io.izzel.arclight.common.mod.server.ArclightServer; import io.izzel.arclight.common.mod.util.ArclightCaptures; @@ -26,10 +27,49 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.StringTag; import net.minecraft.network.Connection; import net.minecraft.network.PacketSendListener; -import net.minecraft.network.chat.*; +import net.minecraft.network.chat.ChatType; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.LastSeenMessages; +import net.minecraft.network.chat.OutgoingChatMessage; +import net.minecraft.network.chat.PlayerChatMessage; +import net.minecraft.network.chat.SignableCommand; +import net.minecraft.network.chat.SignedMessageChain; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.PacketUtils; -import net.minecraft.network.protocol.game.*; +import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundDisconnectPacket; +import net.minecraft.network.protocol.game.ClientboundMoveVehiclePacket; +import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; +import net.minecraft.network.protocol.game.ClientboundSetCarriedItemPacket; +import net.minecraft.network.protocol.game.ClientboundSetDefaultSpawnPositionPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityLinkPacket; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.protocol.game.ClientboundSystemChatPacket; +import net.minecraft.network.protocol.game.ServerboundAcceptTeleportationPacket; +import net.minecraft.network.protocol.game.ServerboundChatCommandPacket; +import net.minecraft.network.protocol.game.ServerboundChatPacket; +import net.minecraft.network.protocol.game.ServerboundContainerButtonClickPacket; +import net.minecraft.network.protocol.game.ServerboundContainerClickPacket; +import net.minecraft.network.protocol.game.ServerboundContainerClosePacket; +import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; +import net.minecraft.network.protocol.game.ServerboundEditBookPacket; +import net.minecraft.network.protocol.game.ServerboundInteractPacket; +import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket; +import net.minecraft.network.protocol.game.ServerboundMoveVehiclePacket; +import net.minecraft.network.protocol.game.ServerboundPlaceRecipePacket; +import net.minecraft.network.protocol.game.ServerboundPlayerAbilitiesPacket; +import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket; +import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket; +import net.minecraft.network.protocol.game.ServerboundResourcePackPacket; +import net.minecraft.network.protocol.game.ServerboundSelectTradePacket; +import net.minecraft.network.protocol.game.ServerboundSetCarriedItemPacket; +import net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket; +import net.minecraft.network.protocol.game.ServerboundSignUpdatePacket; +import net.minecraft.network.protocol.game.ServerboundSwingPacket; +import net.minecraft.network.protocol.game.ServerboundTeleportToEntityPacket; +import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket; +import net.minecraft.network.protocol.game.ServerboundUseItemPacket; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; @@ -43,7 +83,12 @@ import net.minecraft.util.StringUtil; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.*; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.ExperienceOrb; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MoverType; +import net.minecraft.world.entity.RelativeMovement; import net.minecraft.world.entity.animal.Bucketable; import net.minecraft.world.entity.animal.allay.Allay; import net.minecraft.world.entity.item.ItemEntity; @@ -72,25 +117,53 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.craftbukkit.v.CraftServer; +import org.bukkit.craftbukkit.v.entity.CraftEntity; import org.bukkit.craftbukkit.v.entity.CraftPlayer; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.craftbukkit.v.util.CraftChatMessage; import org.bukkit.craftbukkit.v.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.v.util.CraftNamespacedKey; import org.bukkit.craftbukkit.v.util.LazyPlayerSet; import org.bukkit.craftbukkit.v.util.Waitable; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.block.Action; -import org.bukkit.event.inventory.*; -import org.bukkit.event.player.*; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.CraftItemEvent; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCreativeEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.inventory.SmithItemEvent; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerAnimationEvent; +import org.bukkit.event.player.PlayerAnimationType; +import org.bukkit.event.player.PlayerChatEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerItemHeldEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerResourcePackStatusEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.PlayerToggleFlightEvent; +import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.event.player.PlayerToggleSprintEvent; import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.SmithingInventory; import org.slf4j.Logger; import org.spigotmc.SpigotConfig; -import org.spongepowered.asm.mixin.*; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Overwrite; +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; @@ -101,7 +174,12 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.nio.charset.StandardCharsets; import java.time.Instant; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.function.UnaryOperator; @@ -398,8 +476,8 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } @Inject(method = "handleAcceptTeleportPacket", - at = @At(value = "FIELD", shift = At.Shift.AFTER, target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;awaitingPositionFromClient:Lnet/minecraft/world/phys/Vec3;"), - slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;isChangingDimension()Z"))) + at = @At(value = "FIELD", shift = At.Shift.AFTER, target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;awaitingPositionFromClient:Lnet/minecraft/world/phys/Vec3;"), + slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;isChangingDimension()Z"))) private void arclight$updateLoc(ServerboundAcceptTeleportationPacket packetIn, CallbackInfo ci) { if (((ServerPlayerEntityBridge) this.player).bridge$isValid()) { this.player.serverLevel().getChunkSource().move(this.player); @@ -996,7 +1074,6 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } - // TODO ChatType.RAW public void chat(String s, PlayerChatMessage original, boolean async) { if (s.isEmpty() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) { return; @@ -1026,9 +1103,6 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB if (!org.spigotmc.SpigotConfig.bungee && originalFormat.equals(queueEvent.getFormat()) && originalMessage.equals(queueEvent.getMessage()) && queueEvent.getPlayer().getName().equalsIgnoreCase(queueEvent.getPlayer().getDisplayName())) { // Spigot server.getPlayerList().broadcastChatMessage(original, player, ChatType.bind(ChatType.CHAT, player)); return null; - } else if (!org.spigotmc.SpigotConfig.bungee && CraftChatMessage.fromComponent(original.decoratedContent()).equals(message)) { // Spigot - // TODO server.getPlayerList().broadcastChatMessage(original, player, ChatType.bind(ChatType.RAW, player)); - return null; } for (ServerPlayer recipient : server.getPlayerList().players) { ((ServerPlayerEntityBridge) recipient).bridge$getBukkitEntity().sendMessage(player.getUUID(), message); @@ -1067,9 +1141,6 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB if (!org.spigotmc.SpigotConfig.bungee && originalFormat.equals(event.getFormat()) && originalMessage.equals(event.getMessage()) && event.getPlayer().getName().equalsIgnoreCase(event.getPlayer().getDisplayName())) { // Spigot server.getPlayerList().broadcastChatMessage(original, player, ChatType.bind(ChatType.CHAT, player)); return; - } else if (!org.spigotmc.SpigotConfig.bungee && CraftChatMessage.fromComponent(original.decoratedContent()).equals(s)) { // Spigot - // TODO server.getPlayerList().broadcastChatMessage(original, player, ChatType.bind(ChatType.RAW, player)); - return; } for (ServerPlayer recipient : server.getPlayerList().players) { @@ -1139,17 +1210,13 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB double d0 = this.player.getX(); double d2 = this.player.getY() + this.player.getEyeHeight(); double d3 = this.player.getZ(); - Vec3 vec3d = new Vec3(d0, d2, d3); - float f3 = Mth.cos(-f2 * 0.017453292f - 3.1415927f); - float f4 = Mth.sin(-f2 * 0.017453292f - 3.1415927f); - float f5 = -Mth.cos(-f1 * 0.017453292f); - float f6 = Mth.sin(-f1 * 0.017453292f); - float f7 = f4 * f5; - float f8 = f3 * f5; double d4 = this.player.getBlockReach(); - Vec3 vec3d2 = vec3d.add(f7 * d4, f6 * d4, f8 * d4); - HitResult result = this.player.level().clip(new ClipContext(vec3d, vec3d2, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, this.player)); - if (result == null || result.getType() != HitResult.Type.BLOCK) { + var origin = new Location(((WorldBridge) this.player.level()).bridge$getWorld(), d0, d2, d3, f1, f2); + var result = ((WorldBridge) this.player.level()).bridge$getWorld().rayTrace(origin, origin.getDirection(), d4, org.bukkit.FluidCollisionMode.NEVER, false, 0.1, entity -> { + Entity handle = ((CraftEntity) entity).getHandle(); + return handle != this.player && ((ServerPlayerEntityBridge) this.player).bridge$getBukkitEntity().canSee(entity) && !handle.isSpectator() && handle.isPickable() && !handle.isPassengerOfSameVehicle(player); + }); + if (result == null) { CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND); } PlayerAnimationEvent event = new PlayerAnimationEvent(this.getCraftPlayer(), packet.getHand() == InteractionHand.MAIN_HAND ? PlayerAnimationType.ARM_SWING : PlayerAnimationType.OFF_ARM_SWING); @@ -1262,19 +1329,19 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB @Override public void onInteraction(InteractionHand hand) { this.performInteraction(hand, net.minecraft.world.entity.player.Player::interactOn, - new PlayerInteractEntityEvent(getCraftPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), - (hand == InteractionHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND)); + new PlayerInteractEntityEvent(getCraftPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), + (hand == InteractionHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND)); } @Override public void onInteraction(InteractionHand hand, Vec3 vec) { this.performInteraction(hand, (player, e, h) -> { - var onInteractEntityAtResult = ForgeHooks.onInteractEntityAt(player, entity, vec, hand); - if (onInteractEntityAtResult != null) return onInteractEntityAtResult; - return e.interactAt(player, vec, h); - }, - new PlayerInteractAtEntityEvent(getCraftPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), - new org.bukkit.util.Vector(vec.x, vec.y, vec.z), (hand == InteractionHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND)); + var onInteractEntityAtResult = ForgeHooks.onInteractEntityAt(player, entity, vec, hand); + if (onInteractEntityAtResult != null) return onInteractEntityAtResult; + return e.interactAt(player, vec, h); + }, + new PlayerInteractAtEntityEvent(getCraftPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), + new org.bukkit.util.Vector(vec.x, vec.y, vec.z), (hand == InteractionHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND)); } @Override @@ -1624,6 +1691,20 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } + @Redirect(method = "handlePlaceRecipe", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ServerboundPlaceRecipePacket;getRecipe()Lnet/minecraft/resources/ResourceLocation;")) + private ResourceLocation arclight$recipeBookClick(ServerboundPlaceRecipePacket instance) { + var location = instance.getRecipe(); + org.bukkit.inventory.Recipe recipe = this.cserver.getRecipe(CraftNamespacedKey.fromMinecraft(location)); + if (recipe == null) { + return location; + } + var event = CraftEventFactory.callRecipeBookClickEvent(this.player, recipe, instance.isShiftDown()); + if (event.getRecipe() instanceof org.bukkit.Keyed keyed) { + return CraftNamespacedKey.toMinecraft(keyed.getKey()); + } + return location; + } + @Inject(method = "handleContainerButtonClick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;resetLastActionTime()V")) private void arclight$noEnchant(ServerboundContainerButtonClickPacket packetIn, CallbackInfo ci) { if (((ServerPlayerEntityBridge) player).bridge$isMovementBlocked()) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/level/ServerEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/level/ServerEntityMixin.java index 493b9bd9..d13c762f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/level/ServerEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/level/ServerEntityMixin.java @@ -15,7 +15,6 @@ import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; import net.minecraft.network.protocol.game.ClientboundSetPassengersPacket; import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; import net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket; -import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; import net.minecraft.network.protocol.game.VecDeltaCodec; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.level.ServerEntity; @@ -23,7 +22,6 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerPlayerConnection; import net.minecraft.util.Mth; -import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; @@ -290,9 +288,13 @@ public abstract class ServerEntityMixin implements ServerEntityBridge { if (!list.isEmpty()) { consumer.accept(new ClientboundSetEquipmentPacket(this.entity.getId(), list)); } + ((LivingEntity) this.entity).detectEquipmentUpdates(); } - this.yHeadRotp = Mth.floor(this.entity.getYHeadRot() * 256.0f / 360.0f); - consumer.accept(new ClientboundRotateHeadPacket(this.entity, (byte) this.yHeadRotp)); + // CraftBukkit start - MC-109346: Fix for nonsensical head yaw + if (this.entity instanceof ServerPlayer) { + consumer.accept(new ClientboundRotateHeadPacket(this.entity, (byte) Mth.floor(this.entity.getYHeadRot() * 256.0F / 360.0F))); + } + // CraftBukkit end if (!this.entity.getPassengers().isEmpty()) { consumer.accept(new ClientboundSetPassengersPacket(this.entity)); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/ServerPlayerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/ServerPlayerMixin.java index 78d5861c..620d7a22 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/ServerPlayerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/ServerPlayerMixin.java @@ -713,6 +713,10 @@ public abstract class ServerPlayerMixin extends PlayerMixin implements ServerPla Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { ci.cancel(); + } else { + if (this.connection != null) { + ((ServerPlayNetHandlerBridge) this.connection).bridge$pushTeleportCause(PlayerTeleportEvent.TeleportCause.EXIT_BED); + } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SignBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SignBlockMixin.java new file mode 100644 index 00000000..51f79bc6 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SignBlockMixin.java @@ -0,0 +1,52 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.SignBlock; +import net.minecraft.world.level.block.entity.SignBlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.player.PlayerSignOpenEvent; +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(SignBlock.class) +public abstract class SignBlockMixin { + + // @formatter:off + @Shadow public abstract void openTextEdit(Player p_277738_, SignBlockEntity p_277467_, boolean p_277771_); + // @formatter:on + + private transient PlayerSignOpenEvent.Cause arclight$edit; + + @Inject(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/SignBlock;openTextEdit(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/block/entity/SignBlockEntity;Z)V")) + private void arclight$beforeEdit(BlockState p_56278_, Level p_56279_, BlockPos p_56280_, Player p_56281_, InteractionHand p_56282_, BlockHitResult p_56283_, CallbackInfoReturnable cir) { + arclight$edit = PlayerSignOpenEvent.Cause.INTERACT; + } + + @Inject(method = "use", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/level/block/SignBlock;openTextEdit(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/block/entity/SignBlockEntity;Z)V")) + private void arclight$afterEdit(BlockState p_56278_, Level p_56279_, BlockPos p_56280_, Player p_56281_, InteractionHand p_56282_, BlockHitResult p_56283_, CallbackInfoReturnable cir) { + arclight$edit = null; + } + + public void openTextEdit(Player p_277738_, SignBlockEntity p_277467_, boolean p_277771_, PlayerSignOpenEvent.Cause cause) { + arclight$edit = cause; + this.openTextEdit(p_277738_, p_277467_, p_277771_); + arclight$edit = null; + } + + @Inject(method = "openTextEdit", cancellable = true, at = @At("HEAD")) + private void arclight$signEdit(Player player, SignBlockEntity signBlockEntity, boolean flag, CallbackInfo ci) { + if (!CraftEventFactory.callPlayerSignOpenEvent(player, signBlockEntity, flag, arclight$edit != null ? arclight$edit : (flag ? PlayerSignOpenEvent.Cause.PLACE : PlayerSignOpenEvent.Cause.UNKNOWN))) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModChestedHorse.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModChestedHorse.java index 85e7cb41..f97848df 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModChestedHorse.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModChestedHorse.java @@ -1,27 +1,16 @@ package io.izzel.arclight.common.mod.server.entity; -import io.izzel.arclight.common.mod.util.ResourceLocationUtil; import net.minecraft.world.entity.animal.horse.AbstractChestedHorse; -import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftChestedHorse; import org.bukkit.entity.EntityCategory; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Horse; import org.jetbrains.annotations.NotNull; public class ArclightModChestedHorse extends CraftChestedHorse { - private final EntityType entityType; - public ArclightModChestedHorse(CraftServer server, AbstractChestedHorse entity) { super(server, entity); - this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()))); - } - - @Override - public @NotNull EntityType getType() { - return this.entityType; } @Override @@ -29,11 +18,6 @@ public class ArclightModChestedHorse extends CraftChestedHorse { return Horse.Variant.HORSE; } - @Override - public String toString() { - return "ArclightModChestedHorse{" + entityType + '}'; - } - @Override public @NotNull EntityCategory getCategory() { return EntityCategory.NONE; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModEntity.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModEntity.java index caf357ba..52e76571 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModEntity.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModEntity.java @@ -1,29 +1,12 @@ package io.izzel.arclight.common.mod.server.entity; -import io.izzel.arclight.common.mod.util.ResourceLocationUtil; import net.minecraft.world.entity.Entity; -import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftEntity; -import org.bukkit.entity.EntityType; -import org.jetbrains.annotations.NotNull; public class ArclightModEntity extends CraftEntity { - private final EntityType entityType; - public ArclightModEntity(CraftServer server, Entity entity) { super(server, entity); - this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()))); - } - - @Override - public @NotNull EntityType getType() { - return entityType; - } - - @Override - public String toString() { - return "ArclightModEntity{" + entityType + '}'; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModHorse.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModHorse.java index feb83f60..f132d491 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModHorse.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModHorse.java @@ -1,28 +1,16 @@ package io.izzel.arclight.common.mod.server.entity; -import io.izzel.arclight.common.mod.util.ResourceLocationUtil; import net.minecraft.world.entity.animal.horse.AbstractHorse; -import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftAbstractHorse; import org.bukkit.entity.EntityCategory; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Horse; import org.jetbrains.annotations.NotNull; public class ArclightModHorse extends CraftAbstractHorse { - private final EntityType entityType; - public ArclightModHorse(CraftServer server, AbstractHorse entity) { super(server, entity); - this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()))); - } - - @Override - @NotNull - public EntityType getType() { - return this.entityType; } @Override @@ -30,11 +18,6 @@ public class ArclightModHorse extends CraftAbstractHorse { return Horse.Variant.HORSE; } - @Override - public String toString() { - return "ArclightModHorse{" + entityType + '}'; - } - @Override public @NotNull EntityCategory getCategory() { return EntityCategory.NONE; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModLivingEntity.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModLivingEntity.java deleted file mode 100644 index 78803b4f..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModLivingEntity.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.izzel.arclight.common.mod.server.entity; - -import io.izzel.arclight.common.mod.util.ResourceLocationUtil; -import net.minecraft.world.entity.LivingEntity; -import net.minecraftforge.registries.ForgeRegistries; -import org.bukkit.craftbukkit.v.CraftServer; -import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; -import org.bukkit.entity.EntityType; -import org.jetbrains.annotations.NotNull; - -public class ArclightModLivingEntity extends CraftLivingEntity { - - private final EntityType entityType; - - public ArclightModLivingEntity(CraftServer server, LivingEntity entity) { - super(server, entity); - this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()))); - } - - @Override - public @NotNull EntityType getType() { - return entityType; - } - - @Override - public String toString() { - return "ArclightModLivingEntity{" + entityType + '}'; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecart.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecart.java index 1f500eac..6eb9cc34 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecart.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecart.java @@ -1,29 +1,12 @@ package io.izzel.arclight.common.mod.server.entity; -import io.izzel.arclight.common.mod.util.ResourceLocationUtil; import net.minecraft.world.entity.vehicle.AbstractMinecart; -import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftMinecart; -import org.bukkit.entity.EntityType; -import org.jetbrains.annotations.NotNull; public class ArclightModMinecart extends CraftMinecart { - private final EntityType entityType; - public ArclightModMinecart(CraftServer server, AbstractMinecart entity) { super(server, entity); - this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()))); - } - - @Override - public @NotNull EntityType getType() { - return entityType; - } - - @Override - public String toString() { - return "ArclightModMinecart{" + entityType + '}'; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecartContainer.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecartContainer.java index 1a80e518..6b740377 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecartContainer.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecartContainer.java @@ -1,29 +1,12 @@ package io.izzel.arclight.common.mod.server.entity; -import io.izzel.arclight.common.mod.util.ResourceLocationUtil; import net.minecraft.world.entity.vehicle.AbstractMinecartContainer; -import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftMinecartContainer; -import org.bukkit.entity.EntityType; -import org.jetbrains.annotations.NotNull; public class ArclightModMinecartContainer extends CraftMinecartContainer { - private final EntityType entityType; - public ArclightModMinecartContainer(CraftServer server, AbstractMinecartContainer entity) { super(server, entity); - this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()))); - } - - @Override - public @NotNull EntityType getType() { - return entityType; - } - - @Override - public String toString() { - return "ArclightModMinecartContainer{" + entityType + '}'; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMob.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMob.java index 16f406d2..d9fadf42 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMob.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMob.java @@ -1,35 +1,12 @@ package io.izzel.arclight.common.mod.server.entity; -import io.izzel.arclight.common.mod.util.ResourceLocationUtil; import net.minecraft.world.entity.Mob; -import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftMob; -import org.bukkit.entity.EntityCategory; -import org.bukkit.entity.EntityType; -import org.jetbrains.annotations.NotNull; public class ArclightModMob extends CraftMob { - private final EntityType entityType; - public ArclightModMob(CraftServer server, Mob entity) { super(server, entity); - this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()))); - } - - @Override - public @NotNull EntityType getType() { - return entityType; - } - - @Override - public String toString() { - return "ArclightModMob{" + entityType + '}'; - } - - @Override - public @NotNull EntityCategory getCategory() { - return EntityCategory.NONE; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModProjectile.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModProjectile.java index 860ac630..da2d3cf2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModProjectile.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModProjectile.java @@ -1,30 +1,13 @@ package io.izzel.arclight.common.mod.server.entity; -import io.izzel.arclight.common.mod.util.ResourceLocationUtil; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.projectile.Projectile; -import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftProjectile; -import org.bukkit.entity.EntityType; -import org.jetbrains.annotations.NotNull; public class ArclightModProjectile extends CraftProjectile { - private final EntityType entityType; - public ArclightModProjectile(CraftServer server, Entity entity) { super(server, (Projectile) entity); - this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()))); - } - - @Override - public @NotNull EntityType getType() { - return entityType; - } - - @Override - public String toString() { - return "ArclightModProjectile{" + entityType + '}'; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModRaider.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModRaider.java index 68dfc3e9..300b3945 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModRaider.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModRaider.java @@ -1,35 +1,12 @@ package io.izzel.arclight.common.mod.server.entity; -import io.izzel.arclight.common.mod.util.ResourceLocationUtil; import net.minecraft.world.entity.raid.Raider; -import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftRaider; -import org.bukkit.entity.EntityCategory; -import org.bukkit.entity.EntityType; -import org.jetbrains.annotations.NotNull; public class ArclightModRaider extends CraftRaider { - private final EntityType entityType; - public ArclightModRaider(CraftServer server, Raider entity) { super(server, entity); - this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()))); - } - - @Override - public @NotNull EntityType getType() { - return entityType; - } - - @Override - public String toString() { - return "ArclightModRaider{" + entityType + '}'; - } - - @Override - public @NotNull EntityCategory getCategory() { - return EntityCategory.ILLAGER; } } diff --git a/arclight-common/src/main/resources/mixins.arclight.core.json b/arclight-common/src/main/resources/mixins.arclight.core.json index bd55ced9..338d46f4 100644 --- a/arclight-common/src/main/resources/mixins.arclight.core.json +++ b/arclight-common/src/main/resources/mixins.arclight.core.json @@ -418,6 +418,7 @@ "world.level.block.SculkSensorBlockMixin", "world.level.block.SculkShriekerBlockMixin", "world.level.block.SculkVeinBlockMixin", + "world.level.block.SignBlockMixin", "world.level.block.SnowBlockMixin", "world.level.block.SnowLayerBlockMixin", "world.level.block.SpongeBlockMixin", diff --git a/arclight-forge/src/main/java/io/izzel/arclight/boot/asm/ArclightImplementer.java b/arclight-forge/src/main/java/io/izzel/arclight/boot/asm/ArclightImplementer.java index 95ea6c37..9d99ac2c 100644 --- a/arclight-forge/src/main/java/io/izzel/arclight/boot/asm/ArclightImplementer.java +++ b/arclight-forge/src/main/java/io/izzel/arclight/boot/asm/ArclightImplementer.java @@ -61,7 +61,6 @@ public class ArclightImplementer implements ILaunchPluginService { this.implementers.put("inventory", new InventoryImplementer()); this.implementers.put("switch", SwitchTableFixer.INSTANCE); this.implementers.put("async", AsyncCatcher.INSTANCE); - this.implementers.put("entitytype", EntityTypePatcher.INSTANCE); this.implementers.put("enum", new EnumDefinalizer()); if (this.logger) { this.implementers.put("logger", new LoggerTransformer()); diff --git a/arclight-forge/src/main/java/io/izzel/arclight/boot/asm/EntityTypePatcher.java b/arclight-forge/src/main/java/io/izzel/arclight/boot/asm/EntityTypePatcher.java deleted file mode 100644 index 2e77d4d5..00000000 --- a/arclight-forge/src/main/java/io/izzel/arclight/boot/asm/EntityTypePatcher.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.izzel.arclight.boot.asm; - -import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; -import io.izzel.arclight.api.ArclightVersion; -import org.objectweb.asm.tree.ClassNode; - -public class EntityTypePatcher implements Implementer { - - public static final EntityTypePatcher INSTANCE = new EntityTypePatcher(); - - private final String entityPackage = "org/bukkit/craftbukkit/" + ArclightVersion.current().packageName() + "/entity"; - - @Override - public boolean processClass(ClassNode node, ILaunchPluginService.ITransformerLoader transformerLoader) { - if (node.name.startsWith(entityPackage) && !node.name.endsWith("CraftEntity")) { - return node.methods.removeIf(methodNode -> methodNode.name.equals("getType") - && methodNode.desc.equals("()Lorg/bukkit/entity/EntityType;")); - } - return false; - } -}