diff --git a/src/main/java/me/youhavetrouble/quickerstacker/QuickerStacker.java b/src/main/java/me/youhavetrouble/quickerstacker/QuickerStacker.java index 1036184..0336986 100644 --- a/src/main/java/me/youhavetrouble/quickerstacker/QuickerStacker.java +++ b/src/main/java/me/youhavetrouble/quickerstacker/QuickerStacker.java @@ -1,9 +1,10 @@ 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.system.QuickStackToChestSystem; +import me.youhavetrouble.quickerstacker.interaction.QuickStackToChestInteraction; import org.checkerframework.checker.nullness.compatqual.NonNullDecl; public class QuickerStacker extends JavaPlugin { @@ -13,8 +14,8 @@ public class QuickerStacker extends JavaPlugin { } @Override - public void start() { - this.getEntityStoreRegistry().registerSystem(new QuickStackToChestSystem()); + public void setup() { + this.getCodecRegistry(Interaction.CODEC).register("Yht_QuickerStacker_QuickStackToChest", QuickStackToChestInteraction.class, QuickStackToChestInteraction.CODEC); } } diff --git a/src/main/java/me/youhavetrouble/quickerstacker/interaction/QuickStackToChestInteraction.java b/src/main/java/me/youhavetrouble/quickerstacker/interaction/QuickStackToChestInteraction.java new file mode 100644 index 0000000..f48f321 --- /dev/null +++ b/src/main/java/me/youhavetrouble/quickerstacker/interaction/QuickStackToChestInteraction.java @@ -0,0 +1,57 @@ +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.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.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 QuickStackToChestInteraction extends SimpleBlockInteraction { + + public static final BuilderCodec CODEC = BuilderCodec + .builder(QuickStackToChestInteraction.class, QuickStackToChestInteraction::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 is happening."); + 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()); + NotificationUtil.sendNotification(player.getPlayerRef().getPacketHandler(), "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/java/me/youhavetrouble/quickerstacker/system/QuickStackToChestSystem.java b/src/main/java/me/youhavetrouble/quickerstacker/system/QuickStackToChestSystem.java deleted file mode 100644 index 749bb96..0000000 --- a/src/main/java/me/youhavetrouble/quickerstacker/system/QuickStackToChestSystem.java +++ /dev/null @@ -1,57 +0,0 @@ -package me.youhavetrouble.quickerstacker.system; - -import com.hypixel.hytale.component.ArchetypeChunk; -import com.hypixel.hytale.component.CommandBuffer; -import com.hypixel.hytale.component.Ref; -import com.hypixel.hytale.component.Store; -import com.hypixel.hytale.component.query.Query; -import com.hypixel.hytale.component.system.EntityEventSystem; -import com.hypixel.hytale.math.util.ChunkUtil; -import com.hypixel.hytale.protocol.InteractionType; -import com.hypixel.hytale.server.core.Message; -import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType; -import com.hypixel.hytale.server.core.entity.entities.Player; -import com.hypixel.hytale.server.core.event.events.ecs.UseBlockEvent; -import com.hypixel.hytale.server.core.inventory.Inventory; -import com.hypixel.hytale.server.core.universe.PlayerRef; -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 QuickStackToChestSystem extends EntityEventSystem { - - public QuickStackToChestSystem() { - super(UseBlockEvent.Post.class); - } - - @Override - public void handle(int index, @NonNullDecl ArchetypeChunk archetypeChunk, @NonNullDecl Store store, @NonNullDecl CommandBuffer commandBuffer, @NonNullDecl UseBlockEvent.Post event) { - if (event.getBlockType() != BlockType.EMPTY) return; - if (event.getInteractionType() != InteractionType.Secondary) return; // right click - Ref ref = archetypeChunk.getReferenceTo(index); - Player player = store.getComponent(ref, Player.getComponentType()); - if (player == null) return; - World world = player.getWorld(); - if (world == null) return; - WorldChunk chunk = world.getChunk(ChunkUtil.indexChunkFromBlock(event.getTargetBlock().x, event.getTargetBlock().z)); - if (chunk == null) return; - var blockState = chunk.getState(event.getTargetBlock().x, event.getTargetBlock().y, event.getTargetBlock().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.")); - - NotificationUtil.sendNotification(player.getPlayerRef().getPacketHandler(), "Quick stacked items to chest."); - } - - @NullableDecl - @Override - public Query getQuery() { - return PlayerRef.getComponentType(); - } -} diff --git a/src/main/resources/Server/Item/Interactions/Yht_QuickerStacker_QuickStackToChest.json b/src/main/resources/Server/Item/Interactions/Yht_QuickerStacker_QuickStackToChest.json new file mode 100644 index 0000000..b438da7 --- /dev/null +++ b/src/main/resources/Server/Item/Interactions/Yht_QuickerStacker_QuickStackToChest.json @@ -0,0 +1,3 @@ +{ + "Type": "Yht_QuickerStacker_QuickStackToChest" +} diff --git a/src/main/resources/Server/Item/RootInteractions/Block/Yht_QuickerStacker_QuickStackToChest.json b/src/main/resources/Server/Item/RootInteractions/Block/Yht_QuickerStacker_QuickStackToChest.json new file mode 100644 index 0000000..d3c41aa --- /dev/null +++ b/src/main/resources/Server/Item/RootInteractions/Block/Yht_QuickerStacker_QuickStackToChest.json @@ -0,0 +1,5 @@ +{ + "Interactions": [ + "Yht_QuickerStacker_QuickStackToChest" + ] +} diff --git a/src/main/resources/Server/Item/Unarmed/Interactions/Empty.json b/src/main/resources/Server/Item/Unarmed/Interactions/Empty.json new file mode 100644 index 0000000..2887100 --- /dev/null +++ b/src/main/resources/Server/Item/Unarmed/Interactions/Empty.json @@ -0,0 +1,105 @@ +{ + "Interactions": { + "Wielding": "Double_Jump", + "Primary": { + "Settings": { + "Adventure": { + "Cooldown": { + "Id": "BlockInteraction", + "Cooldown": 0.35 + } + }, + "Creative": { + "AllowSkipChainOnClick": true, + "Cooldown": { + "Id": "BlockInteraction_Creative", + "Cooldown": 0.35, + "ClickBypass": true + } + } + }, + "Interactions": [ + { + "Type": "Simple", + "Next": { + "Type": "UseBlock", + "Failed": "Unarmed_Attack" + } + } + ] + }, + "Use": { + "Settings": { + "Adventure": { + "Cooldown": { + "Id": "BlockInteraction", + "Cooldown": 0.35 + } + }, + "Creative": { + "Cooldown": { + "Id": "BlockInteraction_Creative", + "Cooldown": 0.35, + "ClickBypass": true + } + } + }, + "Interactions": [ + { + "Type": "Simple", + "Effects": { + "ItemAnimationId": "Interact" + }, + "Next": { + "Type": "UseBlock", + "Failed": { + "Type": "UseEntity", + "Failed": { + "Type": "BreakBlock", + "Harvest": true + } + } + } + } + ] + }, + "Pick": { + "Settings": { + "Adventure": { + "Cooldown": { + "Id": "BlockInteraction", + "Cooldown": 0.35 + } + }, + "Creative": { + "Cooldown": { + "Id": "BlockInteraction_Creative", + "Cooldown": 0.35, + "ClickBypass": true + } + } + }, + "Interactions": [ + { + "Type": "Simple", + "Effects": { + "ItemAnimationId": "Interact" + }, + "Next": { + "Type": "PickBlock" + } + } + ] + }, + "Secondary": { + "Interactions": [ + "Yht_QuickerStacker_QuickStackToChest" + ], + "Cooldown": { + "Id": "Yht_QuickerStacker_QuickStack", + "Cooldown": 0.25 + }, + "RequireNewClick": false + } + } +} diff --git a/src/main/resources/manifest.json b/src/main/resources/manifest.json index 2af80fa..e164eaa 100644 --- a/src/main/resources/manifest.json +++ b/src/main/resources/manifest.json @@ -14,6 +14,6 @@ "Dependencies": {}, "OptionalDependencies": {}, "DisabledByDefault": false, - "IncludesAssetPack": false, + "IncludesAssetPack": true, "Main": "me.youhavetrouble.quickerstacker.QuickerStacker" }