Skip to content

Commit

Permalink
Update to 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Dec 5, 2024
1 parent 90bf223 commit c03f521
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 158 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ on: [pull_request, push]

jobs:
build:
strategy:
matrix:
# Use these Java versions
java: [17]
os: [ubuntu-20.04]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- name: checkout repository
uses: actions/checkout@v2
Expand All @@ -22,14 +17,14 @@ jobs:
- name: setup jdk ${{ matrix.java }}
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
java-version: 21
- name: make gradle wrapper executable
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew
- name: build
run: ./gradlew build
- name: capture build artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 17
java-version: 21

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand All @@ -38,7 +38,7 @@ jobs:
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}

- name: Upload GitHub release
uses: AButler/upload-release-assets@v2.0
uses: AButler/upload-release-assets@v3.0
with:
files: 'build/libs/*.jar'
repo-token: ${{ secrets.GITHUB_TOKEN }}
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
plugins {
id "java"
id "maven-publish"
id 'fabric-loom' version '1.4.+'
id 'fabric-loom' version '1.7.+'
}
apply plugin: 'fabric-loom'

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = rootProject.archives_base_name
version = rootProject.mod_version
Expand All @@ -25,7 +25,6 @@ tasks.withType(JavaCompile).configureEach {
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"

it.options.release = 17
}

