Skip to content

Commit

Permalink
Update upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Dec 30, 2023
1 parent 3803ece commit 3f7d1ee
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@
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.inventory.CraftItemType;
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;
Expand Down Expand Up @@ -292,6 +292,15 @@ public void handleMoveVehicle(final ServerboundMoveVehiclePacket packetplayinveh
Entity entity = this.player.getRootVehicle();
if (entity != this.player && entity.getControllingPassenger() == this.player && entity == this.lastVehicle) {
ServerLevel worldserver = this.player.serverLevel();

// CraftBukkit - store current player position
double prevX = player.getX();
double prevY = player.getY();
double prevZ = player.getZ();
float prevYaw = player.getYRot();
float prevPitch = player.getXRot();
// CraftBukkit end

double d0 = entity.getX();
double d2 = entity.getY();
double d3 = entity.getZ();
Expand Down Expand Up @@ -369,12 +378,12 @@ public void handleMoveVehicle(final ServerboundMoveVehiclePacket packetplayinveh
}
Player player = this.getCraftPlayer();
if (!hasMoved) {
lastPosX = curPos.getX();
lastPosY = curPos.getY();
lastPosZ = curPos.getZ();
lastYaw = curPos.getYaw();
lastPitch = curPos.getPitch();
hasMoved = true;
this.lastPosX = prevX;
this.lastPosY = prevY;
this.lastPosZ = prevZ;
this.lastYaw = prevYaw;
this.lastPitch = prevPitch;
this.hasMoved = true;
}
Location from = new Location(player.getWorld(), this.lastPosX, this.lastPosY, this.lastPosZ, this.lastYaw, this.lastPitch);
Location to = player.getLocation().clone();
Expand All @@ -391,22 +400,20 @@ public void handleMoveVehicle(final ServerboundMoveVehiclePacket packetplayinveh
this.lastPosZ = to.getZ();
this.lastYaw = to.getYaw();
this.lastPitch = to.getPitch();
if (true) {
Location oldTo = to.clone();
PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
this.cserver.getPluginManager().callEvent(event);
if (event.isCancelled()) {
this.bridge$teleport(from);
return;
}
if (!oldTo.equals(event.getTo()) && !event.isCancelled()) {
((ServerPlayerEntityBridge) this.player).bridge$getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.PLUGIN);
return;
}
if (!from.equals(this.getCraftPlayer().getLocation()) && this.justTeleported) {
this.justTeleported = false;
return;
}
Location oldTo = to.clone();
PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
this.cserver.getPluginManager().callEvent(event);
if (event.isCancelled()) {
this.bridge$teleport(from);
return;
}
if (!oldTo.equals(event.getTo()) && !event.isCancelled()) {
((ServerPlayerEntityBridge) this.player).bridge$getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.PLUGIN);
return;
}
if (!from.equals(this.getCraftPlayer().getLocation()) && this.justTeleported) {
this.justTeleported = false;
return;
}
}
this.player.serverLevel().getChunkSource().move(this.player);
Expand Down Expand Up @@ -629,6 +636,14 @@ public void handleMovePlayer(ServerboundMovePlayerPacket packetplayinflying) {
// Reset to old location first
this.player.absMoveTo(prevX, prevY, prevZ, prevYaw, prevPitch);
CraftPlayer player = this.getCraftPlayer();
if (!this.hasMoved) {
this.lastPosX = prevX;
this.lastPosY = prevY;
this.lastPosZ = prevZ;
this.lastYaw = prevYaw;
this.lastPitch = prevPitch;
this.hasMoved = true;
}
Location from = new Location(player.getWorld(), this.lastPosX, this.lastPosY, this.lastPosZ, this.lastYaw, this.lastPitch);
Location to = player.getLocation().clone();
if (packetplayinflying.hasPos) {
Expand All @@ -648,22 +663,20 @@ public void handleMovePlayer(ServerboundMovePlayerPacket packetplayinflying) {
this.lastPosZ = to.getZ();
this.lastYaw = to.getYaw();
this.lastPitch = to.getPitch();
if (from.getX() != Double.MAX_VALUE) {
Location oldTo = to.clone();
PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
this.cserver.getPluginManager().callEvent(event);
if (event.isCancelled()) {
this.teleport(from);
return;
}
if (!oldTo.equals(event.getTo()) && !event.isCancelled()) {
getCraftPlayer().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.PLUGIN);
return;
}
if (!from.equals(this.getCraftPlayer().getLocation()) && this.justTeleported) {
this.justTeleported = false;
return;
}
Location oldTo = to.clone();
PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
this.cserver.getPluginManager().callEvent(event);
if (event.isCancelled()) {
this.teleport(from);
return;
}
if (!oldTo.equals(event.getTo()) && !event.isCancelled()) {
getCraftPlayer().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.PLUGIN);
return;
}
if (!from.equals(this.getCraftPlayer().getLocation()) && this.justTeleported) {
this.justTeleported = false;
return;
}
}

Expand Down Expand Up @@ -1481,7 +1494,7 @@ public void handleContainerClick(ServerboundContainerClickPacket packet) {
ItemStack cursor = this.player.containerMenu.getCarried();
action = InventoryAction.NOTHING;
// Quick check for if we have any of the item
if (inventory.getTopInventory().contains(CraftMagicNumbers.getMaterial(cursor.getItem())) || inventory.getBottomInventory().contains(CraftMagicNumbers.getMaterial(cursor.getItem()))) {
if (inventory.getTopInventory().contains(CraftItemType.minecraftToBukkit(cursor.getItem())) || inventory.getBottomInventory().contains(CraftItemType.minecraftToBukkit(cursor.getItem()))) {
action = InventoryAction.COLLECT_TO_CURSOR;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.izzel.arclight.common.mixin.core.server;

import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.Component;
import net.minecraft.server.ServerTickRateManager;
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.Redirect;

import java.util.function.Supplier;

@Mixin(ServerTickRateManager.class)
public abstract class ServerTickRateManagerMixin {

// @formatter:off
@Shadow public abstract boolean stopSprinting();
// @formatter:on

private boolean arclight$sendLog = true;

public boolean stopSprinting(boolean sendLog) {
try {
arclight$sendLog = sendLog;
return this.stopSprinting();
} finally {
arclight$sendLog = true;
}
}

@Redirect(method = "finishTickSprint", at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/CommandSourceStack;sendSuccess(Ljava/util/function/Supplier;Z)V"))
private void arclight$send(CommandSourceStack source, Supplier<Component> supplier, boolean flag) {
if (arclight$sendLog) {
source.sendSuccess(supplier, flag);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt
@Shadow public abstract void indicateDamage(double p_270514_, double p_270826_);
@Shadow public static EquipmentSlot getEquipmentSlotForItem(ItemStack p_147234_) { return null; }
@Shadow protected abstract void actuallyHurt(DamageSource p_21240_, float p_21241_);
@Shadow public abstract void skipDropExperience();
// @formatter:on

public int expToDrop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@ public void reset() {
}
this.keepLevel = false;
this.setDeltaMovement(0, 0, 0);
this.skipDropExperience();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.bukkit.craftbukkit.v.block.CraftBlock;
import org.bukkit.craftbukkit.v.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v.inventory.CraftItemType;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.inventory.FurnaceBurnEvent;
import org.bukkit.event.inventory.FurnaceExtractEvent;
Expand Down Expand Up @@ -168,7 +168,7 @@ public List<RecipeHolder<?>> getRecipesToAwardAndPopExperience(ServerLevel world
private static void arclight$expEvent(ServerLevel level, Vec3 vec3, int amount) {
if (arclight$capturePlayer != null && arclight$captureAmount != 0) {
FurnaceExtractEvent event = new FurnaceExtractEvent(((ServerPlayerEntityBridge) arclight$capturePlayer).bridge$getBukkitEntity(),
CraftBlock.at(level, arclight$captureFurnace.getBlockPos()), CraftMagicNumbers.getMaterial(arclight$item.getItem()), arclight$captureAmount, amount);
CraftBlock.at(level, arclight$captureFurnace.getBlockPos()), CraftItemType.minecraftToBukkit(arclight$item.getItem()), arclight$captureAmount, amount);
Bukkit.getPluginManager().callEvent(event);
amount = event.getExpToDrop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public abstract class ChunkGeneratorMixin implements ChunkGeneratorBridge {
private void arclight$structureSpawn(StructureSet.StructureSelectionEntry p_223105_, StructureManager manager, RegistryAccess registryAccess, RandomState p_223108_, StructureTemplateManager p_223109_, long p_223110_, ChunkAccess p_223111_, ChunkPos chunkPos, SectionPos p_223113_, CallbackInfoReturnable<Boolean> cir,
Structure structure, int i, HolderSet<Biome> holderset, Predicate<Holder<Biome>> predicate, StructureStart structurestart) {
var box = structurestart.getBoundingBox();
var event = new org.bukkit.event.world.AsyncStructureSpawnEvent(((WorldBridge) ((IWorldBridge) manager.level).bridge$getMinecraftWorld()).bridge$getWorld(), CraftStructure.minecraftToBukkit(structure, registryAccess), new org.bukkit.util.BoundingBox(box.minX(), box.minY(), box.minZ(), box.maxX(), box.maxY(), box.maxZ()), chunkPos.x, chunkPos.z);
var event = new org.bukkit.event.world.AsyncStructureSpawnEvent(((WorldBridge) ((IWorldBridge) manager.level).bridge$getMinecraftWorld()).bridge$getWorld(), CraftStructure.minecraftToBukkit(structure), new org.bukkit.util.BoundingBox(box.minX(), box.minY(), box.minZ(), box.maxX(), box.maxY(), box.maxZ()), chunkPos.x, chunkPos.z);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
cir.setReturnValue(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Arclight 1.20.4
public net.minecraft.world.entity.projectile.WindCharge m_305979_()V # explode
public net.minecraft.server.level.DistanceManager f_183902_ # simulationDistance
public net.minecraft.server.level.ChunkMap f_290679_ # serverViewDistance
# Arclight 1.20.2
public net.minecraft.server.network.ServerCommonPacketListenerImpl f_291338_ # connection
public net.minecraft.world.level.levelgen.structure.StructurePiece f_73383_ # boundingBox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"server.PlayerAdvancementsMixin",
"server.ServerFunctionManagerMixin",
"server.ServerScoreboardMixin",
"server.ServerTickRateManagerMixin",
"server.WorldLoaderMixin",
"server.commands.EffectCommandMixin",
"server.commands.GameRuleCommandMixin",
Expand Down

0 comments on commit 3f7d1ee

Please sign in to comment.