mirror of
https://github.com/YouHaveTrouble/QuickerStacker.git
synced 2026-05-11 21:56:55 +00:00
go back to interaction and it actually works this time
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
package me.youhavetrouble.quickerstacker;
|
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.JavaPlugin;
|
||||||
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
|
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;
|
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
||||||
|
|
||||||
public class QuickerStacker extends JavaPlugin {
|
public class QuickerStacker extends JavaPlugin {
|
||||||
@@ -13,8 +14,8 @@ public class QuickerStacker extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void setup() {
|
||||||
this.getEntityStoreRegistry().registerSystem(new QuickStackToChestSystem());
|
this.getCodecRegistry(Interaction.CODEC).register("Yht_QuickerStacker_QuickStackToChest", QuickStackToChestInteraction.class, QuickStackToChestInteraction.CODEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+57
@@ -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<QuickStackToChestInteraction> CODEC = BuilderCodec
|
||||||
|
.builder(QuickStackToChestInteraction.class, QuickStackToChestInteraction::new)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void interactWithBlock(@NonNullDecl World world, @NonNullDecl CommandBuffer<EntityStore> commandBuffer, @NonNullDecl InteractionType interactionType, @NonNullDecl InteractionContext interactionContext, @NullableDecl ItemStack itemStack, @NonNullDecl Vector3i vector3i, @NonNullDecl CooldownHandler cooldownHandler) {
|
||||||
|
Ref<EntityStore> 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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<EntityStore, UseBlockEvent.Post> {
|
|
||||||
|
|
||||||
public QuickStackToChestSystem() {
|
|
||||||
super(UseBlockEvent.Post.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(int index, @NonNullDecl ArchetypeChunk<EntityStore> archetypeChunk, @NonNullDecl Store<EntityStore> store, @NonNullDecl CommandBuffer<EntityStore> commandBuffer, @NonNullDecl UseBlockEvent.Post event) {
|
|
||||||
if (event.getBlockType() != BlockType.EMPTY) return;
|
|
||||||
if (event.getInteractionType() != InteractionType.Secondary) return; // right click
|
|
||||||
Ref<EntityStore> 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<EntityStore> getQuery() {
|
|
||||||
return PlayerRef.getComponentType();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"Type": "Yht_QuickerStacker_QuickStackToChest"
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"Interactions": [
|
||||||
|
"Yht_QuickerStacker_QuickStackToChest"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,6 @@
|
|||||||
"Dependencies": {},
|
"Dependencies": {},
|
||||||
"OptionalDependencies": {},
|
"OptionalDependencies": {},
|
||||||
"DisabledByDefault": false,
|
"DisabledByDefault": false,
|
||||||
"IncludesAssetPack": false,
|
"IncludesAssetPack": true,
|
||||||
"Main": "me.youhavetrouble.quickerstacker.QuickerStacker"
|
"Main": "me.youhavetrouble.quickerstacker.QuickerStacker"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user