diff --git a/src/main/java/me/youhavetrouble/quickerstacker/QuickerStacker.java b/src/main/java/me/youhavetrouble/quickerstacker/QuickerStacker.java index be7bbb7..37b1cd5 100644 --- a/src/main/java/me/youhavetrouble/quickerstacker/QuickerStacker.java +++ b/src/main/java/me/youhavetrouble/quickerstacker/QuickerStacker.java @@ -8,6 +8,7 @@ import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType; import com.hypixel.hytale.server.core.entity.InteractionContext; import com.hypixel.hytale.server.core.entity.InteractionManager; import com.hypixel.hytale.server.core.entity.entities.Player; +import com.hypixel.hytale.server.core.event.events.BootEvent; import com.hypixel.hytale.server.core.event.events.ecs.UseBlockEvent; import com.hypixel.hytale.server.core.modules.interaction.InteractionSimulationHandler; import com.hypixel.hytale.server.core.modules.interaction.interaction.config.Interaction; @@ -15,10 +16,16 @@ import com.hypixel.hytale.server.core.plugin.JavaPlugin; import com.hypixel.hytale.server.core.plugin.JavaPluginInit; import com.hypixel.hytale.server.core.universe.PlayerRef; import com.hypixel.hytale.server.core.universe.world.World; +import me.youhavetrouble.quickerstacker.interaction.QuickStackInteraction; import me.youhavetrouble.quickerstacker.interaction.QuickStackToChestInteraction; +import me.youhavetrouble.quickerstacker.interaction.QuickStackToNearbyChestsInteraction; import org.checkerframework.checker.nullness.compatqual.NonNullDecl; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + public class QuickerStacker extends JavaPlugin { public QuickerStacker(@NonNullDecl JavaPluginInit init) { @@ -27,7 +34,45 @@ public class QuickerStacker extends JavaPlugin { @Override public void setup() { - this.getCodecRegistry(Interaction.CODEC).register("Yht_QuickerStacker_QuickStackToChest", QuickStackToChestInteraction.class, QuickStackToChestInteraction.CODEC); + this.getCodecRegistry(Interaction.CODEC) + .register( + "Yht_QuickerStacker_QuickStack", + QuickStackInteraction.class, + QuickStackInteraction.CODEC + ); + this.getCodecRegistry(Interaction.CODEC) + .register( + "Yht_QuickerStacker_QuickStackToChest", + QuickStackToChestInteraction.class, + QuickStackToChestInteraction.CODEC + ); + this.getCodecRegistry(Interaction.CODEC) + .register( + "Yht_QuickerStacker_QuickStackToNearbyChests", + QuickStackToNearbyChestsInteraction.class, + QuickStackToNearbyChestsInteraction.CODEC + ); + + this.getEventRegistry().registerGlobal(BootEvent.class, (event) -> { + for (BlockType block : BlockType.getAssetMap().getAssetMap().values()) { + if (!"Open_Container".equals(block.getInteractions().get(InteractionType.Use))) continue; + try { + Field interactionsField = block.getClass().getDeclaredField("interactions"); + interactionsField.setAccessible(true); + Object interactionsObj = interactionsField.get(block); + if (!(interactionsObj instanceof Map interactionsMap)) continue; + Map modifiableMap = new HashMap<>(interactionsMap); + modifiableMap.put(InteractionType.Secondary, "Yht_QuickerStacker_QuickStack"); + interactionsField.set(block, modifiableMap); + } catch (NoSuchFieldException | IllegalAccessException _) { + System.out.println("Error modifying interactions for block type: " + block.getId()); + continue; + } + System.out.println(block.getId()); + System.out.println(block.getInteractions().get(InteractionType.Secondary)); + } + }); + } /** diff --git a/src/main/resources/Server/Item/Interactions/Yht_QuickerStacker_QuickStack.json b/src/main/resources/Server/Item/Interactions/Yht_QuickerStacker_QuickStack.json new file mode 100644 index 0000000..e15a322 --- /dev/null +++ b/src/main/resources/Server/Item/Interactions/Yht_QuickerStacker_QuickStack.json @@ -0,0 +1,13 @@ +{ + "Type": "Charging", + "DisplayProgress": true, + "Next": { + "0.1": "Yht_QuickerStacker_QuickStackToChest", + "1": "Yht_QuickerStacker_QuickStackToNearbyChests" + }, + "Cooldown": { + "Id": "Yht_QuickerStacker_QuickStack", + "Cooldown": 0.25 + }, + "RequireNewClick": true +} diff --git a/src/main/resources/Server/Item/Interactions/Yht_QuickerStacker_QuickStackToNearbyChests.json b/src/main/resources/Server/Item/Interactions/Yht_QuickerStacker_QuickStackToNearbyChests.json new file mode 100644 index 0000000..aeb5f0a --- /dev/null +++ b/src/main/resources/Server/Item/Interactions/Yht_QuickerStacker_QuickStackToNearbyChests.json @@ -0,0 +1,3 @@ +{ + "Type": "Yht_QuickerStacker_QuickStackToNearbyChests" +} diff --git a/src/main/resources/Server/Item/RootInteractions/Block/Yht_QuickerStacker_QuickStack.json b/src/main/resources/Server/Item/RootInteractions/Block/Yht_QuickerStacker_QuickStack.json new file mode 100644 index 0000000..3ba2bec --- /dev/null +++ b/src/main/resources/Server/Item/RootInteractions/Block/Yht_QuickerStacker_QuickStack.json @@ -0,0 +1,5 @@ +{ + "Interactions": [ + "Yht_QuickerStacker_QuickStack" + ] +} diff --git a/src/main/resources/Server/Item/RootInteractions/Block/Yht_QuickerStacker_QuickStackToNearbyChests.json b/src/main/resources/Server/Item/RootInteractions/Block/Yht_QuickerStacker_QuickStackToNearbyChests.json new file mode 100644 index 0000000..64c2b11 --- /dev/null +++ b/src/main/resources/Server/Item/RootInteractions/Block/Yht_QuickerStacker_QuickStackToNearbyChests.json @@ -0,0 +1,5 @@ +{ + "Interactions": [ + "Yht_QuickerStacker_QuickStackToNearbyChests" + ] +} diff --git a/src/main/resources/Server/Item/Unarmed/Interactions/Empty.json b/src/main/resources/Server/Item/Unarmed/Interactions/Empty.json deleted file mode 100644 index de10644..0000000 --- a/src/main/resources/Server/Item/Unarmed/Interactions/Empty.json +++ /dev/null @@ -1,110 +0,0 @@ -{ - "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": [ - { - "Type": "Yht_QuickerStacker_QuickStackToChest", - "Effects": { - "ItemAnimationId": "Interact" - } - } - ], - "Cooldown": { - "Id": "Yht_QuickerStacker_QuickStack", - "Cooldown": 0.25 - }, - "RequireNewClick": false - } - } -}