Skip to content

Commit

Permalink
Add 1.21.4 support (#597)
Browse files Browse the repository at this point in the history
* Initial work on 1.21.4 support

* Implement loading state packet

* Update VV

* Fix generated java classes
  • Loading branch information
AlexProgrammerDE authored Dec 6, 2024
1 parent 928839a commit 344b91a
Show file tree
Hide file tree
Showing 23 changed files with 37,377 additions and 27,507 deletions.
4 changes: 2 additions & 2 deletions data-generator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
}

unimined.minecraft {
version("1.21.3")
version("1.21.4")

mappings {
intermediary()
Expand All @@ -33,7 +33,7 @@ unimined.minecraft {
}

fabric {
loader("0.16.5")
loader("0.16.9")
}

defaultRemapJar = true
Expand Down
14 changes: 7 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
log4j = "2.24.2"
grpc = "1.68.2"
protobuf = "4.29.1"
via-version = "5.1.1"
via-backwards = "5.1.1"
via-rewind = "4.0.3"
via-legacy = "3.0.5"
via-version = "5.2.0"
via-backwards = "5.2.0"
via-rewind = "4.0.4"
via-legacy = "3.0.6"
via-aprilfools = "3.0.4"
via-loader = "3.0.4"
via-bedrock = "0.0.12-SNAPSHOT"
mcprotocollib = "d6d2a33"
via-bedrock = "0.0.14-SNAPSHOT"
mcprotocollib = "1.21.4-SNAPSHOT"
kyori = "4.17.0"
reactor = "1.2.0"
classtransform = "1.14.0"
Expand Down Expand Up @@ -44,7 +44,7 @@ disruptor = "com.lmax:disruptor:4.0.0"
brigadier = "com.mojang:brigadier:1.1.8"
picoli = "info.picocli:picocli:4.7.6"
picoli-codegen = "info.picocli:picocli-codegen:4.7.6"
mcprotocollib = { module = "com.github.AlexProgrammerDE:MCProtocolLib", version.ref = "mcprotocollib" }
mcprotocollib = { group = "org.geysermc.mcprotocollib", name = "protocol", version.ref = "mcprotocollib" }
mcstructs = "net.lenni0451.mcstructs:all:2.5.5"
netty-raknet = "org.cloudburstmc.netty:netty-transport-raknet:1.0.0.CR3-SNAPSHOT"
via-version = { module = "com.viaversion:viaversion-common", version.ref = "via-version" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public class BlockTags {
public static final TagKey<BlockType> SMALL_FLOWERS = register("minecraft:small_flowers");
public static final TagKey<BlockType> BEDS = register("minecraft:beds");
public static final TagKey<BlockType> FENCES = register("minecraft:fences");
public static final TagKey<BlockType> TALL_FLOWERS = register("minecraft:tall_flowers");
public static final TagKey<BlockType> FLOWERS = register("minecraft:flowers");
public static final TagKey<BlockType> BEE_ATTRACTIVE = register("minecraft:bee_attractive");
public static final TagKey<BlockType> PIGLIN_REPELLENTS = register("minecraft:piglin_repellents");
public static final TagKey<BlockType> GOLD_ORES = register("minecraft:gold_ores");
public static final TagKey<BlockType> IRON_ORES = register("minecraft:iron_ores");
Expand Down
12 changes: 11 additions & 1 deletion server/src/main/java/com/soulfiremc/server/data/BlockType.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import net.kyori.adventure.key.Key;

import java.io.IOException;
import java.util.List;

@SuppressWarnings("unused")
public record BlockType(
Expand Down Expand Up @@ -394,12 +393,19 @@ public FluidType read(JsonReader in) throws IOException {
public static final BlockType MELON_STEM = register("minecraft:melon_stem");
public static final BlockType VINE = register("minecraft:vine");
public static final BlockType GLOW_LICHEN = register("minecraft:glow_lichen");
public static final BlockType RESIN_CLUMP = register("minecraft:resin_clump");
public static final BlockType OAK_FENCE_GATE = register("minecraft:oak_fence_gate");
public static final BlockType BRICK_STAIRS = register("minecraft:brick_stairs");
public static final BlockType STONE_BRICK_STAIRS = register("minecraft:stone_brick_stairs");
public static final BlockType MUD_BRICK_STAIRS = register("minecraft:mud_brick_stairs");
public static final BlockType MYCELIUM = register("minecraft:mycelium");
public static final BlockType LILY_PAD = register("minecraft:lily_pad");
public static final BlockType RESIN_BLOCK = register("minecraft:resin_block");
public static final BlockType RESIN_BRICKS = register("minecraft:resin_bricks");
public static final BlockType RESIN_BRICK_STAIRS = register("minecraft:resin_brick_stairs");
public static final BlockType RESIN_BRICK_SLAB = register("minecraft:resin_brick_slab");
public static final BlockType RESIN_BRICK_WALL = register("minecraft:resin_brick_wall");
public static final BlockType CHISELED_RESIN_BRICKS = register("minecraft:chiseled_resin_bricks");
public static final BlockType NETHER_BRICKS = register("minecraft:nether_bricks");
public static final BlockType NETHER_BRICK_FENCE = register("minecraft:nether_brick_fence");
public static final BlockType NETHER_BRICK_STAIRS = register("minecraft:nether_brick_stairs");
Expand Down Expand Up @@ -1145,6 +1151,10 @@ public FluidType read(JsonReader in) throws IOException {
public static final BlockType PALE_MOSS_BLOCK = register("minecraft:pale_moss_block");
public static final BlockType PALE_MOSS_CARPET = register("minecraft:pale_moss_carpet");
public static final BlockType PALE_HANGING_MOSS = register("minecraft:pale_hanging_moss");
public static final BlockType OPEN_EYEBLOSSOM = register("minecraft:open_eyeblossom");
public static final BlockType CLOSED_EYEBLOSSOM = register("minecraft:closed_eyeblossom");
public static final BlockType POTTED_OPEN_EYEBLOSSOM = register("minecraft:potted_open_eyeblossom");
public static final BlockType POTTED_CLOSED_EYEBLOSSOM = register("minecraft:potted_closed_eyeblossom");
//@formatter:on

public BlockType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public record EntityType(
public static final EntityType COMMAND_BLOCK_MINECART = register("minecraft:command_block_minecart");
public static final EntityType COW = register("minecraft:cow");
public static final EntityType CREAKING = register("minecraft:creaking");
public static final EntityType CREAKING_TRANSIENT = register("minecraft:creaking_transient");
public static final EntityType CREEPER = register("minecraft:creeper");
public static final EntityType DARK_OAK_BOAT = register("minecraft:dark_oak_boat");
public static final EntityType DARK_OAK_CHEST_BOAT = register("minecraft:dark_oak_chest_boat");
Expand Down
8 changes: 5 additions & 3 deletions server/src/main/java/com/soulfiremc/server/data/ItemTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public class ItemTags {
public static final TagKey<ItemType> SMALL_FLOWERS = register("minecraft:small_flowers");
public static final TagKey<ItemType> BEDS = register("minecraft:beds");
public static final TagKey<ItemType> FENCES = register("minecraft:fences");
public static final TagKey<ItemType> TALL_FLOWERS = register("minecraft:tall_flowers");
public static final TagKey<ItemType> FLOWERS = register("minecraft:flowers");
public static final TagKey<ItemType> PIGLIN_REPELLENTS = register("minecraft:piglin_repellents");
public static final TagKey<ItemType> PIGLIN_LOVED = register("minecraft:piglin_loved");
public static final TagKey<ItemType> IGNORED_BY_PIGLIN_BABIES = register("minecraft:ignored_by_piglin_babies");
Expand Down Expand Up @@ -163,7 +161,6 @@ public class ItemTags {
public static final TagKey<ItemType> SKULLS = register("minecraft:skulls");
public static final TagKey<ItemType> TRIMMABLE_ARMOR = register("minecraft:trimmable_armor");
public static final TagKey<ItemType> TRIM_MATERIALS = register("minecraft:trim_materials");
public static final TagKey<ItemType> TRIM_TEMPLATES = register("minecraft:trim_templates");
public static final TagKey<ItemType> DECORATED_POT_SHERDS = register("minecraft:decorated_pot_sherds");
public static final TagKey<ItemType> DECORATED_POT_INGREDIENTS = register("minecraft:decorated_pot_ingredients");
public static final TagKey<ItemType> SWORDS = register("minecraft:swords");
Expand All @@ -177,6 +174,11 @@ public class ItemTags {
public static final TagKey<ItemType> DYEABLE = register("minecraft:dyeable");
public static final TagKey<ItemType> FURNACE_MINECART_FUEL = register("minecraft:furnace_minecart_fuel");
public static final TagKey<ItemType> BUNDLES = register("minecraft:bundles");
public static final TagKey<ItemType> SKELETON_PREFERRED_WEAPONS = register("minecraft:skeleton_preferred_weapons");
public static final TagKey<ItemType> DROWNED_PREFERRED_WEAPONS = register("minecraft:drowned_preferred_weapons");
public static final TagKey<ItemType> PIGLIN_PREFERRED_WEAPONS = register("minecraft:piglin_preferred_weapons");
public static final TagKey<ItemType> PILLAGER_PREFERRED_WEAPONS = register("minecraft:pillager_preferred_weapons");
public static final TagKey<ItemType> WITHER_SKELETON_DISLIKED_WEAPONS = register("minecraft:wither_skeleton_disliked_weapons");
public static final TagKey<ItemType> FOOT_ARMOR_ENCHANTABLE = register("minecraft:enchantable/foot_armor");
public static final TagKey<ItemType> LEG_ARMOR_ENCHANTABLE = register("minecraft:enchantable/leg_armor");
public static final TagKey<ItemType> CHEST_ARMOR_ENCHANTABLE = register("minecraft:enchantable/chest_armor");
Expand Down
10 changes: 10 additions & 0 deletions server/src/main/java/com/soulfiremc/server/data/ItemType.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ public record ItemType(
public static final ItemType RED_WOOL = register("minecraft:red_wool");
public static final ItemType BLACK_WOOL = register("minecraft:black_wool");
public static final ItemType DANDELION = register("minecraft:dandelion");
public static final ItemType OPEN_EYEBLOSSOM = register("minecraft:open_eyeblossom");
public static final ItemType CLOSED_EYEBLOSSOM = register("minecraft:closed_eyeblossom");
public static final ItemType POPPY = register("minecraft:poppy");
public static final ItemType BLUE_ORCHID = register("minecraft:blue_orchid");
public static final ItemType ALLIUM = register("minecraft:allium");
Expand Down Expand Up @@ -401,6 +403,13 @@ public record ItemType(
public static final ItemType MELON = register("minecraft:melon");
public static final ItemType VINE = register("minecraft:vine");
public static final ItemType GLOW_LICHEN = register("minecraft:glow_lichen");
public static final ItemType RESIN_CLUMP = register("minecraft:resin_clump");
public static final ItemType RESIN_BLOCK = register("minecraft:resin_block");
public static final ItemType RESIN_BRICKS = register("minecraft:resin_bricks");
public static final ItemType RESIN_BRICK_STAIRS = register("minecraft:resin_brick_stairs");
public static final ItemType RESIN_BRICK_SLAB = register("minecraft:resin_brick_slab");
public static final ItemType RESIN_BRICK_WALL = register("minecraft:resin_brick_wall");
public static final ItemType CHISELED_RESIN_BRICKS = register("minecraft:chiseled_resin_bricks");
public static final ItemType BRICK_STAIRS = register("minecraft:brick_stairs");
public static final ItemType STONE_BRICK_STAIRS = register("minecraft:stone_brick_stairs");
public static final ItemType MUD_BRICK_STAIRS = register("minecraft:mud_brick_stairs");
Expand Down Expand Up @@ -1185,6 +1194,7 @@ public record ItemType(
public static final ItemType FIREWORK_STAR = register("minecraft:firework_star");
public static final ItemType ENCHANTED_BOOK = register("minecraft:enchanted_book");
public static final ItemType NETHER_BRICK = register("minecraft:nether_brick");
public static final ItemType RESIN_BRICK = register("minecraft:resin_brick");
public static final ItemType PRISMARINE_SHARD = register("minecraft:prismarine_shard");
public static final ItemType PRISMARINE_CRYSTALS = register("minecraft:prismarine_crystals");
public static final ItemType RABBIT = register("minecraft:rabbit");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public record NamedEntityData(String key, int networkId, String entityClass) {
public static final NamedEntityData CAT__RELAX_STATE_ONE = register("relax_state_one", 21, "cat");
public static final NamedEntityData CAT__VARIANT = register("variant", 19, "cat");
public static final NamedEntityData CREAKING__CAN_MOVE = register("can_move", 16, "creaking");
public static final NamedEntityData CREAKING__HOME_POS = register("home_pos", 19, "creaking");
public static final NamedEntityData CREAKING__IS_ACTIVE = register("is_active", 17, "creaking");
public static final NamedEntityData CREAKING__IS_TEARING_DOWN = register("is_tearing_down", 18, "creaking");
public static final NamedEntityData CREEPER__IS_IGNITED = register("is_ignited", 18, "creeper");
public static final NamedEntityData CREEPER__IS_POWERED = register("is_powered", 17, "creeper");
public static final NamedEntityData CREEPER__SWELL_DIR = register("swell_dir", 16, "creeper");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ private static void syncBotAndUser(BotConnection botConnection, Session clientSe
entry.getLatency(),
entry.getGameMode(),
entry.getDisplayName(),
entry.isShowHat(),
entry.getListOrder(),
entry.getSessionId(),
entry.getExpiresAt(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.soulfiremc.server.settings.lib.SettingsSource;
import com.soulfiremc.server.util.EntityMovement;
import com.soulfiremc.server.util.SFHelpers;
import com.soulfiremc.server.util.mcstructs.LevelLoadStatusManager;
import com.soulfiremc.server.util.structs.TickTimer;
import com.soulfiremc.server.viaversion.SFVersionConstants;
import io.netty.buffer.Unpooled;
Expand Down Expand Up @@ -91,6 +92,7 @@
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.*;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.border.*;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundClientCommandPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundPlayerLoadedPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosRotPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerRotPacket;
Expand Down Expand Up @@ -127,6 +129,7 @@ public final class SessionDataManager {
private Key[] serverEnabledFeatures;
private List<KnownPack> serverKnownPacks;
private LocalPlayer localPlayer;
private LevelLoadStatusManager levelLoadStatusManager;
private @Nullable ServerPlayData serverPlayData;
private BorderState borderState;
private HealthData healthData;
Expand Down Expand Up @@ -178,9 +181,9 @@ private static List<String> readChannels(ClientboundCustomPayloadPacket packet)

private float getTickTargetMillis(float defaultValue) {
if (this.level != null) {
var lv = this.level.tickRateManager();
if (lv.runsNormally()) {
return Math.max(defaultValue, lv.millisecondsPerTick());
var tickRateManager = this.level.tickRateManager();
if (tickRateManager.runsNormally()) {
return Math.max(defaultValue, tickRateManager.millisecondsPerTick());
}
}

Expand Down Expand Up @@ -260,6 +263,8 @@ public void onJoin(ClientboundLoginPacket packet) {
connection.inventoryManager().setContainer(0, localPlayer.inventory());

entityTrackerState.addEntity(localPlayer);

startWaitingForNewLevel(localPlayer, currentLevel());
}

private void processSpawnInfo(PlayerSpawnInfo spawnInfo) {
Expand All @@ -279,6 +284,10 @@ private void processSpawnInfo(PlayerSpawnInfo spawnInfo) {
portalCooldown = spawnInfo.getPortalCooldown();
}

private void startWaitingForNewLevel(LocalPlayer player, Level level) {
this.levelLoadStatusManager = new LevelLoadStatusManager(player, level);
}

@EventHandler
public void onTickingState(ClientboundTickingStatePacket packet) {
if (this.level != null) {
Expand Down Expand Up @@ -370,6 +379,8 @@ public void onRespawn(ClientboundRespawnPacket packet) {
// We are now possibly in a new dimension
localPlayer.level(currentLevel());

this.startWaitingForNewLevel(localPlayer, currentLevel());

log.info("Respawned");
}

Expand Down Expand Up @@ -477,6 +488,7 @@ public void onPlayerListUpdate(ClientboundPlayerInfoUpdatePacket packet) {
case UPDATE_LISTED -> () -> entry.setListed(update.isListed());
case UPDATE_LATENCY -> () -> entry.setLatency(update.getLatency());
case UPDATE_DISPLAY_NAME -> () -> entry.setDisplayName(update.getDisplayName());
case UPDATE_HAT -> () -> entry.setShowHat(update.isShowHat());
case UPDATE_LIST_ORDER -> () -> entry.setListOrder(update.getListOrder());
});
}
Expand Down Expand Up @@ -684,7 +696,12 @@ public void onGameEvent(ClientboundGameEventPacket packet) {
case AFFECTED_BY_ELDER_GUARDIAN -> () -> log.debug("Affected by elder guardian");
case ENABLE_RESPAWN_SCREEN -> () -> enableRespawnScreen = packet.getValue() == RespawnScreenValue.ENABLE_RESPAWN_SCREEN;
case LIMITED_CRAFTING -> () -> doLimitedCrafting = packet.getValue() == LimitedCraftingValue.LIMITED_CRAFTING;
case LEVEL_CHUNKS_LOAD_START -> () -> log.debug("Level chunks load start");
case LEVEL_CHUNKS_LOAD_START -> () -> {
log.debug("Level chunks load start");
if (levelLoadStatusManager != null) {
levelLoadStatusManager.loadingPacketsReceived();
}
};
});
}

Expand Down Expand Up @@ -1180,5 +1197,13 @@ private void tickCooldowns() {
}
}
}

if (this.levelLoadStatusManager != null) {
this.levelLoadStatusManager.tick();
if (this.levelLoadStatusManager.levelReady() && !this.localPlayer.hasClientLoaded()) {
this.connection.sendPacket(ServerboundPlayerLoadedPacket.INSTANCE);
this.localPlayer.setClientLoaded(true);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

import com.soulfiremc.server.data.AttributeType;
import com.soulfiremc.server.data.EffectType;
import com.soulfiremc.server.data.EquipmentSlot;
import com.soulfiremc.server.protocol.BotConnection;
import com.soulfiremc.server.protocol.bot.container.SFItemStack;
import com.soulfiremc.server.protocol.bot.state.InputState;
import com.soulfiremc.server.protocol.bot.state.KeyPresses;
import com.soulfiremc.server.protocol.bot.state.Level;
Expand All @@ -40,9 +38,6 @@
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerState;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.*;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

/**
* Represents the bot itself as an entity.
Expand Down Expand Up @@ -85,17 +80,20 @@ public static boolean isAlwaysFlying(GameMode gameMode) {

@Override
public void tick() {
super.tick();
this.tickClientLoadTimeout();
if (this.hasClientLoaded()) {
super.tick();

this.sendShiftKeyState();
this.sendShiftKeyState();

if (!input.keyPresses.equals(this.lastSentInput)) {
this.connection.sendPacket(input.keyPresses.toServerboundPlayerInputPacket());
this.lastSentInput = input.keyPresses;
}
if (!input.keyPresses.equals(this.lastSentInput)) {
this.connection.sendPacket(input.keyPresses.toServerboundPlayerInputPacket());
this.lastSentInput = input.keyPresses;
}

// Send position changes
sendPositionChanges();
// Send position changes
sendPositionChanges();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public abstract class Player extends LivingEntity {
protected final GameProfile gameProfile;
protected boolean wasUnderwater = false;
private boolean reducedDebugInfo;
protected int clientLoadedTimeoutTimer = 60;
private boolean clientLoaded = false;

public Player(Level level, GameProfile gameProfile) {
super(EntityType.PLAYER, level);
Expand Down Expand Up @@ -352,4 +354,21 @@ public int permissionLevel() {
public boolean hasPermissions(int i) {
return this.permissionLevel() >= i;
}

public boolean hasClientLoaded() {
return this.clientLoaded || this.clientLoadedTimeoutTimer <= 0;
}

public void tickClientLoadTimeout() {
if (!this.clientLoaded) {
this.clientLoadedTimeoutTimer--;
}
}

public void setClientLoaded(boolean clientLoaded) {
this.clientLoaded = clientLoaded;
if (!this.clientLoaded) {
this.clientLoadedTimeoutTimer = 60;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
import org.geysermc.mcprotocollib.network.helper.TransportHelper;

public class SFNettyHelper {
public static final TransportHelper.TransportType TRANSPORT_TYPE = TransportHelper.determineTransportMethod();

private SFNettyHelper() {}

public static EventLoopGroup createEventLoopGroup(String name) {
var group =
TRANSPORT_TYPE.eventLoopGroupFactory().apply(
TransportHelper.TRANSPORT_TYPE.eventLoopGroupFactory().apply(
r ->
Thread.ofPlatform().name(name).daemon().priority(Thread.MAX_PRIORITY).unstarted(r));

Expand Down
Loading

0 comments on commit 344b91a

Please sign in to comment.