mirror of
https://github.com/YouHaveTrouble/QuickerStacker.git
synced 2026-05-11 21:56:55 +00:00
okay, so hear me out... reflection to add interactions
This commit is contained in:
@@ -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.InteractionContext;
|
||||||
import com.hypixel.hytale.server.core.entity.InteractionManager;
|
import com.hypixel.hytale.server.core.entity.InteractionManager;
|
||||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
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.event.events.ecs.UseBlockEvent;
|
||||||
import com.hypixel.hytale.server.core.modules.interaction.InteractionSimulationHandler;
|
import com.hypixel.hytale.server.core.modules.interaction.InteractionSimulationHandler;
|
||||||
import com.hypixel.hytale.server.core.modules.interaction.interaction.config.Interaction;
|
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.plugin.JavaPluginInit;
|
||||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
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.World;
|
||||||
|
import me.youhavetrouble.quickerstacker.interaction.QuickStackInteraction;
|
||||||
import me.youhavetrouble.quickerstacker.interaction.QuickStackToChestInteraction;
|
import me.youhavetrouble.quickerstacker.interaction.QuickStackToChestInteraction;
|
||||||
|
import me.youhavetrouble.quickerstacker.interaction.QuickStackToNearbyChestsInteraction;
|
||||||
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
||||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
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 class QuickerStacker extends JavaPlugin {
|
||||||
|
|
||||||
public QuickerStacker(@NonNullDecl JavaPluginInit init) {
|
public QuickerStacker(@NonNullDecl JavaPluginInit init) {
|
||||||
@@ -27,7 +34,45 @@ public class QuickerStacker extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
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<Object, Object> 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));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"Type": "Yht_QuickerStacker_QuickStackToNearbyChests"
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"Interactions": [
|
||||||
|
"Yht_QuickerStacker_QuickStack"
|
||||||
|
]
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"Interactions": [
|
||||||
|
"Yht_QuickerStacker_QuickStackToNearbyChests"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user