From 0e0ba2e21ecd01ab15c7b27dc4202816d3ab55aa Mon Sep 17 00:00:00 2001 From: Patbox Date: Tue, 5 Nov 2024 20:56:15 +0100 Subject: [PATCH] Fixup test mod to make it joinable --- build.gradle | 4 +- .../xyz/nucleoid/plasmid/test/JankGame.java | 61 +++++++++---------- .../plasmid/test/TestInitializer.java | 7 +-- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/build.gradle b/build.gradle index 48a8afe4..59b351ec 100644 --- a/build.gradle +++ b/build.gradle @@ -110,8 +110,8 @@ dependencies { modCompileOnly('xyz.nucleoid:disguiselib-fabric:1.3.2') modCompileOnly('maven.modrinth:afkdisplay:1.1.0') - modCompileOnly('eu.pb4:polymer-autohost:0.10.1+1.21.3') - modCompileOnly("dev.emi:trinkets:3.7.1") + modCompileOnly("eu.pb4:polymer-autohost:${project.polymer_version}") + modCompileOnly("dev.emi:trinkets:3.10.0") testmodImplementation sourceSets.main.output testmodImplementation sourceSets.client.output diff --git a/src/testmod/java/xyz/nucleoid/plasmid/test/JankGame.java b/src/testmod/java/xyz/nucleoid/plasmid/test/JankGame.java index ff234125..bbbf987e 100644 --- a/src/testmod/java/xyz/nucleoid/plasmid/test/JankGame.java +++ b/src/testmod/java/xyz/nucleoid/plasmid/test/JankGame.java @@ -3,6 +3,7 @@ import eu.pb4.polymer.common.api.PolymerCommonUtils; import eu.pb4.polymer.core.api.entity.PolymerEntityUtils; import eu.pb4.polymer.virtualentity.api.VirtualEntityUtils; +import eu.pb4.sidebars.api.SidebarUtils; import it.unimi.dsi.fastutil.ints.IntList; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; @@ -21,6 +22,9 @@ import net.minecraft.server.network.EntityTrackerEntry; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.PlayerInput; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameMode; import net.minecraft.world.GameRules; @@ -44,15 +48,13 @@ import java.util.function.Consumer; public final class JankGame { - private static ChestBoatEntity FAKE_BOAT = new ChestBoatEntity(EntityType.OAK_CHEST_BOAT, PolymerCommonUtils.getFakeWorld(), () -> Items.OAK_CHEST_BOAT); private static ArmorStandEntity CAMERA = new ArmorStandEntity(PolymerCommonUtils.getFakeWorld(), 0, 80, 0); private volatile static float currentYaw; private volatile static float currentPitch; private volatile static float currentX; private volatile static float currentXOld; private volatile static double currentY; - private volatile static boolean shift; - private volatile static boolean space; + private volatile static PlayerInput input = PlayerInput.DEFAULT; private static double mouseX = 0; private static double mouseY = 0; @@ -105,17 +107,24 @@ private static GameResult startGame(GameSpace gameSpace) { sidebar.setUpdateRate(99999999); Consumer updateSidebar = (player) -> { + var text = Text.empty(); + text.append(Text.literal("^").formatted(input.forward() ? Formatting.GREEN : Formatting.DARK_GRAY)); + text.append(Text.literal("v").formatted(input.backward() ? Formatting.GREEN : Formatting.DARK_GRAY)); + text.append(Text.literal("<").formatted(input.left() ? Formatting.GREEN : Formatting.DARK_GRAY)); + text.append(Text.literal(">").formatted(input.right() ? Formatting.GREEN : Formatting.DARK_GRAY)); + text.append(Text.literal("-").formatted(input.jump() ? Formatting.GREEN : Formatting.DARK_GRAY)); + text.append(Text.literal("_").formatted(input.sneak() ? Formatting.GREEN : Formatting.DARK_GRAY)); + text.append(Text.literal("$").formatted(input.sprint() ? Formatting.GREEN : Formatting.DARK_GRAY)); + sidebar.set(b -> { - b.add(Text.literal(" ")); b.add(Text.literal("YAW: " + currentYaw)); b.add(Text.literal("PITCH: " + currentPitch)); - b.add(Text.literal("X: " + currentX)); - b.add(Text.literal("Y: " + currentY)); - b.add(Text.literal("Space: " + space)); - b.add(Text.literal("Shift: " + shift)); + b.add(Text.literal("Mouse-X: " + currentX)); + b.add(Text.literal("Mouse-Y: " + currentY)); + b.add(text); }); - //SidebarUtils.updateTexts(player.networkHandler, sidebar); + SidebarUtils.updateTexts(player.networkHandler, sidebar); }; var world = gameSpace.getWorlds().iterator().next(); @@ -128,11 +137,9 @@ private static GameResult startGame(GameSpace gameSpace) { world.spawnEntity(mover); activity.listen(GamePlayerEvents.ADD, player -> { - player.networkHandler.sendPacket(FAKE_BOAT.createSpawnPacket(new EntityTrackerEntry(world, FAKE_BOAT, 1, false, player.networkHandler::sendPacket))); player.networkHandler.sendPacket(CAMERA.createSpawnPacket(new EntityTrackerEntry(world, CAMERA, 1, false, player.networkHandler::sendPacket))); - player.networkHandler.sendPacket(new EntityTrackerUpdateS2CPacket(FAKE_BOAT.getId(), FAKE_BOAT.getDataTracker().getChangedEntries())); player.networkHandler.sendPacket(new EntityTrackerUpdateS2CPacket(CAMERA.getId(), CAMERA.getDataTracker().getChangedEntries())); - player.networkHandler.sendPacket(VirtualEntityUtils.createRidePacket(FAKE_BOAT.getId(), IntList.of(player.getId()))); + player.networkHandler.sendPacket(VirtualEntityUtils.createRidePacket(CAMERA.getId(), IntList.of(player.getId()))); player.networkHandler.sendPacket(new SetCameraEntityS2CPacket(CAMERA)); }); @@ -143,16 +150,11 @@ private static GameResult startGame(GameSpace gameSpace) { currentPitch = rot.getPitch(currentPitch); } - updateSidebar.accept(player); - return EventResult.DENY; - } else if (packet instanceof VehicleMoveC2SPacket vehicleMoveC2SPacket) { - currentX = vehicleMoveC2SPacket.getYaw(); - currentY = vehicleMoveC2SPacket.getZ(); updateSidebar.accept(player); return EventResult.DENY; } else if (packet instanceof PlayerInputC2SPacket playerInputC2SPacket) { - space = playerInputC2SPacket.input().jump(); - shift = playerInputC2SPacket.input().sneak(); + input = playerInputC2SPacket.input(); + updateSidebar.accept(player); return EventResult.DENY; } @@ -162,24 +164,19 @@ private static GameResult startGame(GameSpace gameSpace) { var player = gameSpace.getPlayers().iterator().next(); activity.listen(GameActivityEvents.TICK, () -> { - boolean isMoving = Math.abs(currentX) > 9 || (Math.abs(currentX) - Math.abs(currentXOld) > 0 && Math.abs(currentX) > 0.1); - currentXOld = currentX; - - mover.move(MovementType.PLAYER, new Vec3d(isMoving ? -Math.signum(currentX) : 0, space ? 1 : shift ? -1 : 0, currentY > 0.02 ? 1 : currentY < -0.003 ? -1 : 0).multiply(0.1)); + mover.move(MovementType.PLAYER, new Vec3d(input.right() ? -1 : input.left() ? 1 : 0, + input.jump() ? 3 : input.sneak() ? -1 : 0, + input.forward() ? 1 : input.backward() ? -1 : 0).multiply(input.sprint() ? 0.4 : 0.2)); mover.setYaw(currentYaw); - JankGame.mouseX += Math.abs(currentYaw) > 0.1 ? -currentYaw * 0.1 : 0; - JankGame.mouseY += Math.abs(currentPitch) > 0.1 ? -currentPitch * 0.1 : 0; + JankGame.mouseX = MathHelper.clamp(-currentYaw / 90 * 2, -8, 8) + mover.getX(); + JankGame.mouseY = MathHelper.clamp(-currentPitch / 90 * 2, -8, 8) + mover.getZ(); - player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleTypes.FLAME, true, JankGame.mouseX, 65, JankGame.mouseY, 0, 0, 0, 0, 0)); + player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleTypes.FLAME, true, JankGame.mouseX, mover.getY(), JankGame.mouseY, 0, 0, 0, 0, 0)); - player.networkHandler.sendPacket(new EntityTrackerUpdateS2CPacket(FAKE_BOAT.getId(), FAKE_BOAT.getDataTracker().getChangedEntries())); - player.networkHandler.sendPacket(new VehicleMoveS2CPacket(FAKE_BOAT)); - CAMERA.setPos(mover.getX(), 70, mover.getZ()); + CAMERA.setPos(mover.getX(), mover.getY() + 10, mover.getZ()); player.networkHandler.sendPacket(EntityPositionSyncS2CPacket.create(CAMERA)); - player.networkHandler.sendPacket(EntityPositionSyncS2CPacket.create(FAKE_BOAT)); - player.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(FAKE_BOAT)); player.networkHandler.sendPacket(PlayerPositionLookS2CPacket.of(0, new PlayerPosition(Vec3d.ZERO, Vec3d.ZERO, 0, 0f), Set.of())); }); @@ -207,8 +204,6 @@ private static MapTemplate generateMapTemplate(BlockState state) { } static { - FAKE_BOAT.setNoGravity(true); - FAKE_BOAT.setInvisible(true); CAMERA.setNoGravity(true); CAMERA.setMarker(true); CAMERA.setInvisible(true); diff --git a/src/testmod/java/xyz/nucleoid/plasmid/test/TestInitializer.java b/src/testmod/java/xyz/nucleoid/plasmid/test/TestInitializer.java index 8f4d2d4b..dac08ab2 100644 --- a/src/testmod/java/xyz/nucleoid/plasmid/test/TestInitializer.java +++ b/src/testmod/java/xyz/nucleoid/plasmid/test/TestInitializer.java @@ -4,6 +4,7 @@ import eu.pb4.polymer.blocks.api.BlockModelType; import eu.pb4.polymer.blocks.api.BlockResourceCreator; import eu.pb4.polymer.blocks.api.PolymerBlockModel; +import eu.pb4.polymer.core.api.item.PolymerBlockItem; import eu.pb4.polymer.resourcepack.api.ResourcePackCreator; import net.fabricmc.api.ModInitializer; import net.minecraft.block.AbstractBlock; @@ -38,11 +39,9 @@ public class TestInitializer implements ModInitializer { private static final RegistryKey TEST_ITEM_KEY = RegistryKey.of(RegistryKeys.ITEM, id("test_item")); - public static final Item TEST_ITEM = new BlockItem( + public static final Item TEST_ITEM = new PolymerBlockItem( TEST_BLOCK, - new Item.Settings() - .component(DataComponentTypes.ITEM_MODEL, id("chair")) - .registryKey(TEST_ITEM_KEY) + new Item.Settings().registryKey(TEST_ITEM_KEY) ); public static Optional resourcePack;