Skip to content

Commit

Permalink
Merge pull request #29 from skerit/1.19
Browse files Browse the repository at this point in the history
Upgrade to 1.19
  • Loading branch information
samolego authored Jun 10, 2022
2 parents e854ba6 + 4d06269 commit f31363e
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 96 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "0.11.0-SNAPSHOT" apply false
id "dev.architectury.loom" version "0.12.0-SNAPSHOT" apply false
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
Expand All @@ -58,11 +56,7 @@
import xyz.nucleoid.disguiselib.impl.mixin.accessor.PlayerListS2CPacketAccessor;
import xyz.nucleoid.disguiselib.impl.mixin.accessor.ThreadedAnvilChunkStorageAccessor;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;

import static net.minecraft.entity.EntityType.PLAYER;
Expand Down Expand Up @@ -168,7 +162,7 @@ public void disguiseAs(EntityType<?> entityType) {
// Previous type was player, we have to send a player remove packet
PlayerListS2CPacket listPacket = new PlayerListS2CPacket(REMOVE_PLAYER);
PlayerListS2CPacketAccessor listPacketAccessor = (PlayerListS2CPacketAccessor) listPacket;
listPacketAccessor.setEntries(Arrays.asList(new PlayerListS2CPacket.Entry(this.disguiselib$profile, 0, GameMode.SURVIVAL, new LiteralText(this.disguiselib$profile.getName()))));
listPacketAccessor.setEntries(Arrays.asList(new PlayerListS2CPacket.Entry(this.disguiselib$profile, 0, GameMode.SURVIVAL, Text.literal(this.disguiselib$profile.getName()), null)));
manager.sendToAll(listPacket);
}

