From 23e365fc147cc5cc00b8c5f946f0208609b3abc1 Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Thu, 2 Jun 2022 17:33:12 +0800 Subject: [PATCH] Update to forge 40.1.31 --- README.md | 2 +- .../network/ServerPlayNetHandlerMixin.java | 147 +++++++++--------- .../management/ServerPlayerGameModeMixin.java | 14 +- .../mixin/core/world/entity/EntityMixin.java | 3 + .../core/world/entity/player/PlayerMixin.java | 2 +- .../entity/player/ServerPlayerMixin.java | 1 + .../common/mixin/forge/ForgeHooksMixin.java | 10 -- build.gradle | 2 +- 8 files changed, 91 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index 8b7b70db..f95a0386 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A Bukkit server implementation utilizing Mixin. | Minecraft | Forge | Status | Build | | :----: |:-------:| :---: | :---: | -| 1.18.x | 40.1.0 | ACTIVE | [![1.18 Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-18?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-18) | +| 1.18.x | 40.1.31 | ACTIVE | [![1.18 Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-18?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-18) | | 1.17.x | 37.1.0 | [LEGACY](https://github.com/IzzelAliz/Arclight/releases/tag/1.17/1.0.2) | [![1.17 Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-17?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-17) | | 1.16.x | 36.2.26 | ACTIVE | [![1.16 Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-16?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-16) | | 1.15.x | 31.2.48 | [LEGACY](https://github.com/IzzelAliz/Arclight/releases/tag/1.15/1.0.19) | [![1.15 Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-15?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-15) | 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 bb020c38..6a992c22 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 @@ -590,7 +590,7 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB this.player.absMoveTo(d0, d1, d2, f, f1); if (!this.player.noPhysics && !this.player.isSleeping() && (flag1 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew((LevelReader) worldserver, axisalignedbb))) { - this.teleport(d3, d4, d5, f, f1); + this.internalTeleport(d3, d4, d5, f, f1, Collections.emptySet(), false); // CraftBukkit - SPIGOT-1807: Don't call teleport event, when the client thinks the player is falling, because the chunks are not loaded on the client yet. } else { this.player.absMoveTo(prevX, prevY, prevZ, prevYaw, prevPitch); CraftPlayer player = this.getCraftPlayer(); @@ -1166,89 +1166,90 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB if (!world.getWorldBorder().isWithinBounds(entity.blockPosition())) { return; } - double d0 = 36.0D; - if (this.player.distanceToSqr(entity) < 36.0D) { - class Handler implements ServerboundInteractPacket.Handler { + class Handler implements ServerboundInteractPacket.Handler { - private void performInteraction(InteractionHand hand, ServerGamePacketListenerImpl.EntityInteraction interaction, PlayerInteractEntityEvent event) { // CraftBukkit - ItemStack itemstack = player.getItemInHand(hand).copy(); - // CraftBukkit start - ItemStack itemInHand = player.getItemInHand(hand); - boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof Mob; - Item origItem = player.getInventory().getSelected() == null ? null : player.getInventory().getSelected().getItem(); + private void performInteraction(InteractionHand hand, ServerGamePacketListenerImpl.EntityInteraction interaction, PlayerInteractEntityEvent event) { // CraftBukkit + if (!player.canInteractWith(entity, 1.5D)) + return; //Forge: If the entity cannot be reached, do nothing. Original check was dist < 6, range is 4.5, so vanilla used padding=1.5 + ItemStack itemstack = player.getItemInHand(hand).copy(); + // CraftBukkit start + ItemStack itemInHand = player.getItemInHand(hand); + boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof Mob; + Item origItem = player.getInventory().getSelected() == null ? null : player.getInventory().getSelected().getItem(); - cserver.getPluginManager().callEvent(event); + cserver.getPluginManager().callEvent(event); - // Fish bucket - SPIGOT-4048 - if ((entity instanceof Bucketable && entity instanceof LivingEntity && origItem != null && origItem.asItem() == Items.WATER_BUCKET) && (event.isCancelled() || player.getInventory().getSelected() == null || player.getInventory().getSelected().getItem() != origItem)) { - send(new ClientboundAddMobPacket((LivingEntity) entity)); - player.containerMenu.sendAllDataToRemote(); + // Fish bucket - SPIGOT-4048 + if ((entity instanceof Bucketable && entity instanceof LivingEntity && origItem != null && origItem.asItem() == Items.WATER_BUCKET) && (event.isCancelled() || player.getInventory().getSelected() == null || player.getInventory().getSelected().getItem() != origItem)) { + send(new ClientboundAddMobPacket((LivingEntity) entity)); + player.containerMenu.sendAllDataToRemote(); + } + + if (triggerLeashUpdate && (event.isCancelled() || player.getInventory().getSelected() == null || player.getInventory().getSelected().getItem() != origItem)) { + // Refresh the current leash state + send(new ClientboundSetEntityLinkPacket(entity, ((Mob) entity).getLeashHolder())); + } + + if (event.isCancelled() || player.getInventory().getSelected() == null || player.getInventory().getSelected().getItem() != origItem) { + // Refresh the current entity metadata + send(new ClientboundSetEntityDataPacket(entity.getId(), entity.getEntityData(), true)); + } + + if (event.isCancelled()) { + return; + } + // CraftBukkit end + + InteractionResult enuminteractionresult = interaction.run(player, entity, hand); + if (ForgeHooks.onInteractEntityAt(player, entity, entity.position(), hand) != null) return; + + // CraftBukkit start + if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) { + player.containerMenu.sendAllDataToRemote(); + } + // CraftBukkit end + + if (enuminteractionresult.consumesAction()) { + CriteriaTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(player, itemstack, entity); + if (enuminteractionresult.shouldSwing()) { + player.swing(hand, true); + } + } + + } + + @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)); + } + + @Override + public void onInteraction(InteractionHand hand, Vec3 vec) { + this.performInteraction(hand, (player, e, h) -> 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 + public void onAttack() { + if (!(entity instanceof ItemEntity) && !(entity instanceof ExperienceOrb) && !(entity instanceof AbstractArrow) && (entity != player || player.isSpectator())) { + ItemStack itemInHand = player.getMainHandItem(); + if (player.canHit(entity, 3)) { //Forge: Perform attack range check. Original check was dist < 6, range is 3, so vanilla used padding=3 + player.attack(entity); } - if (triggerLeashUpdate && (event.isCancelled() || player.getInventory().getSelected() == null || player.getInventory().getSelected().getItem() != origItem)) { - // Refresh the current leash state - send(new ClientboundSetEntityLinkPacket(entity, ((Mob) entity).getLeashHolder())); - } - - if (event.isCancelled() || player.getInventory().getSelected() == null || player.getInventory().getSelected().getItem() != origItem) { - // Refresh the current entity metadata - send(new ClientboundSetEntityDataPacket(entity.getId(), entity.getEntityData(), true)); - } - - if (event.isCancelled()) { - return; - } - // CraftBukkit end - - InteractionResult enuminteractionresult = interaction.run(player, entity, hand); - if (ForgeHooks.onInteractEntityAt(player, entity, entity.position(), hand) != null) return; - - // CraftBukkit start if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) { player.containerMenu.sendAllDataToRemote(); } - // CraftBukkit end - - if (enuminteractionresult.consumesAction()) { - CriteriaTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(player, itemstack, entity); - if (enuminteractionresult.shouldSwing()) { - player.swing(hand, true); - } - } - - } - - @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)); - } - - @Override - public void onInteraction(InteractionHand hand, Vec3 vec) { - this.performInteraction(hand, (player, e, h) -> 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 - public void onAttack() { - if (!(entity instanceof ItemEntity) && !(entity instanceof ExperienceOrb) && !(entity instanceof AbstractArrow) && (entity != player || player.isSpectator())) { - ItemStack itemInHand = player.getMainHandItem(); - player.attack(entity); - - if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) { - player.containerMenu.sendAllDataToRemote(); - } - } else { - disconnect(new TranslatableComponent("multiplayer.disconnect.invalid_entity_attacked")); - LOGGER.warn("Player {} tried to attack an invalid entity", player.getName().getString()); - } + } else { + disconnect(new TranslatableComponent("multiplayer.disconnect.invalid_entity_attacked")); + LOGGER.warn("Player {} tried to attack an invalid entity", player.getName().getString()); } } - packetIn.dispatch(new Handler()); } + packetIn.dispatch(new Handler()); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/ServerPlayerGameModeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/ServerPlayerGameModeMixin.java index 66d19b7f..d00f8e54 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/ServerPlayerGameModeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/ServerPlayerGameModeMixin.java @@ -20,8 +20,10 @@ import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.DoubleHighBlockItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.GameType; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.CakeBlock; import net.minecraft.world.level.block.DoorBlock; import net.minecraft.world.level.block.TrapDoorBlock; @@ -95,16 +97,20 @@ public abstract class ServerPlayerGameModeMixin implements PlayerInteractionMana double d2 = this.player.getY() - (blockPos.getY() + 0.5) + 1.5; double d3 = this.player.getZ() - (blockPos.getZ() + 0.5); double d4 = d0 * d0 + d2 * d2 + d3 * d3; - double dist = player.getAttribute(net.minecraftforge.common.ForgeMod.REACH_DISTANCE.get()).getValue() + 1; - dist *= dist; net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock forgeEvent = net.minecraftforge.common.ForgeHooks.onLeftClickBlock(player, blockPos, direction); if (forgeEvent.isCanceled() || (!this.isCreative() && forgeEvent.getUseItem() == net.minecraftforge.eventbus.api.Event.Result.DENY)) { // Restore block and te data player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, level.getBlockState(blockPos), action, false, "mod canceled")); level.sendBlockUpdated(blockPos, level.getBlockState(blockPos), level.getBlockState(blockPos), 3); return; } - if (d4 > dist) { - this.player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, this.level.getBlockState(blockPos), action, false, "too far")); + if (!this.player.canInteractWith(blockPos, 1)) { + BlockState state; + if (this.player.level.getServer() != null && this.player.chunkPosition().getChessboardDistance(new ChunkPos(blockPos)) < this.player.level.getServer().getPlayerList().getViewDistance()) { + state = this.level.getBlockState(blockPos); + } else { + state = Blocks.AIR.defaultBlockState(); + } + this.player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, state, action, false, "too far")); } else if (blockPos.getY() >= i) { this.player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, this.level.getBlockState(blockPos), action, false, "too high")); } else if (action == ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK) { 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 e604d250..d4759174 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 @@ -54,6 +54,7 @@ import net.minecraft.world.level.portal.PortalShape; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.Team; +import net.minecraftforge.common.ForgeHooks; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; @@ -857,6 +858,8 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, @Overwrite(remap = false) @Nullable public Entity changeDimension(ServerLevel server, net.minecraftforge.common.util.ITeleporter teleporter) { + if (!ForgeHooks.onTravelToDimension((Entity) (Object) this, server.dimension())) + return null; if (this.level instanceof ServerLevel && !this.isRemoved()) { this.level.getProfiler().push("changeDimension"); if (server == null) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java index acacaaf2..41ed3205 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java @@ -326,7 +326,7 @@ public abstract class PlayerMixin extends LivingEntityMixin implements PlayerEnt final float f5 = 1.0f + EnchantmentHelper.getSweepingDamageRatio((net.minecraft.world.entity.player.Player) (Object) this) * f; final List list = this.level.getEntitiesOfClass(LivingEntity.class, this.getItemInHand(InteractionHand.MAIN_HAND).getSweepHitBox((net.minecraft.world.entity.player.Player) (Object) this, entity)); for (final LivingEntity entityliving : list) { - if (entityliving != (Object) this && entityliving != entity && !this.isAlliedTo(entityliving) && (!(entityliving instanceof ArmorStand) || !((ArmorStand) entityliving).isMarker()) && this.distanceToSqr(entityliving) < 9.0 && entityliving.hurt(((DamageSourceBridge) DamageSource.playerAttack((net.minecraft.world.entity.player.Player) (Object) this)).bridge$sweep(), f5)) { + if (entityliving != (Object) this && entityliving != entity && !this.isAlliedTo(entityliving) && (!(entityliving instanceof ArmorStand) || !((ArmorStand) entityliving).isMarker()) && this.lastHurtByPlayer.canHit(entityliving, 0) && entityliving.hurt(((DamageSourceBridge) DamageSource.playerAttack((net.minecraft.world.entity.player.Player) (Object) this)).bridge$sweep(), f5)) { entityliving.knockback(0.4f, Mth.sin(this.getYRot() * 0.017453292f), -Mth.cos(this.getYRot() * 0.017453292f)); } } 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 bc93149e..ff726644 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 @@ -948,6 +948,7 @@ public abstract class ServerPlayerMixin extends PlayerMixin implements ServerPla this.giveExperiencePoints(this.newExp); } this.keepLevel = false; + this.setDeltaMovement(0, 0, 0); } @Override diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeHooksMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeHooksMixin.java index 5061e391..330c69ce 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeHooksMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeHooksMixin.java @@ -1,12 +1,9 @@ package io.izzel.arclight.common.mixin.forge; import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.context.UseOnContext; -import net.minecraft.world.level.Level; import net.minecraftforge.common.ForgeHooks; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -25,11 +22,4 @@ public class ForgeHooksMixin { private static void arclight$removeHand(UseOnContext context, CallbackInfoReturnable cir) { ArclightCaptures.getPlaceEventHand(InteractionHand.MAIN_HAND); } - - @Inject(method = "canEntityDestroy", cancellable = true, remap = false, at = @At("HEAD")) - private static void arclight$returnIfNotLoaded(Level world, BlockPos pos, LivingEntity entity, CallbackInfoReturnable cir) { - if (!world.isLoaded(pos)) { - cir.setReturnValue(false); - } - } } diff --git a/build.gradle b/build.gradle index 8d5f1728..85d94f02 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ allprojects { ext { agpVersion = '1.22' minecraftVersion = '1.18.2' - forgeVersion = '40.1.0' + forgeVersion = '40.1.31' apiVersion = '1.2.6' toolsVersion = '1.3.+' mixinVersion = '0.8.5'