Skip to content

Commit

Permalink
1.21.2 (#305)
Browse files Browse the repository at this point in the history
* update gradle and loom

* update to 1.21.2

* increase gitignore aggressiveness on 'run'-like dirs

* loom to 1.7 bc of genSources errors

* code review in SuicideCommand,PlayerManagerMixin,PlayerTeleporter

* update papi

this seems to get rid of the crashing

* final touches?

from basic testing all seems good
~~guess we'll find out soon enough after release~~

---------

Co-authored-by: John Paul Rutigliano <johnpaul122jpr@gmail.com>
  • Loading branch information
arnokeesman and John-Paul-R authored Nov 14, 2024
1 parent 30e6bc0 commit 7ea9845
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 58 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ bin/

run_*/
run/
run.*/

# env
.env
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'groovy'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish'
id "com.modrinth.minotaur" version "2.+"
id 'com.matthewprenger.cursegradle' version "1.4.0"
Expand Down Expand Up @@ -139,7 +139,7 @@ tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"

// Minecraft 1.17 (21w19a) upwards uses Java 16.
it.options.release.set(17)
it.options.release.set(21)
}

//jar {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx2048M

# Fabric Properties
# check these on https://fabricmc.net/develup
minecraft_version=1.21
yarn_mappings=1.21+build.1
loader_version=0.15.11
minecraft_version=1.21.2
yarn_mappings=1.21.2+build.1
loader_version=0.16.7

# Fabric API
fabric_version=0.100.1+1.21
fabric_version=0.106.1+1.21.2

# Mod Properties
mod_name = Essential Commands
Expand All @@ -20,7 +20,7 @@ archives_base_name = essential_commands