Expand Down Expand Up @@ -347,7 +341,7 @@ public void setGameProfile(@Nullable GameProfile gameProfile) {
*/
@Unique
private void disguiselib$constructFakePlayer(@NotNull GameProfile profile) {
this.disguiselib$disguiseEntity = new ServerPlayerEntity(world.getServer(), (ServerWorld) world, profile);
this.disguiselib$disguiseEntity = new ServerPlayerEntity(world.getServer(), (ServerWorld) world, profile, null);
this.disguiselib$disguiseEntity.getDataTracker().set(getPLAYER_MODEL_PARTS(), (byte) 0x7f);
}

Expand All @@ -372,7 +366,7 @@ public void setGameProfile(@Nullable GameProfile gameProfile) {
PlayerListS2CPacket packet = new PlayerListS2CPacket(REMOVE_PLAYER);
//noinspection ConstantConditions
PlayerListS2CPacketAccessor accessor = (PlayerListS2CPacketAccessor) packet;
accessor.setEntries(Arrays.asList(new PlayerListS2CPacket.Entry(this.disguiselib$profile, 0, GameMode.SURVIVAL, new LiteralText(this.disguiselib$profile.getName()))));
accessor.setEntries(Arrays.asList(new PlayerListS2CPacket.Entry(this.disguiselib$profile, 0, GameMode.SURVIVAL, Text.literal(this.disguiselib$profile.getName()), null)));

PlayerManager playerManager = this.world.getServer().getPlayerManager();
playerManager.sendToAll(packet);
Expand All @@ -390,14 +384,15 @@ public void setGameProfile(@Nullable GameProfile gameProfile) {
ServerWorld targetWorld = player.getWorld();

player.networkHandler.sendPacket(new PlayerRespawnS2CPacket(
targetWorld.method_40134(), // getDimension()
targetWorld.getDimensionKey(), // getDimension()
targetWorld.getRegistryKey(),
BiomeAccess.hashSeed(targetWorld.getSeed()),
player.interactionManager.getGameMode(),
player.interactionManager.getPreviousGameMode(),
targetWorld.isDebugWorld(),
targetWorld.isFlat(),
true
true,
Optional.empty()
));
player.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());

Expand Down Expand Up @@ -451,8 +446,8 @@ private void postTick(CallbackInfo ci) {
this.world.getServer().getPlayerManager().sendToDimension(new EntityPositionS2CPacket(this.disguiselib$entity), this.world.getRegistryKey());
else if(this.disguiselib$entity instanceof ServerPlayerEntity && ++this.disguiselib$ticks % 40 == 0 && this.disguiselib$disguiseEntity != null) {
// "Disguised as" message
MutableText msg = new LiteralText("You are disguised as ")
.append(new TranslatableText(this.disguiselib$disguiseEntity.getType().getTranslationKey()))
MutableText msg = Text.literal("You are disguised as ")
.append(Text.translatable(this.disguiselib$disguiseEntity.getType().getTranslationKey()))
.formatted(Formatting.GREEN);

((ServerPlayerEntity) this.disguiselib$entity).sendMessage(msg, true);
Expand All @@ -479,7 +474,7 @@ private void onRemove(CallbackInfo ci) {

GameProfile profile = new GameProfile(this.disguiselib$entity.getUuid(), this.getName().getString());
// Arrays.asList is needed as we PlayerList needs mutable list
listS2CPacketAccessor.setEntries(Arrays.asList(new PlayerListS2CPacket.Entry(profile, 0, GameMode.SURVIVAL, this.getName())));
listS2CPacketAccessor.setEntries(Arrays.asList(new PlayerListS2CPacket.Entry(profile, 0, GameMode.SURVIVAL, this.getName(), null)));

PlayerManager manager = this.world.getServer().getPlayerManager();
manager.sendToAll(packet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
import net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.MobSpawnS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket.Entry;
import net.minecraft.network.packet.s2c.play.PlayerSpawnS2CPacket;
import net.minecraft.network.packet.s2c.play.TeamS2CPacket;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.world.GameMode;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -42,7 +41,6 @@
import xyz.nucleoid.disguiselib.impl.mixin.accessor.EntitySetHeadYawS2CPacketAccessor;
import xyz.nucleoid.disguiselib.impl.mixin.accessor.EntitySpawnS2CPacketAccessor;
import xyz.nucleoid.disguiselib.impl.mixin.accessor.EntityTrackerUpdateS2CPacketAccessor;
import xyz.nucleoid.disguiselib.impl.mixin.accessor.MobSpawnS2CPacketAccessor;
import xyz.nucleoid.disguiselib.impl.mixin.accessor.PlayerListS2CPacketAccessor;
import xyz.nucleoid.disguiselib.impl.mixin.accessor.PlayerSpawnS2CPacketAccessor;
import xyz.nucleoid.disguiselib.impl.packets.FakePackets;
Expand Down Expand Up @@ -98,8 +96,6 @@ private void disguiseEntity(Packet<?> packet, GenericFutureListener<? extends Fu
}
} else if(packet instanceof PlayerSpawnS2CPacket) {
entity = world.getEntityById(((PlayerSpawnS2CPacketAccessor) packet).getId());
} else if(packet instanceof MobSpawnS2CPacket) {
entity = world.getEntityById(((MobSpawnS2CPacketAccessor) packet).getEntityId());
} else if(packet instanceof EntitySpawnS2CPacket) {
entity = world.getEntityById(((EntitySpawnS2CPacketAccessor) packet).getEntityId());
} else if(packet instanceof EntitiesDestroyS2CPacket && ((EntitiesDestroyS2CPacketAccessor) packet).getEntityIds().getInt(0) == this.player.getId()) {
Expand Down Expand Up @@ -190,15 +186,15 @@ private void disguiseEntity(Packet<?> packet, GenericFutureListener<? extends Fu

// Arrays.asList is used as it returns mutable map, otherwise
// this packet can cause some issues with other mods.
listS2CPacketAccessor.setEntries(Arrays.asList(new Entry(profile, 0, GameMode.SURVIVAL, new LiteralText(profile.getName()))));
listS2CPacketAccessor.setEntries(Arrays.asList(new Entry(profile, 0, GameMode.SURVIVAL, Text.literal(profile.getName()), null)));

this.sendPacket(packet);

if(!(entity instanceof PlayerEntity)) {
packet = new PlayerListS2CPacket(PlayerListS2CPacket.Action.REMOVE_PLAYER);
//noinspection ConstantConditions
listS2CPacketAccessor = (PlayerListS2CPacketAccessor) packet;
listS2CPacketAccessor.setEntries(Arrays.asList(new Entry(profile, 0, GameMode.SURVIVAL, new LiteralText(profile.getName()))));
listS2CPacketAccessor.setEntries(Arrays.asList(new Entry(profile, 0, GameMode.SURVIVAL, Text.literal(profile.getName()), null)));

this.disguiselib$q.add(packet);
this.disguiselib$qTimer = 50;
Expand All @@ -210,10 +206,7 @@ private void disguiseEntity(Packet<?> packet, GenericFutureListener<? extends Fu
// Well, sending spawn packet of the new entity makes the player not being able to move :(
if(disguise.getDisguiseType() != EntityType.PLAYER && disguise.isDisguised()) {
if(disguiseEntity != null) {
if(spawnPacket instanceof MobSpawnS2CPacket) {
((MobSpawnS2CPacketAccessor) spawnPacket).setEntityId(disguiseEntity.getId());
((MobSpawnS2CPacketAccessor) spawnPacket).setUuid(disguiseEntity.getUuid());
} else if(spawnPacket instanceof EntitySpawnS2CPacket) {
if(spawnPacket instanceof EntitySpawnS2CPacket) {
((EntitySpawnS2CPacketAccessor) spawnPacket).setEntityId(disguiseEntity.getId());
((EntitySpawnS2CPacketAccessor) spawnPacket).setUuid(disguiseEntity.getUuid());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,32 @@ public interface EntitySpawnS2CPacketAccessor {
@Mutable
@Accessor("uuid")
void setUuid(UUID uuid);

@Mutable
@Accessor("x")
void setX(double x);
@Mutable
@Accessor("y")
void setY(double y);
@Mutable
@Accessor("z")
void setZ(double z);
@Mutable
@Accessor("velocityX")
void setVelocityX(int velocityX);
@Mutable
@Accessor("velocityY")
void setVelocityY(int velocityY);
@Mutable
@Accessor("velocityZ")
void setVelocityZ(int velocityZ);
@Mutable
@Accessor("yaw")
void setYaw(byte yaw);
@Mutable
@Accessor("pitch")
void setPitch(byte pitch);
@Mutable
@Accessor("headYaw")
void setHeadYaw(byte headYaw);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.Packet;
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
import net.minecraft.network.packet.s2c.play.MobSpawnS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerSpawnS2CPacket;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;
import xyz.nucleoid.disguiselib.api.EntityDisguise;
import xyz.nucleoid.disguiselib.impl.mixin.accessor.EntitySpawnS2CPacketAccessor;
import xyz.nucleoid.disguiselib.impl.mixin.accessor.MobSpawnS2CPacketAccessor;
import xyz.nucleoid.disguiselib.impl.mixin.accessor.PlayerSpawnS2CPacketAccessor;

public class FakePackets {
Expand All @@ -35,10 +32,8 @@ public static Packet<?> universalSpawnPacket(Entity entity) {

Packet<?> packet = disguise.createSpawnPacket();

if(packet instanceof MobSpawnS2CPacket) {
if(packet instanceof EntitySpawnS2CPacket) {
packet = fakeMobSpawnS2CPacket(entity);
} else if(packet instanceof EntitySpawnS2CPacket) {
packet = fakeEntitySpawnS2CPacket(entity);
} else if(packet instanceof PlayerSpawnS2CPacket) {
packet = fakePlayerSpawnS2CPacket(entity);
}
Expand All @@ -47,21 +42,21 @@ public static Packet<?> universalSpawnPacket(Entity entity) {
}

/**
* Constructs a fake {@link MobSpawnS2CPacket} for the given entity.
* Constructs a fake {@link EntitySpawnS2CPacket} for the given entity.
*
* @param entity entity that requires fake packet
*
* @return fake {@link MobSpawnS2CPacket}
* @return fake {@link EntitySpawnS2CPacket}
*/
public static MobSpawnS2CPacket fakeMobSpawnS2CPacket(Entity entity) {
public static EntitySpawnS2CPacket fakeMobSpawnS2CPacket(Entity entity) {
EntityDisguise disguise = (EntityDisguise) entity;
MobSpawnS2CPacket packet = new MobSpawnS2CPacket((LivingEntity) disguise.getDisguiseEntity());
EntitySpawnS2CPacket packet = new EntitySpawnS2CPacket((LivingEntity) disguise.getDisguiseEntity());

MobSpawnS2CPacketAccessor accessor = (MobSpawnS2CPacketAccessor) packet;
EntitySpawnS2CPacketAccessor accessor = (EntitySpawnS2CPacketAccessor) packet;
accessor.setEntityId(entity.getId());
accessor.setUuid(entity.getUuid());

accessor.setEntityType(Registry.ENTITY_TYPE.getRawId(disguise.getDisguiseType()));
accessor.setEntityType(disguise.getDisguiseType());
accessor.setX(entity.getX());
accessor.setY(entity.getY());
accessor.setZ(entity.getZ());
Expand Down
1 change: 0 additions & 1 deletion common/src/main/resources/disguiselib.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"accessor.EntitySpawnS2CPacketAccessor",
"accessor.EntityTrackerEntryAccessor",
"accessor.EntityTrackerUpdateS2CPacketAccessor",
"accessor.MobSpawnS2CPacketAccessor",
"accessor.PlayerEntityAccessor",
"accessor.PlayerListS2CPacketAccessor",
"accessor.PlayerSpawnS2CPacketAccessor",
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
org.gradle.jvmargs=-Xmx2G

# Fabric Properties
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.2
loader_version=0.13.3
minecraft_version=1.19
yarn_mappings=1.19+build.1
loader_version=0.14.6

#Fabric api
fabric_version=0.48.0+1.18.2
fabric_version=0.55.3+1.19

#Forge
forge_version=40.0.19
forge_enabled=true
forge_enabled=false

# Mod Properties
mod_version = 1.2.2
mod_version = 1.3.0
maven_group = xyz.nucleoid
archives_base_name = disguiselib

0 comments on commit f31363e

Please sign in to comment.