From 969a532787f314d5f80c2c50be4090780350b02a Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Thu, 15 Jan 2026 21:07:19 +0100 Subject: [PATCH] an attempt was made at understanding how interactions work without any documentation --- .gitignore | 38 ++++++++++ pom.xml | 37 ++++++++++ .../quickerstacker/QuickerStacker.java | 19 +++++ .../interaction/ChestInteraction.java | 69 +++++++++++++++++++ ...uble_QuickerStacker_QuickStackToChest.json | 3 + .../Interactions/Tests/QuickStackToChest.json | 11 +++ ...uble_QuickerStacker_QuickStackToChest.json | 5 ++ src/main/resources/manifest.json | 19 +++++ 8 files changed, 201 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/me/youhavetrouble/quickerstacker/QuickerStacker.java create mode 100644 src/main/java/me/youhavetrouble/quickerstacker/interaction/ChestInteraction.java create mode 100644 src/main/resources/Server/Item/Interactions/Block/YouHaveTrouble_QuickerStacker_QuickStackToChest.json create mode 100644 src/main/resources/Server/Item/Interactions/Tests/QuickStackToChest.json create mode 100644 src/main/resources/Server/Item/RootInteractions/Block/YouHaveTrouble_QuickerStacker_QuickStackToChest.json create mode 100644 src/main/resources/manifest.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..79c6da6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ +.kotlin +libraries/ + + +### IntelliJ IDEA ### +.idea/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..0dc4b27 --- /dev/null +++ b/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + + me.youhavetrouble.quickerstacker + QuickerStacker + 1.0-SNAPSHOT + + + 25 + 25 + UTF-8 + + + + clean package + + + src/main/resources + true + + + + + + + com.hypixel.hytale + HytaleServer-parent + 1.0-SNAPSHOT + system + ${project.basedir}/libraries/HytaleServer.jar + + + + diff --git a/src/main/java/me/youhavetrouble/quickerstacker/QuickerStacker.java b/src/main/java/me/youhavetrouble/quickerstacker/QuickerStacker.java new file mode 100644 index 0000000..09481d1 --- /dev/null +++ b/src/main/java/me/youhavetrouble/quickerstacker/QuickerStacker.java @@ -0,0 +1,19 @@ +package me.youhavetrouble.quickerstacker; + + +import com.hypixel.hytale.server.core.modules.interaction.interaction.config.Interaction; +import com.hypixel.hytale.server.core.plugin.JavaPlugin; +import com.hypixel.hytale.server.core.plugin.JavaPluginInit; +import me.youhavetrouble.quickerstacker.interaction.ChestInteraction; +import org.checkerframework.checker.nullness.compatqual.NonNullDecl; + +public class QuickerStacker extends JavaPlugin { + + public QuickerStacker(@NonNullDecl JavaPluginInit init) { + super(init); + + this.getCodecRegistry(Interaction.CODEC).register("YouHaveTrouble_QuickerStacker_QuickStackToChest", ChestInteraction.class, ChestInteraction.CODEC); + + } + +} diff --git a/src/main/java/me/youhavetrouble/quickerstacker/interaction/ChestInteraction.java b/src/main/java/me/youhavetrouble/quickerstacker/interaction/ChestInteraction.java new file mode 100644 index 0000000..0027e5c --- /dev/null +++ b/src/main/java/me/youhavetrouble/quickerstacker/interaction/ChestInteraction.java @@ -0,0 +1,69 @@ +package me.youhavetrouble.quickerstacker.interaction; + + +import com.hypixel.hytale.codec.builder.BuilderCodec; +import com.hypixel.hytale.component.CommandBuffer; +import com.hypixel.hytale.component.Ref; +import com.hypixel.hytale.component.Store; +import com.hypixel.hytale.math.util.ChunkUtil; +import com.hypixel.hytale.math.vector.Vector3i; +import com.hypixel.hytale.protocol.BlockPosition; +import com.hypixel.hytale.protocol.InteractionSyncData; +import com.hypixel.hytale.protocol.InteractionType; +import com.hypixel.hytale.server.core.Message; +import com.hypixel.hytale.server.core.entity.InteractionContext; +import com.hypixel.hytale.server.core.entity.entities.Player; +import com.hypixel.hytale.server.core.inventory.Inventory; +import com.hypixel.hytale.server.core.inventory.ItemStack; +import com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler; +import com.hypixel.hytale.server.core.modules.interaction.interaction.config.SimpleInstantInteraction; +import com.hypixel.hytale.server.core.modules.interaction.interaction.config.client.SimpleBlockInteraction; +import com.hypixel.hytale.server.core.universe.world.World; +import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk; +import com.hypixel.hytale.server.core.universe.world.meta.state.ItemContainerState; +import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; +import com.hypixel.hytale.server.core.util.NotificationUtil; +import org.checkerframework.checker.nullness.compatqual.NonNullDecl; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; + +public class ChestInteraction extends SimpleBlockInteraction { + + public static final BuilderCodec CODEC = BuilderCodec + .builder(ChestInteraction.class, ChestInteraction::new) + .build(); + + @Override + protected void interactWithBlock( + @NonNullDecl World world, + @NonNullDecl CommandBuffer commandBuffer, + @NonNullDecl InteractionType interactionType, + @NonNullDecl InteractionContext interactionContext, + @NullableDecl ItemStack itemStack, + @NonNullDecl Vector3i vector3i, + @NonNullDecl CooldownHandler cooldownHandler + ) { + Ref ref = interactionContext.getEntity(); + Player player = ref.getStore().getComponent(ref, Player.getComponentType()); + if (player == null) return; + NotificationUtil.sendNotification(player.getPlayerRef().getPacketHandler(), "Interaction happened! "+ interactionType.name()); + player.sendMessage(Message.raw("Interaction: " + interactionType.name())); + InteractionSyncData clientState = interactionContext.getClientState(); + if (clientState == null) return; + BlockPosition targetBlockPosition = clientState.blockPosition; + if (targetBlockPosition == null) return; + WorldChunk chunk = world.getChunk(ChunkUtil.indexChunkFromBlock(targetBlockPosition.x, targetBlockPosition.z)); + if (chunk == null) return; + var blockState = chunk.getState(targetBlockPosition.x, targetBlockPosition.y, targetBlockPosition.z); + if (!(blockState instanceof ItemContainerState containerState)) return; + + Inventory playerInventory = player.getInventory(); + if (playerInventory == null) return; + playerInventory.getCombinedHotbarFirst().quickStackTo(containerState.getItemContainer()); + player.sendMessage(Message.raw("Quick stacked items to chest.")); + } + + @Override + protected void simulateInteractWithBlock(@NonNullDecl InteractionType interactionType, @NonNullDecl InteractionContext interactionContext, @NullableDecl ItemStack itemStack, @NonNullDecl World world, @NonNullDecl Vector3i vector3i) { + + } +} diff --git a/src/main/resources/Server/Item/Interactions/Block/YouHaveTrouble_QuickerStacker_QuickStackToChest.json b/src/main/resources/Server/Item/Interactions/Block/YouHaveTrouble_QuickerStacker_QuickStackToChest.json new file mode 100644 index 0000000..e5b4f99 --- /dev/null +++ b/src/main/resources/Server/Item/Interactions/Block/YouHaveTrouble_QuickerStacker_QuickStackToChest.json @@ -0,0 +1,3 @@ +{ + "Type": "YouHaveTrouble_QuickerStacker_QuickStackToChest" +} diff --git a/src/main/resources/Server/Item/Interactions/Tests/QuickStackToChest.json b/src/main/resources/Server/Item/Interactions/Tests/QuickStackToChest.json new file mode 100644 index 0000000..4be151c --- /dev/null +++ b/src/main/resources/Server/Item/Interactions/Tests/QuickStackToChest.json @@ -0,0 +1,11 @@ +{ + "Type": "UseBlock", + "Next": { + "Type": "YouHaveTrouble_QuickerStacker_QuickStackToChest", + "RunTime": 0.5 + }, + "Failed": { + "Type": "Simple", + "RunTime": 0.5 + } +} \ No newline at end of file diff --git a/src/main/resources/Server/Item/RootInteractions/Block/YouHaveTrouble_QuickerStacker_QuickStackToChest.json b/src/main/resources/Server/Item/RootInteractions/Block/YouHaveTrouble_QuickerStacker_QuickStackToChest.json new file mode 100644 index 0000000..3e16fb9 --- /dev/null +++ b/src/main/resources/Server/Item/RootInteractions/Block/YouHaveTrouble_QuickerStacker_QuickStackToChest.json @@ -0,0 +1,5 @@ +{ + "Interactions": [ + "YouHaveTrouble_QuickerStacker_QuickStackToChest" + ] +} diff --git a/src/main/resources/manifest.json b/src/main/resources/manifest.json new file mode 100644 index 0000000..2af80fa --- /dev/null +++ b/src/main/resources/manifest.json @@ -0,0 +1,19 @@ +{ + "Group": "me.youhavetrouble.quickerstacker", + "Name": "QuickerStacker", + "Version": "1.0.0", + "Description": "Quick stack everything!", + "Authors": [ + { + "Name": "YouHaveTrouble", + "Email": "youhavetrouble@youhavetrouble.me", + "Url": "https://yht.one" + } + ], + "ServerVersion": "*", + "Dependencies": {}, + "OptionalDependencies": {}, + "DisabledByDefault": false, + "IncludesAssetPack": false, + "Main": "me.youhavetrouble.quickerstacker.QuickerStacker" +}