# Dependencies
permissions_api_version=0.3.1
placeholder_api_version=2.4.0-pre.2+1.21
placeholder_api_version=2.5.0+1.21.2
pal_version=1.10.0
vanish_version=1.5.3+1.20.4

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ public void fromNbt(NbtCompound tag) {

public void save(RegistryWrapper.WrapperLookup wrapperLookup) {
EssentialCommands.log(Level.INFO, "Saving world_data.dat (Spawn/Warps)...");
super.save(this.worldDataFile, wrapperLookup);
NbtCompound data = this.toNbt(wrapperLookup);
try {
NbtIo.writeCompressed(data, this.worldDataFile.toPath());
} catch (IOException e) {
EssentialCommands.LOGGER.error("Could not save data {}", this, e);
}
EssentialCommands.log(Level.INFO, "world_data.dat saved.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ final static class ExecutionContext {
public final int bottomY;

public ExecutionContext(ServerWorld world) {
this.topY = world.getTopY();
this.topY = world.getTopYInclusive();
this.bottomY = world.getBottomY();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ private static OptionalInt findYBottomUp(Chunk chunk, int x, int z) {

public static int getChunkHighestNonEmptySectionYOffsetOrTopY(Chunk chunk) {
int i = chunk.getHighestNonEmptySection();
return i == chunk.getTopY() ? chunk.getBottomY() : ChunkSectionPos.getBlockCoord(chunk.sectionIndexToCoord(i));
return i == chunk.getTopYInclusive() ? chunk.getBottomY() : ChunkSectionPos.getBlockCoord(chunk.sectionIndexToCoord(i));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public int run(CommandContext<ServerCommandSource> context) throws CommandSyntax

hungerManager.setFoodLevel(20);
hungerManager.setSaturationLevel(5);
hungerManager.setExhaustion(0);
// hungerManager.setExhaustion(0);
// idk, you ca only add to it now

senderPlayerData.sendCommandFeedback("cmd.feed.feedback");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public int run(CommandContext<ServerCommandSource> context) throws CommandSyntax
return 0;
}

player.kill();
player.kill(player.getServerWorld());

return SINGLE_SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static OptionalInt getTop(Chunk chunk, int x, int z) {
}

private static int calculateMaxY(Chunk chunk) {
final int maxY = chunk.getTopY();
final int maxY = chunk.getTopYInclusive();
ChunkSection[] sections = chunk.getSectionArray();
int maxSectionIndex = Math.min(sections.length - 1, maxY >> 4);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.fibermc.essentialcommands.mixin;

import java.io.File;
import java.nio.file.Path;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
Expand All @@ -11,6 +11,6 @@
public interface PersistentStateManagerInvoker {

@Invoker("getFile")
File invokeGetFile(String id);
Path invokeGetFile(String id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import net.minecraft.entity.Entity;
import net.minecraft.network.ClientConnection;
Expand Down Expand Up @@ -90,13 +89,11 @@ public void onPlayerLeave(ServerPlayerEntity player, CallbackInfo callbackInfo)
// created. This lets us update the EC PlayerData, sooner, might be
// before the new ServerPlayerEntity is fully initialized.
target = "Lnet/minecraft/server/network/ServerPlayerEntity;copyFrom(Lnet/minecraft/server/network/ServerPlayerEntity;Z)V"
), locals = LocalCapture.CAPTURE_FAILHARD)
))
public void onRespawnPlayer(
ServerPlayerEntity oldServerPlayerEntity, boolean alive, Entity.RemovalReason removalReason
, CallbackInfoReturnable<ServerPlayerEntity> cir
, TeleportTarget teleportTarget
, ServerWorld serverWorld
, ServerPlayerEntity serverPlayerEntity
ServerPlayerEntity oldServerPlayerEntity, boolean alive, Entity.RemovalReason removalReason,
CallbackInfoReturnable<ServerPlayerEntity> cir,
@Local(ordinal = 1) ServerPlayerEntity serverPlayerEntity
) {
PlayerDataManager.handlePlayerDataRespawnSync(oldServerPlayerEntity, serverPlayerEntity);
}
Expand All @@ -107,7 +104,7 @@ public void onRespawnPlayer(
// This target lets us modify respawn position and dimension (player maybe not _fully_ initialized, still)
target = "Lnet/minecraft/server/network/ServerPlayerEntity;<init>(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/server/world/ServerWorld;Lcom/mojang/authlib/GameProfile;Lnet/minecraft/network/packet/c2s/common/SyncedClientOptions;)V"
))
public void onRespawnPlayer_forResawnLocationOverwrite(
public void onRespawnPlayer_forRespawnLocationOverwrite(
CallbackInfoReturnable<ServerPlayerEntity> cir
, @Local(ordinal = 0, argsOnly = true) ServerPlayerEntity oldServerPlayerEntity
, @Local(ordinal = 0) LocalRef<TeleportTarget> teleportTargetLocalRef
Expand All @@ -122,7 +119,6 @@ public void onRespawnPlayer_forResawnLocationOverwrite(
Vec3d.ZERO,
0,
0,
false,
TeleportTarget.NO_OP
));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fibermc.essentialcommands.access.ServerPlayerEntityAccess;
import com.fibermc.essentialcommands.playerdata.PlayerData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -15,11 +16,13 @@
@Mixin(ServerPlayNetworkHandler.class)
public class ServerPlayNetworkHandlerMixin {

@Unique
private PlayerData getPlayerData() {
var player = ((ServerPlayNetworkHandler) (Object) this).player;
return ((ServerPlayerEntityAccess) player).ec$getPlayerData();
}

@Unique
private void invokeActEvent(Packet<ServerPlayPacketListener> packet) {
getPlayerData().playerActEvent.invoker().onPlayerAct(packet);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.fibermc.essentialcommands.mixin;

import java.util.Set;

import com.fibermc.essentialcommands.EssentialCommands;
import com.fibermc.essentialcommands.access.ServerPlayerEntityAccess;
import com.fibermc.essentialcommands.config.EssentialCommandsConfig;
Expand All @@ -16,19 +18,15 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.registry.RegistryKey;
import net.minecraft.server.PlayerManager;
import net.minecraft.network.packet.s2c.play.PositionFlag;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.world.GameMode;
import net.minecraft.world.TeleportTarget;
import net.minecraft.world.World;
import net.minecraft.world.WorldProperties;

import static com.fibermc.essentialcommands.EssentialCommands.BACKING_CONFIG;
import static com.fibermc.essentialcommands.EssentialCommands.CONFIG;
Expand All @@ -48,7 +46,7 @@ public void onDeath(DamageSource damageSource, CallbackInfo callbackInfo) {
}

@Inject(method = "damage", at = @At("RETURN"))
public void onDamage(DamageSource damageSource, float amount, CallbackInfoReturnable<Boolean> cir) {
public void onDamage(ServerWorld world, DamageSource damageSource, float amount, CallbackInfoReturnable<Boolean> cir) {
// If damage was actually applied...
if (cir.getReturnValue()) {
PlayerDamageCallback.EVENT.invoker().onPlayerDamaged(
Expand All @@ -63,26 +61,18 @@ public void onChangeGameMode(GameMode gameMode, CallbackInfoReturnable<Boolean>
// ((ServerPlayerEntityAccess) this).getEcPlayerData().updatePlayer(((ServerPlayerEntity) (Object) this));
}

@Inject(method = "teleportTo(Lnet/minecraft/world/TeleportTarget;)Lnet/minecraft/entity/Entity;", at = @At(
@Inject(method = "teleportTo(Lnet/minecraft/world/TeleportTarget;)Lnet/minecraft/server/network/ServerPlayerEntity;", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/PlayerManager;sendPlayerStatus(Lnet/minecraft/server/network/ServerPlayerEntity;)V"
), locals = LocalCapture.CAPTURE_FAILSOFT)
public void onTeleportBetweenWorlds(
TeleportTarget teleportTarget,
CallbackInfoReturnable<Entity> cir,
ServerWorld serverWorld,
ServerWorld serverWorld2,
RegistryKey<World> registryKey,
WorldProperties worldProperties,
PlayerManager playerManager)
{
var playerData = ((ServerPlayerEntityAccess) this).ec$getPlayerData();
))
public void onTeleportBetweenWorlds(TeleportTarget teleportTarget, CallbackInfoReturnable<Entity> cir) {
var playerData = this.ec$getPlayerData();
playerData.updatePlayerEntity((ServerPlayerEntity) (Object) this);
}

@Inject(method = "worldChanged", at = @At(value = "RETURN"), locals = LocalCapture.CAPTURE_FAILSOFT)
public void onWorldChanged(ServerWorld origin, CallbackInfo ci, RegistryKey<World> registryKey, RegistryKey<World> registryKey2) {
var playerData = ((ServerPlayerEntityAccess) this).ec$getPlayerData();
@Inject(method = "worldChanged", at = @At(value = "RETURN"))
public void onWorldChanged(ServerWorld origin, CallbackInfo ci) {
var playerData = this.ec$getPlayerData();
if (CONFIG.RECHECK_PLAYER_ABILITY_PERMISSIONS_ON_DIMENSION_CHANGE) {
PlayerDataManager.getInstance().scheduleTask(playerData::clearAbilitiesWithoutPermisisons);
}
Expand Down Expand Up @@ -170,8 +160,8 @@ public void getPlayerListName(CallbackInfoReturnable<Text> cir) {
}

// Teleport hook (for /back)
@Inject(method = "teleport(Lnet/minecraft/server/world/ServerWorld;DDDFF)V", at = @At("HEAD"))
public void onTeleport(ServerWorld targetWorld, double x, double y, double z, float yaw, float pitch, CallbackInfo ci) {
@Inject(method = "teleport(Lnet/minecraft/server/world/ServerWorld;DDDLjava/util/Set;FFZ)Z", at = @At("HEAD"))
public void onTeleport(ServerWorld world, double destX, double destY, double destZ, Set<PositionFlag> flags, float yaw, float pitch, boolean resetCamera, CallbackInfoReturnable<Boolean> cir) {
if (!isSpectator()) {
this.ec$getPlayerData().setPreviousLocation(new MinecraftLocation((ServerPlayerEntity) (Object) this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class TeleportCommandMixin {

@Inject(method = "teleport",
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;teleport(Lnet/minecraft/server/world/ServerWorld;DDDLjava/util/Set;FF)Z")
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;teleport(Lnet/minecraft/server/world/ServerWorld;DDDLjava/util/Set;FFZ)Z")
)
private static void execute(
ServerCommandSource source,
Expand All @@ -35,9 +35,8 @@ private static void execute(
@Coerce Object facingLocation,
CallbackInfo ci
) throws CommandSyntaxException {
if (target instanceof ServerPlayerEntity) {
if (target instanceof ServerPlayerEntity targetPlayer) {
// This cast is guaranteed to work because of where we inject.
var targetPlayer = (ServerPlayerEntity)target;
var targetPlayerData = ((ServerPlayerEntityAccess)target).ec$getPlayerData();
if (!targetPlayer.isSpectator()) {
targetPlayerData.setPreviousLocation(new MinecraftLocation(targetPlayer));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fibermc.essentialcommands.playerdata;

import java.io.File;
import java.io.IOException;
import java.util.*;

import com.fibermc.essentialcommands.ECAbilitySources;
Expand Down Expand Up @@ -29,6 +30,7 @@
import net.minecraft.entity.player.PlayerAbilities;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtIo;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -515,7 +517,13 @@ public int setNickname(Text nickname) {
}

public void save(RegistryWrapper.WrapperLookup wrapperLookup) {
super.save(saveFile, wrapperLookup);
NbtCompound data = this.toNbt(wrapperLookup);

try {
NbtIo.writeCompressed(data, this.saveFile.toPath());
} catch (IOException e) {
EssentialCommands.LOGGER.error("Could not save data {}", this, e);
}
}

public void setTimeUsedRtp(int i) {
Expand Down
Loading

0 comments on commit 7ea9845

Please sign in to comment.