processResources {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G
# Fabric Properties
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
loader_version=0.15.3
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.1
loader_version=0.16.9
#Fabric api
fabric_version=0.91.1+1.20.4
fabric_version=0.110.2+1.21.4
# Mod Properties
mod_version=1.3.5
mod_version=1.3.6
maven_group=xyz.nucleoid
archives_base_name = disguiselib
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.command.argument.NbtCompoundArgumentType;
import net.minecraft.command.argument.RegistryEntryArgumentType;
import net.minecraft.command.argument.RegistryEntryReferenceArgumentType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnReason;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKeys;
Expand Down Expand Up @@ -41,7 +43,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, C
.requires(src -> src.hasPermissionLevel(2))
.then(argument("target", entities())
.then(literal("as")
.then(argument("disguise", RegistryEntryArgumentType.registryEntry(commandRegistryAccess, RegistryKeys.ENTITY_TYPE))
.then(argument("disguise", new RegistryEntryReferenceArgumentType<>(commandRegistryAccess, RegistryKeys.ENTITY_TYPE))
.suggests(SUMMONABLE_ENTITIES)
.executes(DisguiseCommand::setDisguise)
.then(argument("nbt", NbtCompoundArgumentType.nbtCompound())
Expand Down Expand Up @@ -130,7 +132,7 @@ private static int clearDisguise(CommandContext<ServerCommandSource> ctx) throws
private static int setDisguise(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
Collection<? extends Entity> entities = EntityArgumentType.getEntities(ctx, "target");
ServerCommandSource src = ctx.getSource();
var type = RegistryEntryArgumentType.getRegistryEntry(ctx, "disguise", RegistryKeys.ENTITY_TYPE);
var type = RegistryEntryReferenceArgumentType.getRegistryEntry(ctx, "disguise", RegistryKeys.ENTITY_TYPE);
var disguise = Registries.ENTITY_TYPE.getId(type.value());

NbtCompound nbt;
Expand All @@ -142,7 +144,7 @@ private static int setDisguise(CommandContext<ServerCommandSource> ctx) throws C
nbt.putString("id", disguise.toString());

NbtCompound finalNbt = nbt;
entities.forEach(entity -> EntityType.loadEntityWithPassengers(finalNbt, ctx.getSource().getWorld(), (entityx) -> {
entities.forEach(entity -> EntityType.loadEntityWithPassengers(finalNbt, ctx.getSource().getWorld(), SpawnReason.LOAD, (entityx) -> {
if(entity == src.getEntity()) {
if(src.hasPermissionLevel(2))
((EntityDisguise) entity).disguiseAs(entityx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerPosition;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
Expand All @@ -19,13 +20,12 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
import net.minecraft.server.world.ServerChunkLoadingManager;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import net.minecraft.world.biome.source.BiomeAccess;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -38,7 +38,7 @@
import xyz.nucleoid.disguiselib.api.DisguiseUtils;
import xyz.nucleoid.disguiselib.api.EntityDisguise;
import xyz.nucleoid.disguiselib.impl.mixin.accessor.EntityTrackerEntryAccessor;
import xyz.nucleoid.disguiselib.impl.mixin.accessor.ThreadedAnvilChunkStorageAccessor;
import xyz.nucleoid.disguiselib.impl.mixin.accessor.ServerChunkLoadingManagerAccessor;

import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -115,6 +115,8 @@ public abstract class EntityMixin_Disguise implements EntityDisguise, DisguiseUt
@Shadow
protected abstract void addPassenger(Entity passenger);

@Shadow private boolean onGround;

/**
* Tells you the disguised status.
*
Expand Down Expand Up @@ -147,7 +149,7 @@ public void disguiseAs(EntityType<?> entityType) {
} else {
// Why null check? Well, if entity was disguised via EntityDisguise#disguiseAs(Entity), this field is already set
if (this.disguiselib$disguiseEntity == null || this.disguiselib$disguiseEntity.getType() != entityType)
this.disguiselib$disguiseEntity = entityType.create(world);
this.disguiselib$disguiseEntity = entityType.create(world, SpawnReason.LOAD);

if (this.disguiselib$profile != null) {
// Previous type was player, we have to send a player remove packet
Expand All @@ -169,13 +171,13 @@ public void disguiseAs(EntityType<?> entityType) {
// Minor datatracker thingies
this.updateTrackedData();

// Updating entity on the client
manager.sendToDimension(new EntitiesDestroyS2CPacket(this.id), worldRegistryKey);
manager.sendToDimension(new EntitySpawnS2CPacket(this.disguiselib$entity), worldRegistryKey); // will be replaced by network handler
//noinspection ReferenceToMixin
var tracker = ((ServerChunkLoadingManagerAccessor) ((ServerWorld) this.world).getChunkManager().chunkLoadingManager).getEntityTrackers().get(this.getId());

manager.sendToDimension(new EntityTrackerUpdateS2CPacket(this.id, this.getDataTracker().getChangedEntries()), worldRegistryKey);
manager.sendToDimension(new EntityEquipmentUpdateS2CPacket(this.id, this.disguiselib$getEquipment()), worldRegistryKey); // Reload equipment
manager.sendToDimension(new EntitySetHeadYawS2CPacket(this.disguiselib$entity, (byte) ((int) (this.getHeadYaw() * 256.0F / 360.0F))), worldRegistryKey); // Head correction
for (var listener : tracker.getListeners()) {
tracker.getEntry().stopTracking(listener.getPlayer());
tracker.getEntry().startTracking(listener.getPlayer());
}
}

/**
Expand Down Expand Up @@ -364,8 +366,8 @@ public void setGameProfile(@Nullable GameProfile gameProfile) {
playerManager.sendToAll(addPacket);

ServerChunkManager manager = (ServerChunkManager) this.world.getChunkManager();
ThreadedAnvilChunkStorage storage = manager.threadedAnvilChunkStorage;
EntityTrackerEntryAccessor trackerEntry = ((ThreadedAnvilChunkStorageAccessor) storage).getEntityTrackers().get(this.getId());
var storage = manager.chunkLoadingManager;
EntityTrackerEntryAccessor trackerEntry = ((ServerChunkLoadingManagerAccessor) storage).getEntityTrackers().get(this.getId());
if (trackerEntry != null)
trackerEntry.getListeners().forEach(tracking -> trackerEntry.getEntry().startTracking(tracking.getPlayer()));

Expand All @@ -382,7 +384,7 @@ public void setGameProfile(@Nullable GameProfile gameProfile) {
player.networkHandler.sendPacket(new HealthUpdateS2CPacket(player.getHealth(), player.getHungerManager().getFoodLevel(), player.getHungerManager().getSaturationLevel()));

for (StatusEffectInstance statusEffect : player.getStatusEffects()) {
player.networkHandler.sendPacket(new EntityStatusEffectS2CPacket(player.getId(), statusEffect));
player.networkHandler.sendPacket(new EntityStatusEffectS2CPacket(player.getId(), statusEffect, false));
}

player.sendAbilitiesUpdate();
Expand Down Expand Up @@ -423,7 +425,15 @@ private void postTick(CallbackInfo ci) {
// more than once per second -> movement isn't as "blocky"
if(this.isDisguised()) {
if(this.world.getServer() != null && !(this.disguiselib$disguiseEntity instanceof LivingEntity) && !(this.disguiselib$entity instanceof PlayerEntity))
this.world.getServer().getPlayerManager().sendToDimension(new EntityPositionS2CPacket(this.disguiselib$entity), this.world.getRegistryKey());
this.world.getServer().getPlayerManager().sendToDimension(
new EntityPositionS2CPacket(
this.disguiselib$entity.getId(),
new PlayerPosition(
this.disguiselib$entity.getSyncedPos(),
this.disguiselib$entity.getVelocity(),
this.disguiselib$entity.getYaw(),
this.disguiselib$entity.getPitch()
), Set.of(), this.onGround), this.world.getRegistryKey());
else if(this.disguiselib$entity instanceof ServerPlayerEntity && ++this.disguiselib$ticks % 40 == 0 && this.disguiselib$disguiseEntity != null) {
// "Disguised as" message
MutableText msg = Text.literal("You are disguised as ")
Expand Down Expand Up @@ -468,7 +478,7 @@ private void fromTag(NbtCompound tag, CallbackInfo ci) {
NbtCompound disguiseTag = (NbtCompound) tag.get("DisguiseLib");

if(disguiseTag != null) {
Identifier disguiseTypeId = new Identifier(disguiseTag.getString("DisguiseType"));
Identifier disguiseTypeId = Identifier.tryParse(disguiseTag.getString("DisguiseType"));
this.disguiselib$disguiseType = Registries.ENTITY_TYPE.get(disguiseTypeId);

if(this.disguiselib$disguiseType == PLAYER) {
Expand All @@ -477,7 +487,7 @@ private void fromTag(NbtCompound tag, CallbackInfo ci) {
} else {
NbtCompound disguiseEntityTag = disguiseTag.getCompound("DisguiseEntity");
if(!disguiseEntityTag.isEmpty())
this.disguiselib$disguiseEntity = EntityType.loadEntityWithPassengers(disguiseEntityTag, this.world, (entityx) -> entityx);
this.disguiselib$disguiseEntity = EntityType.loadEntityWithPassengers(disguiseEntityTag, this.world, SpawnReason.LOAD, (entityx) -> entityx);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ private void disguiseEntity(Packet<ClientPlayPacketListener> packet, PacketCallb
return;
}
if (packet instanceof BundleS2CPacket bundleS2CPacket) {
if (bundleS2CPacket.getPackets() instanceof ArrayList<Packet<ClientPlayPacketListener>> list) {
var list2 = new ArrayList<Packet<ClientPlayPacketListener>>();
var adder = new ArrayList<Packet<ClientPlayPacketListener>>();
if (bundleS2CPacket.getPackets() instanceof ArrayList<Packet<? super ClientPlayPacketListener>> list) {
var list2 = new ArrayList<Packet<? super ClientPlayPacketListener>>();
var adder = new ArrayList<Packet<? super ClientPlayPacketListener>>();
var atomic = new AtomicBoolean(true);
for (var packet2 : list) {
atomic.set(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import net.minecraft.entity.EntityType;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerPosition;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ConnectedClientData;
import net.minecraft.server.network.ServerCommonNetworkHandler;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.network.*;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -48,11 +48,14 @@ public ServerPlayNetworkHandlerMixin_Disguiser(MinecraftServer server, ClientCon
super(server, connection, clientData);
}

public void disguiselib$transformPacket(Packet<ClientPlayPacketListener> packet, Runnable remove, Consumer<Packet<ClientPlayPacketListener>> add) {
public void disguiselib$transformPacket(Packet<? super ClientPlayPacketListener> packet, Runnable remove, Consumer<Packet<ClientPlayPacketListener>> add) {
World world = this.player.getEntityWorld();
Entity entity = null;
if (packet instanceof EntitySpawnS2CPacket) {
entity = world.getEntityById(((EntitySpawnS2CPacketAccessor) packet).getEntityId());
var entity = world.getEntityById(((EntitySpawnS2CPacketAccessor) packet).getEntityId());

if(entity != null) {
disguiselib$sendFakePacket(entity, remove, add);
}
} else if (packet instanceof EntitiesDestroyS2CPacket && !((EntitiesDestroyS2CPacketAccessor) packet).getEntityIds().isEmpty() && ((EntitiesDestroyS2CPacketAccessor) packet).getEntityIds().getInt(0) == this.player.getId()) {
remove.run();
return;
Expand Down Expand Up @@ -99,7 +102,7 @@ public ServerPlayNetworkHandlerMixin_Disguiser(MinecraftServer server, ClientCon
return;
}
} else if(packet instanceof EntityVelocityUpdateS2CPacket velocityPacket) {
int id = velocityPacket.getId();
int id = velocityPacket.getEntityId();
if(id != this.player.getId()) {

Entity entity1 = world.getEntityById(id);
Expand All @@ -109,10 +112,6 @@ public ServerPlayNetworkHandlerMixin_Disguiser(MinecraftServer server, ClientCon
}
}
}

if(entity != null) {
disguiselib$sendFakePacket(entity, remove, add);
}
}

/**
Expand All @@ -125,12 +124,16 @@ public ServerPlayNetworkHandlerMixin_Disguiser(MinecraftServer server, ClientCon
EntityDisguise disguise = (EntityDisguise) entity;
GameProfile profile = disguise.getGameProfile();
Entity disguiseEntity = disguise.getDisguiseEntity();
if (disguiseEntity == null) {
return;
}

Packet<?> spawnPacket;
var entry = new EntityTrackerEntry((ServerWorld) entity.getWorld(), entity, 1, true, (c) -> {});
if(((EntityDisguise) this.player).hasTrueSight() || !disguise.isDisguised())
spawnPacket = entity.createSpawnPacket();
spawnPacket = entity.createSpawnPacket(entry);
else
spawnPacket = FakePackets.universalSpawnPacket(entity);
spawnPacket = FakePackets.universalSpawnPacket(entity, entry, entity.getId() != this.player.getId());

if (disguise.getDisguiseType() == EntityType.PLAYER) {
PlayerListS2CPacket packet = new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, (ServerPlayerEntity) disguiseEntity);
Expand Down Expand Up @@ -182,11 +185,9 @@ public ServerPlayNetworkHandlerMixin_Disguiser(MinecraftServer server, ClientCon
private void disguiselib$moveDisguiseEntity(PlayerMoveC2SPacket packet, CallbackInfo ci) {
if(((EntityDisguise) this.player).isDisguised() && ((EntityDisguise) this.player).getDisguiseType() != EntityType.PLAYER) {
// Moving disguise for the disguised player
EntityPositionS2CPacket s2CPacket = new EntityPositionS2CPacket(this.player);
EntityPositionS2CPacket s2CPacket = new EntityPositionS2CPacket(((EntityDisguise) this.player).getDisguiseEntity().getId(), new PlayerPosition(player.getSyncedPos(), Vec3d.ZERO, player.getYaw(), player.getPitch()), Set.of(), false);
EntitySetHeadYawS2CPacket headYawS2CPacket = new EntitySetHeadYawS2CPacket(this.player, (byte)((int)(this.player.getHeadYaw() * 256.0F / 360.0F)));

//noinspection ConstantConditions
((EntityPositionS2CPacketAccessor) s2CPacket).setEntityId(((EntityDisguise) this.player).getDisguiseEntity().getId());
//noinspection ConstantConditions
((EntitySetHeadYawS2CPacketAccessor) headYawS2CPacket).setEntityId(((EntityDisguise) this.player).getDisguiseEntity().getId());
this.sendPacket(s2CPacket);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@Mixin(EntitySetHeadYawS2CPacket.class)
public interface EntitySetHeadYawS2CPacketAccessor {
@Mutable
@Accessor("entity")
@Accessor("entityId")
void setEntityId(int id);
}
Loading

0 comments on commit c03f521

Please sign in to comment.