From b165299ff6ce86e539f8b45cd256222e292f20ce Mon Sep 17 00:00:00 2001 From: Ghostipedia Date: Thu, 30 May 2024 09:27:48 -0400 Subject: [PATCH 1/4] QTOT init commit --- .../gtceu/compass/nodes/tools/crowbar.json | 2 +- .../assets/gtceu/compass/nodes/tools/hoe.json | 2 +- .../nodes/tools/quarktech_omnitool.json | 15 ++ .../resources/assets/gtceu/lang/en_ud.json | 2 + .../resources/assets/gtceu/lang/en_us.json | 2 + .../resources/assets/gtceu/sounds.json | 9 ++ .../material/properties/ToolProperty.java | 1 + .../gtceu/api/item/tool/GTOmniToolItem.java | 136 ++++++++++++++++++ .../gtceu/api/item/tool/GTToolType.java | 18 +++ .../gtceu/api/item/tool/ToolHelper.java | 3 + .../gtceu/common/data/GTItems.java | 5 + .../gtceu/common/data/GTSoundEntries.java | 1 + .../tool/behavior/ToolModeSwitchBehavior.java | 15 ++ .../recipe/generated/ToolRecipeHandler.java | 3 + .../gtceu/utils/input/KeyBind.java | 1 + .../models/item/tools/omnitool/blade.json | 9 ++ .../models/item/tools/omnitool/cutter.json | 9 ++ .../models/item/tools/omnitool/drill.json | 9 ++ .../item/tools/omnitool/screwdriver.json | 9 ++ .../models/item/tools/omnitool/wrench.json | 9 ++ .../models/item/tools/quarktech_omnitool.json | 41 ++++++ .../item/tools/quarktech_omnitool.png | Bin 0 -> 573 bytes .../blade_quarktech_omnitool_beam.png | Bin 0 -> 248 bytes .../blade_quarktech_omnitool_chassis.png | Bin 0 -> 236 bytes ...ade_quarktech_omnitool_chassis_overlay.png | Bin 0 -> 218 bytes .../cutter_quarktech_omnitool_beam.png | Bin 0 -> 460 bytes .../cutter_quarktech_omnitool_chassis.png | Bin 0 -> 468 bytes ...ter_quarktech_omnitool_chassis_overlay.png | Bin 0 -> 200 bytes .../drill_quarktech_omnitool_beam.png | Bin 0 -> 523 bytes .../drill_quarktech_omnitool_chassis.png | Bin 0 -> 529 bytes ...ill_quarktech_omnitool_chassis_overlay.png | Bin 0 -> 200 bytes .../screwdriver_quarktech_omnitool_beam.png | Bin 0 -> 462 bytes ...screwdriver_quarktech_omnitool_chassis.png | Bin 0 -> 399 bytes ...ver_quarktech_omnitool_chassis_overlay.png | Bin 0 -> 200 bytes .../wrench_both_quarktech_omnitool_beam.png | Bin 0 -> 539 bytes ...wrench_both_quarktech_omnitool_chassis.png | Bin 0 -> 490 bytes ...oth_quarktech_omnitool_chassis_overlay.png | Bin 0 -> 203 bytes .../wrench_fluid_quarktech_omnitool_beam.png | Bin 0 -> 482 bytes ...rench_fluid_quarktech_omnitool_chassis.png | Bin 0 -> 490 bytes ...uid_quarktech_omnitool_chassis_overlay.png | Bin 0 -> 204 bytes .../wrench_item_quarktech_omnitool_beam.png | Bin 0 -> 526 bytes ...wrench_item_quarktech_omnitool_chassis.png | Bin 0 -> 490 bytes ...tem_quarktech_omnitool_chassis_overlay.png | Bin 0 -> 203 bytes 43 files changed, 299 insertions(+), 2 deletions(-) create mode 100644 src/generated/resources/assets/gtceu/compass/nodes/tools/quarktech_omnitool.json create mode 100644 src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java create mode 100644 src/main/resources/assets/gtceu/models/item/tools/omnitool/blade.json create mode 100644 src/main/resources/assets/gtceu/models/item/tools/omnitool/cutter.json create mode 100644 src/main/resources/assets/gtceu/models/item/tools/omnitool/drill.json create mode 100644 src/main/resources/assets/gtceu/models/item/tools/omnitool/screwdriver.json create mode 100644 src/main/resources/assets/gtceu/models/item/tools/omnitool/wrench.json create mode 100644 src/main/resources/assets/gtceu/models/item/tools/quarktech_omnitool.json create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/blade_quarktech_omnitool_beam.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/blade_quarktech_omnitool_chassis.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/blade_quarktech_omnitool_chassis_overlay.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/cutter_quarktech_omnitool_beam.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/cutter_quarktech_omnitool_chassis.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/cutter_quarktech_omnitool_chassis_overlay.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/drill_quarktech_omnitool_beam.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/drill_quarktech_omnitool_chassis.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/drill_quarktech_omnitool_chassis_overlay.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/screwdriver_quarktech_omnitool_beam.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/screwdriver_quarktech_omnitool_chassis.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/screwdriver_quarktech_omnitool_chassis_overlay.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_both_quarktech_omnitool_beam.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_both_quarktech_omnitool_chassis.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_both_quarktech_omnitool_chassis_overlay.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_fluid_quarktech_omnitool_beam.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_fluid_quarktech_omnitool_chassis.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_fluid_quarktech_omnitool_chassis_overlay.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_item_quarktech_omnitool_beam.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_item_quarktech_omnitool_chassis.png create mode 100644 src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_item_quarktech_omnitool_chassis_overlay.png diff --git a/src/generated/resources/assets/gtceu/compass/nodes/tools/crowbar.json b/src/generated/resources/assets/gtceu/compass/nodes/tools/crowbar.json index 052539c158..f7bea633eb 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/tools/crowbar.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/tools/crowbar.json @@ -8,7 +8,7 @@ ], "page": "gtceu:tools/crowbar", "position": [ - -250, + -200, 250 ], "section": "gtceu:tools" diff --git a/src/generated/resources/assets/gtceu/compass/nodes/tools/hoe.json b/src/generated/resources/assets/gtceu/compass/nodes/tools/hoe.json index 24cdb670b7..fc69f28c24 100644 --- a/src/generated/resources/assets/gtceu/compass/nodes/tools/hoe.json +++ b/src/generated/resources/assets/gtceu/compass/nodes/tools/hoe.json @@ -8,7 +8,7 @@ ], "page": "gtceu:tools/hoe", "position": [ - -200, + -150, 250 ], "section": "gtceu:tools" diff --git a/src/generated/resources/assets/gtceu/compass/nodes/tools/quarktech_omnitool.json b/src/generated/resources/assets/gtceu/compass/nodes/tools/quarktech_omnitool.json new file mode 100644 index 0000000000..ad450108e8 --- /dev/null +++ b/src/generated/resources/assets/gtceu/compass/nodes/tools/quarktech_omnitool.json @@ -0,0 +1,15 @@ +{ + "button_texture": { + "type": "item", + "res": "gtceu:aluminium_quarktech_omnitool" + }, + "items": [ + "#forge:tools/quarktech_omnitools" + ], + "page": "gtceu:tools/quarktech_omnitool", + "position": [ + -250, + 250 + ], + "section": "gtceu:tools" +} \ No newline at end of file diff --git a/src/generated/resources/assets/gtceu/lang/en_ud.json b/src/generated/resources/assets/gtceu/lang/en_ud.json index 95a1367291..8ec4ddf8f3 100644 --- a/src/generated/resources/assets/gtceu/lang/en_ud.json +++ b/src/generated/resources/assets/gtceu/lang/en_ud.json @@ -1977,6 +1977,7 @@ "compass.node.gtceu.tools/plunger": "ɹǝbunןԀ", "compass.node.gtceu.tools/portable_debug_scanner": "ɹǝuuɐɔS bnqǝᗡ ǝןqɐʇɹoԀ", "compass.node.gtceu.tools/portable_scanner": "ɹǝuuɐɔS ǝןqɐʇɹoԀ", + "compass.node.gtceu.tools/quarktech_omnitool": "ןooʇıuɯO ɥɔǝʇʞɹɐnὉ", "compass.node.gtceu.tools/saw": "ʍɐS", "compass.node.gtceu.tools/screwdriver": "ɹǝʌıɹpʍǝɹɔS", "compass.node.gtceu.tools/scythe": "ǝɥʇʎɔS", @@ -4516,6 +4517,7 @@ "item.gtceu.tool.pickaxe": "ǝxɐʞɔıԀ %s", "item.gtceu.tool.plunger": "ɹǝbunןԀ %s", "item.gtceu.tool.plunger.tooltip": "sǝuıɥɔɐW ɯoɹɟ spınןℲ sǝʌoɯǝᴚ8§", + "item.gtceu.tool.quarktech_omnitool": "ןooʇıuɯO ɥɔǝʇʞɹɐnὉ", "item.gtceu.tool.replace_tool_head": "ʇı ǝɔɐןdǝɹ oʇ pɐǝH ןoo⟘ ʍǝu ɐ ɥʇıʍ ʇɟɐɹƆ", "item.gtceu.tool.rolling_pin": "uıԀ buıןןoᴚ %s", "item.gtceu.tool.saw": "ʍɐS %s", diff --git a/src/generated/resources/assets/gtceu/lang/en_us.json b/src/generated/resources/assets/gtceu/lang/en_us.json index 3be48efe2d..8f5629b826 100644 --- a/src/generated/resources/assets/gtceu/lang/en_us.json +++ b/src/generated/resources/assets/gtceu/lang/en_us.json @@ -1977,6 +1977,7 @@ "compass.node.gtceu.tools/plunger": "Plunger", "compass.node.gtceu.tools/portable_debug_scanner": "Portable Debug Scanner", "compass.node.gtceu.tools/portable_scanner": "Portable Scanner", + "compass.node.gtceu.tools/quarktech_omnitool": "Quarktech Omnitool", "compass.node.gtceu.tools/saw": "Saw", "compass.node.gtceu.tools/screwdriver": "Screwdriver", "compass.node.gtceu.tools/scythe": "Scythe", @@ -4516,6 +4517,7 @@ "item.gtceu.tool.pickaxe": "%s Pickaxe", "item.gtceu.tool.plunger": "%s Plunger", "item.gtceu.tool.plunger.tooltip": "§8Removes Fluids from Machines", + "item.gtceu.tool.quarktech_omnitool": "Quarktech Omnitool", "item.gtceu.tool.replace_tool_head": "Craft with a new Tool Head to replace it", "item.gtceu.tool.rolling_pin": "%s Rolling Pin", "item.gtceu.tool.saw": "%s Saw", diff --git a/src/generated/resources/assets/gtceu/sounds.json b/src/generated/resources/assets/gtceu/sounds.json index 9318d8e902..617938813f 100644 --- a/src/generated/resources/assets/gtceu/sounds.json +++ b/src/generated/resources/assets/gtceu/sounds.json @@ -260,6 +260,15 @@ ], "subtitle": "gtceu.subtitle.portal_opening" }, + "quarktech_tool": { + "sounds": [ + { + "type": "file", + "name": "gtceu:quarktech_tool" + } + ], + "subtitle": "gtceu.subtitle.quarktech_tool" + }, "replicator": { "sounds": [ { diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/ToolProperty.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/ToolProperty.java index 3d5c5e5f46..9aa77ec4d6 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/ToolProperty.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/ToolProperty.java @@ -202,6 +202,7 @@ public static Builder of(float harvestSpeed, float attackDamage, int durability, WRENCH_IV, BUZZSAW, SCREWDRIVER_LV, + QUARKTECH_OMNITOOL }); } diff --git a/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java b/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java new file mode 100644 index 0000000000..5f1ddc60ab --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java @@ -0,0 +1,136 @@ +package com.gregtechceu.gtceu.api.item.tool; + +import appeng.util.Platform; +import com.gregtechceu.gtceu.GTCEu; +import com.gregtechceu.gtceu.api.data.chemical.material.Material; +import com.gregtechceu.gtceu.api.gui.GuiTextures; +import com.gregtechceu.gtceu.api.item.IGTTool; +import com.gregtechceu.gtceu.api.item.tool.aoe.AoESymmetrical; +import com.gregtechceu.gtceu.client.renderer.item.ToolItemRenderer; +import com.gregtechceu.gtceu.common.item.tool.behavior.ToolModeSwitchBehavior; +import com.gregtechceu.gtceu.utils.input.KeyBind; +import com.lowdragmc.lowdraglib.LDLib; +import com.lowdragmc.lowdraglib.gui.factory.HeldItemUIFactory; +import com.lowdragmc.lowdraglib.gui.modular.ModularUI; +import com.lowdragmc.lowdraglib.gui.texture.TextTexture; +import com.lowdragmc.lowdraglib.gui.widget.ButtonWidget; +import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; +import lombok.Getter; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.client.renderer.item.ItemProperties; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraftforge.common.capabilities.ICapabilityProvider; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.ParametersAreNonnullByDefault; +import javax.naming.ldap.LdapContext; + +import static com.gregtechceu.gtceu.api.item.tool.ToolHelper.getBehaviorsTag; +import static com.gregtechceu.gtceu.api.item.tool.ToolHelper.getMaxAoEDefinition; +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +public class GTOmniToolItem extends GTToolItem implements IGTTool { + @Getter + private final GTToolType toolType; + @Getter + private final Material material; + @Getter + private final int electricTier; + @Getter + private final IGTToolDefinition omniToolStats; + + protected GTOmniToolItem(GTToolType toolType, MaterialToolTier tier, Material material, IGTToolDefinition toolStats, Properties properties) { + super(toolType, tier, material ,toolStats, properties); + this.material = material; + this.toolType = toolType; + this.electricTier = toolType.electricTier; + this.omniToolStats = toolStats; + if (Platform.isClient()){ + ToolItemRenderer.create(this,toolType); + } + definition$init(); + if(LDLib.isClient()){ + ItemProperties.register(this, GTCEu.id("omnitool"), (itemStack, c, l, i) -> { + if (ToolHelper.hasBehaviorsTag(itemStack)) { + CompoundTag behaviors = ToolHelper.getBehaviorsTag(itemStack); + return (float) behaviors.getByte("OmniToolMode"); + } + return 0; + }); + } + } + public static GTOmniToolItem create(GTToolType toolType, MaterialToolTier tier, Material material, IGTToolDefinition toolStats, Item.Properties properties){ + return new GTOmniToolItem(toolType, tier, material, toolStats, properties); + } + + @Override + public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) { + super.inventoryTick(stack, level, entity, slotId, isSelected); + if (entity instanceof Player player && KeyBind.QUARK_TOOL_MODE_SWITCH.isKeyDown(player)){ + var tagCompound = getBehaviorsTag(stack); + tagCompound.putByte("OmniToolMode", (byte) ((tagCompound.getByte("OmniToolMode") + 1) % ToolModeSwitchBehavior.OmniModeType.values().length)); + player.displayClientMessage(Component.translatable("metaitem.machine_configuration.mode", ToolModeSwitchBehavior.OmniModeType.values()[tagCompound.getByte("OmniToolMode")].getName()), true); + } + } + + @Override + public ItemStack getDefaultInstance() { + return get(); + } + @Override + public @Nullable ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) { + return definition$initCapabilities(stack, nbt); + } + + @Override + public InteractionResultHolder use(Level level, Player player, InteractionHand usedHand) { + return super.use(level, player, usedHand); + } + @Override + public ModularUI createUI(Player entityPlayer, HeldItemUIFactory.HeldItemHolder holder) { + CompoundTag tag = getBehaviorsTag(holder.getHeld()); + AoESymmetrical defaultDefinition = getMaxAoEDefinition(holder.getHeld()); + return new ModularUI(450, 300, holder, entityPlayer).background(GuiTextures.BACKGROUND) + .widget(new LabelWidget(6, 10, "FUCK")) + .widget(new LabelWidget(49, 10, "SHIT")) + .widget(new LabelWidget(79, 10, "PISS")) + .widget(new ButtonWidget(15, 24, 20, 20, new TextTexture("+"), (data) -> { + AoESymmetrical.increaseColumn(tag, defaultDefinition); + holder.markAsDirty(); + })) + .widget(new ButtonWidget(15, 44, 20, 20, new TextTexture("-"), (data) -> { + AoESymmetrical.decreaseColumn(tag, defaultDefinition); + holder.markAsDirty(); + })) + .widget(new ButtonWidget(50, 24, 20, 20, new TextTexture("+"), (data) -> { + AoESymmetrical.increaseRow(tag, defaultDefinition); + holder.markAsDirty(); + })) + .widget(new ButtonWidget(50, 44, 20, 20, new TextTexture("-"), (data) -> { + AoESymmetrical.decreaseRow(tag, defaultDefinition); + holder.markAsDirty(); + })) + .widget(new ButtonWidget(85, 24, 20, 20, new TextTexture("+"), (data) -> { + AoESymmetrical.increaseLayer(tag, defaultDefinition); + holder.markAsDirty(); + })) + .widget(new ButtonWidget(85, 44, 20, 20, new TextTexture("-"), (data) -> { + AoESymmetrical.decreaseLayer(tag, defaultDefinition); + holder.markAsDirty(); + })) + .widget(new LabelWidget(23, 65, () -> + Integer.toString(1 + 2 * AoESymmetrical.getColumn(getBehaviorsTag(holder.getHeld()), defaultDefinition)))) + .widget(new LabelWidget(58, 65, () -> + Integer.toString(1 + 2 * AoESymmetrical.getRow(getBehaviorsTag(holder.getHeld()), defaultDefinition)))) + .widget(new LabelWidget(93, 65, () -> + Integer.toString(1 + AoESymmetrical.getLayer(getBehaviorsTag(holder.getHeld()), defaultDefinition)))); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTToolType.java b/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTToolType.java index be5eae6299..58ccaddca9 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTToolType.java +++ b/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTToolType.java @@ -5,8 +5,10 @@ import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.data.tag.TagUtil; import com.gregtechceu.gtceu.api.item.IGTTool; +import com.gregtechceu.gtceu.api.item.component.ElectricStats; import com.gregtechceu.gtceu.api.sound.ExistingSoundEntry; import com.gregtechceu.gtceu.api.sound.SoundEntry; +import com.gregtechceu.gtceu.common.data.GTItems; import com.gregtechceu.gtceu.common.data.GTSoundEntries; import com.gregtechceu.gtceu.common.item.tool.behavior.*; @@ -151,6 +153,22 @@ public class GTToolType { .sound(GTSoundEntries.WRENCH_TOOL) .symbol('w') .build(); + public static final GTToolType QUARKTECH_OMNITOOL = GTToolType.builder("quarktech_omnitool") + //TODO: Custom Mode Swapping Behavior + .toolTag(TagUtil.createItemTag("tools/quarktech_omnitools", false)) + .toolTag(TagUtil.createItemTag("tools/quarktech_omnitool", false)) + .harvestTag(TagUtil.createBlockTag("mineable/wrench", false)) + .harvestTag(TagUtil.createBlockTag("mineable/wire_cutter", false)) + .harvestTag(TagUtil.createBlockTag("mineable/axe", true)) + .harvestTag(TagUtil.createBlockTag("mineable/pickaxe", true)) + .harvestTag(TagUtil.createBlockTag("mineable/hoe", true)) + .harvestTag(TagUtil.createBlockTag("mineable/shovel", true)) + .toolStats(b -> b.blockBreaking().aoe(5, 5, 5) + .attackDamage(1.0F).attackSpeed(1.0F)) + .sound(GTSoundEntries.QUARKTECH_TOOL) + .constructor(GTOmniToolItem::create) +// .modelLocation(GTItems.modelPredicate(GTCEu.id("omnitool"),ToolModeSwitchBehavior::getStoredPredicate)) + .build(); public static final GTToolType FILE = GTToolType.builder("file") .toolTag(TagUtil.createItemTag("tools/files", false)) .toolStats(b -> b.crafting().damagePerCraftingAction(4) diff --git a/src/main/java/com/gregtechceu/gtceu/api/item/tool/ToolHelper.java b/src/main/java/com/gregtechceu/gtceu/api/item/tool/ToolHelper.java index fe2f488335..2e8146e52b 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/item/tool/ToolHelper.java +++ b/src/main/java/com/gregtechceu/gtceu/api/item/tool/ToolHelper.java @@ -523,6 +523,9 @@ public static boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, Playe public static boolean removeBlockRoutine(@Nullable BlockState state, Level world, ServerPlayer player, BlockPos pos, boolean playSound) { state = state == null ? world.getBlockState(pos) : state; + if (state.isAir()) { + return true; + } state.getBlock().playerWillDestroy(world, pos, state, player); boolean successful = world.removeBlock(pos, false); diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTItems.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTItems.java index 545fb2009e..ff6b7ffa65 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTItems.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTItems.java @@ -25,6 +25,7 @@ import com.gregtechceu.gtceu.api.item.TagPrefixItem; import com.gregtechceu.gtceu.api.item.armor.ArmorComponentItem; import com.gregtechceu.gtceu.api.item.component.*; +import com.gregtechceu.gtceu.api.item.tool.GTToolItem; import com.gregtechceu.gtceu.api.item.tool.GTToolType; import com.gregtechceu.gtceu.api.item.tool.MaterialToolTier; import com.gregtechceu.gtceu.api.registry.registrate.CompassNode; @@ -33,6 +34,9 @@ import com.gregtechceu.gtceu.common.data.materials.GTFoods; import com.gregtechceu.gtceu.common.item.*; import com.gregtechceu.gtceu.common.item.armor.*; +import com.gregtechceu.gtceu.common.item.tool.behavior.BlockRotatingBehavior; +import com.gregtechceu.gtceu.common.item.tool.behavior.EntityDamageBehavior; +import com.gregtechceu.gtceu.common.item.tool.behavior.ToolModeSwitchBehavior; import com.gregtechceu.gtceu.config.ConfigHolder; import com.gregtechceu.gtceu.data.lang.LangHandler; import com.gregtechceu.gtceu.data.recipe.CustomTags; @@ -51,6 +55,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.stats.Stats; import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.animal.IronGolem; import net.minecraft.world.item.*; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.LayeredCauldronBlock; diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTSoundEntries.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTSoundEntries.java index 58e2efa6cb..bc87fc081f 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTSoundEntries.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTSoundEntries.java @@ -55,6 +55,7 @@ public class GTSoundEntries { public static final SoundEntry SCREWDRIVER_TOOL = REGISTRATE.sound("screwdriver").build(); public static final SoundEntry CHAINSAW_TOOL = REGISTRATE.sound("chainsaw").build(); public static final SoundEntry WIRECUTTER_TOOL = REGISTRATE.sound("wirecutter").build(); + public static final SoundEntry QUARKTECH_TOOL = REGISTRATE.sound("quarktech_tool").build(); public static final SoundEntry SPRAY_CAN_TOOL = REGISTRATE.sound("spray_can").build(); public static final SoundEntry PORTABLE_SCANNER = REGISTRATE.sound("portable_scanner").build(); public static final SoundEntry MORTAR_TOOL = REGISTRATE.sound("mortar").build(); diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/tool/behavior/ToolModeSwitchBehavior.java b/src/main/java/com/gregtechceu/gtceu/common/item/tool/behavior/ToolModeSwitchBehavior.java index 91573808dd..e0dc50330c 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/tool/behavior/ToolModeSwitchBehavior.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/tool/behavior/ToolModeSwitchBehavior.java @@ -1,5 +1,6 @@ package com.gregtechceu.gtceu.common.item.tool.behavior; +import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper; import com.gregtechceu.gtceu.api.item.tool.behavior.IToolBehavior; import net.minecraft.nbt.CompoundTag; @@ -68,4 +69,18 @@ private ModeType(Component name) { this.name = name; } } + public static enum OmniModeType { + DRILL(Component.translatable("gtceu.mode.drill")), + CUTTER(Component.translatable("gtceu.mode.cutter")), + WRENCH(Component.translatable("gtceu.mode.wrench")), + SCREWDRIVER(Component.translatable("gtceu.mode.screwdriver")), + BLADE(Component.translatable("gtceu.mode.blade")); + + @Getter + private final Component name; + + private OmniModeType(Component name) { + this.name = name; + } + } } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/ToolRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/ToolRecipeHandler.java index 564b1daa5a..0e7da49b26 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/ToolRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/ToolRecipeHandler.java @@ -208,6 +208,9 @@ private static void processTool(TagPrefix prefix, Material material, ToolPropert addToolRecipe(provider, material, GTToolType.WRENCH, false, "PhP", " P ", " P ", 'P', plate); + addToolRecipe(provider, material, GTToolType.QUARKTECH_OMNITOOL, false, + "PhP", " P ", " P ", + 'P', plate); } if (material.hasFlag(GENERATE_ROD)) { diff --git a/src/main/java/com/gregtechceu/gtceu/utils/input/KeyBind.java b/src/main/java/com/gregtechceu/gtceu/utils/input/KeyBind.java index dff0636290..f78420a319 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/input/KeyBind.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/input/KeyBind.java @@ -38,6 +38,7 @@ public enum KeyBind { ARMOR_MODE_SWITCH("gtceu.key.armor_mode_switch", KeyConflictContext.IN_GAME, InputConstants.KEY_M), ARMOR_HOVER("gtceu.key.armor_hover", KeyConflictContext.IN_GAME, InputConstants.KEY_H), ARMOR_CHARGING("gtceu.key.armor_charging", KeyConflictContext.IN_GAME, InputConstants.KEY_N), + QUARK_TOOL_MODE_SWITCH("gtceu.key.quarktool_mode_switch", KeyConflictContext.IN_GAME, InputConstants.KEY_R), TOOL_AOE_CHANGE("gtceu.key.tool_aoe_change", KeyConflictContext.IN_GAME, InputConstants.KEY_V); public static final KeyBind[] VALUES = values(); diff --git a/src/main/resources/assets/gtceu/models/item/tools/omnitool/blade.json b/src/main/resources/assets/gtceu/models/item/tools/omnitool/blade.json new file mode 100644 index 0000000000..02e5ce9c9f --- /dev/null +++ b/src/main/resources/assets/gtceu/models/item/tools/omnitool/blade.json @@ -0,0 +1,9 @@ +{ + "parent": "item/handheld", + "textures": { + "layer0": "gtceu:item/tools/quarktech_omnitool/blade_quarktech_omnitool_chassis", + "layer1": "gtceu:item/tools/quarktech_omnitool/blade_quarktech_omnitool_chassis_overlay", + "layer2": "gtceu:item/tools/quarktech_omnitool/blade_quarktech_omnitool_chassis_overlay", + "layer3": "gtceu:item/tools/quarktech_omnitool/blade_quarktech_omnitool_beam" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/gtceu/models/item/tools/omnitool/cutter.json b/src/main/resources/assets/gtceu/models/item/tools/omnitool/cutter.json new file mode 100644 index 0000000000..ccbe18a8e1 --- /dev/null +++ b/src/main/resources/assets/gtceu/models/item/tools/omnitool/cutter.json @@ -0,0 +1,9 @@ +{ + "parent": "item/handheld", + "textures": { + "layer0": "gtceu:item/tools/quarktech_omnitool/cutter_quarktech_omnitool_chassis", + "layer1": "gtceu:item/tools/quarktech_omnitool/cutter_quarktech_omnitool_chassis_overlay", + "layer2": "gtceu:item/tools/quarktech_omnitool/cutter_quarktech_omnitool_chassis_overlay", + "layer3": "gtceu:item/tools/quarktech_omnitool/cutter_quarktech_omnitool_beam" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/gtceu/models/item/tools/omnitool/drill.json b/src/main/resources/assets/gtceu/models/item/tools/omnitool/drill.json new file mode 100644 index 0000000000..047f459265 --- /dev/null +++ b/src/main/resources/assets/gtceu/models/item/tools/omnitool/drill.json @@ -0,0 +1,9 @@ +{ + "parent": "item/handheld", + "textures": { + "layer0": "gtceu:item/tools/quarktech_omnitool/drill_quarktech_omnitool_chassis", + "layer1": "gtceu:item/tools/quarktech_omnitool/drill_quarktech_omnitool_chassis_overlay", + "layer2": "gtceu:item/tools/quarktech_omnitool/drill_quarktech_omnitool_chassis_overlay", + "layer3": "gtceu:item/tools/quarktech_omnitool/drill_quarktech_omnitool_beam" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/gtceu/models/item/tools/omnitool/screwdriver.json b/src/main/resources/assets/gtceu/models/item/tools/omnitool/screwdriver.json new file mode 100644 index 0000000000..4faaabdd41 --- /dev/null +++ b/src/main/resources/assets/gtceu/models/item/tools/omnitool/screwdriver.json @@ -0,0 +1,9 @@ +{ + "parent": "item/handheld", + "textures": { + "layer0": "gtceu:item/tools/quarktech_omnitool/screwdriver_quarktech_omnitool_chassis", + "layer1": "gtceu:item/tools/quarktech_omnitool/screwdriver_quarktech_omnitool_chassis_overlay", + "layer2": "gtceu:item/tools/quarktech_omnitool/screwdriver_quarktech_omnitool_chassis_overlay", + "layer3": "gtceu:item/tools/quarktech_omnitool/screwdriver_quarktech_omnitool_beam" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/gtceu/models/item/tools/omnitool/wrench.json b/src/main/resources/assets/gtceu/models/item/tools/omnitool/wrench.json new file mode 100644 index 0000000000..ffa652d507 --- /dev/null +++ b/src/main/resources/assets/gtceu/models/item/tools/omnitool/wrench.json @@ -0,0 +1,9 @@ +{ + "parent": "item/handheld", + "textures": { + "layer0": "gtceu:item/tools/quarktech_omnitool/wrench_both_quarktech_omnitool_chassis", + "layer1": "gtceu:item/tools/quarktech_omnitool/wrench_both_quarktech_omnitool_chassis_overlay", + "layer2": "gtceu:item/tools/quarktech_omnitool/wrench_both_quarktech_omnitool_chassis_overlay", + "layer3": "gtceu:item/tools/quarktech_omnitool/wrench_both_quarktech_omnitool_beam" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/gtceu/models/item/tools/quarktech_omnitool.json b/src/main/resources/assets/gtceu/models/item/tools/quarktech_omnitool.json new file mode 100644 index 0000000000..2bd5e4f1e0 --- /dev/null +++ b/src/main/resources/assets/gtceu/models/item/tools/quarktech_omnitool.json @@ -0,0 +1,41 @@ +{ + "parent": "minecraft:item/generated", + "overrides": [ + { + "model": "gtceu:item/tools/omnitool/drill", + "predicate": { + "gtceu:omnitool": 0.0 + } + }, + { + "model": "gtceu:item/tools/omnitool/cutter", + "predicate": { + "gtceu:omnitool": 1.0 + } + }, + { + "model": "gtceu:item/tools/omnitool/wrench", + "predicate": { + "gtceu:omnitool": 2.0 + } + }, + { + "model": "gtceu:item/tools/omnitool/screwdriver", + "predicate": { + "gtceu:omnitool": 3.0 + } + }, + { + "model": "gtceu:item/tools/omnitool/blade", + "predicate": { + "gtceu:omnitool": 4.0 + } + } + ], + "textures": { + "layer0": "gtceu:item/tools/quarktech_omnitool/drill_quarktech_omnitool_chassis", + "layer1": "gtceu:item/tools/quarktech_omnitool/drill_quarktech_omnitool_chassis_overlay", + "layer2": "gtceu:item/tools/quarktech_omnitool/drill_quarktech_omnitool_chassis_overlay", + "layer3": "gtceu:item/tools/quarktech_omnitool/drill_quarktech_omnitool_beam" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool.png b/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool.png new file mode 100644 index 0000000000000000000000000000000000000000..e0a773515d7b91e2e8c41ba660c6d27f9153f089 GIT binary patch literal 573 zcmV-D0>b@?P)Llg~?3Q545NXGqkAt_*@&bgz@z>b(ZsD1s18i`oT2 zgKk_4^?$SqX6;6s`Wpn90h=}hgV3U!A1{Rwf_Be^1^K=$ru&@1T6N&Uy_|bL=X-u! zlf?g60pKj#R6`~J@4dYDW7M;3^Pd2dL_?;5!5zW6$pR=`N|M9^=yqXuoFEBF)HAdz zB#FW0hU(dHA4QRzb8^lFU;akY5D=V_7=cjFpq@b#MGEUrupBf77+h{BKmx!yr=ZR` zr=VyI5FkPJ;BtfdFOzdl&z?UH5Asw-6+CZ**CUcaBC-RdY!Q@rrFh@ty73K3%;9;54h{%?q0we;ba0!C`NewPKTMr3}D!ZJ%nT z%t3#SM@t_7=pCP2)gTN>9LGx26d;#bpyVYTOM*RFCy9Vgm9_yx2hy}R^{S_Y0 ze`Ke7!q&aJOwWk>ON*8RLM;Hc=AC9|XRWw+D@0XcB4cvOxHvZs`YSw*o7VwB3BZ%m zCqgO!g^3J+$*JL|yEr$dXGZ2=)Iy7rB+1VK5XVaZeExE*i*w^QM1)=UZ@xLk00000 LNkvXXu0mjfa!~%R literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/blade_quarktech_omnitool_beam.png b/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/blade_quarktech_omnitool_beam.png new file mode 100644 index 0000000000000000000000000000000000000000..55c3a901b8db0bd2c307c5c89c380720b15745ad GIT binary patch literal 248 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkP;ix} zi(`mI@6ySRe1{YST>n3?y|Z)0M}c=fdzkjN+D`h)k>|Om>0L}U_k-OTUW>}24tR1T z8ofXNhrvl`so?fW3c<{?7q>=+bMzR<*>2eEJSpWG7w?J5s{DuLq%KsR6uyw~JoV9c)dR!*%$+~s!T=5B4Sc@J+Hp*0l9jH7g`Pzi<`n$1 u@IT1#g|le!4}Bl*5?%N6OFwRJHMhO3T6UCW>IR^z89ZJ6T-G@yGywpYq+a|0 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/blade_quarktech_omnitool_chassis.png b/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/blade_quarktech_omnitool_chassis.png new file mode 100644 index 0000000000000000000000000000000000000000..7b4be91d23fb8856d1dee91c5e57781a0765adab GIT binary patch literal 236 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkP;j27 zi(`mI@7+m;d`yNsEXS8;YgD-03HtCqJ>bGD_n5+^njT8RO(})4d5b)5o_weF=$*{W zrxSkJGi2Xck(C|7a7O2Sf=GILk3vIwzC5F^PQ&U~{(O&?D99$H%{k{+FtMrRz|*Lj z`z*%YfmL$?KB+5ogQQycQ{RHSP N22WQ%mvv4FO#nnJO*Q}k literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/cutter_quarktech_omnitool_beam.png b/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/cutter_quarktech_omnitool_beam.png new file mode 100644 index 0000000000000000000000000000000000000000..da6b2b3a7aecde13632b2ba6250de17d1c55e0cf GIT binary patch literal 460 zcmV;-0WLQ@=|>Q561;^qYFnP>Z15SGhzy5gbFo!9PHFOS;s* z5EL{A3Jv`S4K@W0=A1uoF9RiRaVD@o_CB+!r=xgEQEj%LhI>IvRbVeyiiq{u~se6 z_c%p{VZbm9M59slU@%Zbjma;;7N@k8YH5z%ygG1Q7q07SAW33B004~YLjb@M6V?}= z_+)s@EipJY+>{HDt6BpjBeP8&(n z%OpRDoU>-uqKD-b!sv@o4wd+zc1Qqpfd9nY+xP=zC+O((mm7uv0000LlfOy>K@i5jIq^@5>pkl?%%`XH3vrj>q?F2iHW5#jJywA(mZXsqQ!4r4U{fc0WfiVWw+CVcM9iU4IG(kXB z*&53VLi?9j;+%tXt{~EqVRa)3CMal)W!RgaWpkwt07#NV@_pH8UIPFmKSouhF$O2S zWm&DA69CdQmCfyS_Ac(do1|$90I=4MCRnYVv$;|a!N*6Z;%xv_Rj6vYgnI_1vN`F?W#M0t|gdX_pU6x7~0H`g@vQj0yNVxp{8~qF0XkH^p z5?E{DoI^DJ^T;Nreh~X_f=ZQT0grBs33gt<+C>1s&FvlgZ-Q?d81s!y?QD+#0000< KMNUMnLSTYEM95bF literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/cutter_quarktech_omnitool_chassis_overlay.png b/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/cutter_quarktech_omnitool_chassis_overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..4c1e0ad922c7323b9af44118b444ca2e41b8a3a1 GIT binary patch literal 200 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkP_W9= z#WBR9_wD3^yv+tYuJb3q5z_Qw*qpXD;uPOUHr;ofaSWnUwg0C@{{I=h>FC{^iwjQw zWmw0!Wo347*4lb?fdkVkE%WBxZ8ZCOmdC^6BCE>t8q0&%_lUax+S=42V!P}`GEdd} v-8+^y7>S+=iHOffMQ&=m}xu6{1-oD!MLld)?QK@`S+?}(^{TOBr+W+t#UfjyTjvC&I+A;C%z z5p7~?VPl!f($dD>;Gb|9o8-DAf?Nudi^7Iv6HZMx7D~W-7MmGwg9oAyhMi^h`{w<= znH5##f2s!1FGTx=D1fyVYi;GD+-el(h-8n%0{Jg=$pV}V?Y<92dY->-JpSA_y@$0uN z-*3y-272RWKZG3afj{3e<&rVYVqU&LPkyZ8jo!ce$mJ`_hwc4p21h?11e7F6@U8mc z`8|f$$>`6tt`g2ZilR!|wF^ToUJ|~46Sg*DtzUg36@-7SvG?F_>lgla>w%H!PAUKZ N002ovPDHLkV1m5{?~woi literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/drill_quarktech_omnitool_chassis.png b/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/drill_quarktech_omnitool_chassis.png new file mode 100644 index 0000000000000000000000000000000000000000..2c4fb59c16a7822876255fca70b78247b1d40672 GIT binary patch literal 529 zcmV+s0`C2ZP)Lld)rYd4Ll2*v5eQVqCCj5tW?YM+yG|tJvJ&QD*y{um`3@#a>U9AeOL8jVIa8jZ|*PnxD0G+cRJ z0vq`t^lD!>QSdSL)%tCyF9{Y<^t@tVc*XIy|-jX|`gTt=JYdQJSV82}wBT zlq8AH=HQ%DuisHo6s)h#IXUNW&XFX^(jd=s^WHPuO*ENI?Be{I;laL+4v*~-!R7P? zgNGJHQ4s#t>vz=acXamGN{dFktwy|!q-7gJf73KA``&ED1cTwhz5p)Huc_9=pWm_{ zS3g$)H+D+f^ble}cQTn+mSqZSwI<%}ytT3hVYKLDU!ud^@!?uRD;(sT!aZ{M$UcWe9up>_cF T=R@HV00000NkvXXu0mjf!VdDK literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/drill_quarktech_omnitool_chassis_overlay.png b/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/drill_quarktech_omnitool_chassis_overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..e7408b0bf829c4a6fc8db72e871c3b7414b42243 GIT binary patch literal 200 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkP_W9= z#WBR9_ib=A*I@&m$;tOsFT`42?@}!9$iLwG`&7hB;a|~zIh8qYMtD5pyQKRyx!~-9 z)t6TLlCeqyK@>&rTNJf0m4%>%Z;jDzV<3$p*l0c=V4-Vc zZQ*~|<`0zMHwa+^Y9$C3Hlh(>{ef86WanDMH|%Ou&g4?>r%i|5N|~FK(Y* z3IQMtLxf>iIP~K7zXb?MbSX>)m?y9)6a!iHdOZ)C3r>mzk|2r1fhPn>BF$nZZn%!3 z2&xKI#mAn%LvjePO_In#kT@W5KomuOd^|Q9kY+IrVgOb3>QvP$DgX>(vePU^G7zdN znmY}sD$*>bS;;F1@_B3u#S%YQS`Yv@Y@f4MuVABmCAE45wR#0dtI^jGO`gea?lh2Q zG4pfJ?J*yyw_uWT5HCL&2$O-()}H}mqnaZX;NoGO8|5o$?QVN3t=(y!z;j?SQKsVR-n3^W;Zl8)7*tdOd9vkN0Y}h@o006qfF2=#4 zqEsrOygUngH5hl8m=wId3ObK#R5_J`g}+wt`;njP9cHvP(V{@j+W-In07*qoM6N<$ Ef_hoFQ2+n{ literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/screwdriver_quarktech_omnitool_chassis.png b/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/screwdriver_quarktech_omnitool_chassis.png new file mode 100644 index 0000000000000000000000000000000000000000..ba0e07257e4be817098af34c6d6910d9f3d10177 GIT binary patch literal 399 zcmV;A0dW3_P)LQaesVF%X=6Qk0~KFF=D=Q4*?Wo|KXkaD{LO?!-Y- zQ6ZrxQSd3Y3KwvSRCz;z9Gn+N0x^qx?TPm;*jX1~I^!%@zA&$_PZz2|1X0!biG=9lxB z_nzMSv~%6zP;=r!La!|WKr@qOIg|VA8W+_ARP~r3^>{OVq?t+Y(*yvXpFS94gsOfA za~D*V&N;MgE2_%UuV>2S;6e#zCM9>wOsYYLYS6*VjtSC>X&TQd7><6z#X-u3M*uKa zl=kt2xLVAm*g}jE&N*q8Gc?PY0Kjy9$?=5fD=RAa?Cx;eydaG*091nx05BX00bsWk tj3+D;B#X@Ka83jvEC2wnZ|~e~1z!tI)XLeU4WIx3002ovPDHLkV1mS?rlSA= literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/screwdriver_quarktech_omnitool_chassis_overlay.png b/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/screwdriver_quarktech_omnitool_chassis_overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..e7408b0bf829c4a6fc8db72e871c3b7414b42243 GIT binary patch literal 200 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkP_W9= z#WBR9_ib=A*I@&m$;tOsFT`42?@}!9$iLwG`&7hB;a|~zIh8qYMtD5pyQKRyx!~-9 z)t6TLlD}(HQ545N=V7o8X6Yhm)%#N8_?ke58U>vqb}N!W zTZ9Zw6|(5&KhVXcv-l%qkkGA&E-AvpArRU@hnV*wq45v64qfa$4)#6rqbTZu1DA6z z-*e9AennOJpExyL@O>YE_{nmrJbLKKdGGb_1$I@qDM}p2iI60BQ9Mw5ccPH|X@#Yw zC9JjSR5K!~iZKRNoydcuHQEl^4uT*^(>+Gpj`ZCO1AviRPtUcSA-cP-vH<=wBZc>Y z*p}sZQ#^oj*w+MJ5)0uAt>p~GQl4DP2$_2TSZjG64JIKr`huD2e)+)_0eExqomQ!c zzxh#$r91%jLYBR~u?fb3eUSz?7DI}qJms*j)nP?ix8}82%G0_%uiZ{Bg_;VquX|Ds z`)aMFUI-YxjI`V7aag}2+Z#LTq9y?Db9085H&X#P5Xxa+yPY1ZTPso>R%Cl)N2|k% z#7~#i%eeGu>VuJ6=R){OgGU8PMl6={%x%8a=FqXawITrBPLDHZl~4P}AgBL*?c0$C zL4Yx4BJY27YK%cX{LpdVOgM2@f4R4oGi0+_7O$Qo>FQ-1r{{#j@4~fqq>W1=6D#~{ doDA_V;wK{%Lld*0SK@f(&u|VL$et|T(O=O4aE+@H9hb2m^xQUxQ zL7s@lG?DTE>5N2)ge*}&AS@K|3v7x&k^58FbFt5%;-t~u&fR?b&%e7SiT`<8%|r-6 zA%qR;qMH1hAPGs#s>gRpWLYK;&)wXgZ2TjMtwb~OJl_B{A@yp_!khaOW);jT$n#tt zuGT@%o@#5o=hMARG0x5XDT+cVWqiEGY7=9O)--OXHRW_KQ#t6d{w<}%yPv^W));vrnkqhC5h&^G8B&%zy}#IMoTGi zc9<*1XrDiQXEYw_;{4K@DuKGCCrw=UWi%dcv=U>q{r;{1uCIPC0Y@el)r1(M6-7~> z#B$KX6*wq_pmxXj`)4V_{4Ol22|w&TM<$kAl>p4;x*{Lj9r5a*Z}nZ+X-#oIQc85Y zT`LDY%0bTn_WQePcZ5T{u2#_8#y8~`Rw@8!J+ALk}+!=K@f%C95IoLsC6KQWM%nWo^)`HkF-glP6jtV zV{q+2enxQRLchQfD$^w?&m0^C3<4Kv>=O>*q#qy`Zgl%xh+W@F!hv{TU>RoLes5=l zB%Tv577L9=0{{@FnN|L>aU^e?ud5YEf+S-7cqR#@luaa>(WGErM3o+rSSl>0=Xq9W zm56<9@nT*?h&2#v!1FwtNHoi|D+Tf*vI52e2BcET5>*7ENx^b4FCs`Xqf!cc`yVa7 zu~H^*0HB|V{nW8O1OU7{+7a1zJtO@S#1iSHw{kI|&3;!F=zgwP; Y2Sa~Da3yNcEdT%j07*qoM6N<$f^!qbNdN!< literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_fluid_quarktech_omnitool_chassis.png b/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_fluid_quarktech_omnitool_chassis.png new file mode 100644 index 0000000000000000000000000000000000000000..a7682f1133aaddd306fa74583b51907c0f04eaf8 GIT binary patch literal 490 zcmVLld*0SK@f(&u|VL$et|T(O=O4aE+@H9hb2m^xQUxQ zL7s@lG?DTE>5N2)ge*}&AS@K|3v7x&k^58FbFt5%;-t~u&fR?b&%e7SiT`<8%|r-6 zA%qR;qMH1hAPGs#s>gRpWLYK;&)wXgZ2TjMtwb~OJl_B{A@yp_!khaOW);jT$n#tt zuGT@%o@#5o=hMARG0x5XDT+cVWqiEGY7=9O)--OXHRW_KQ#t6d{w<}%yPv^W));vrnkqhC5h&^G8B&%zy}#IMoTGi zc9<*1XrDiQXEYw_;{4K@DuKGCCrw=UWi%dcv=U>q{r;{1uCIPC0Y@el)r1(M6-7~> z#B$KX6*wq_pmxXj`)4V_{4Ol22|w&TM<$kAl>p4;x*{Lj9r5a*Z}nZ+X-#oIQc85Y zT`LDY%0bTn_WQePcZ5T{u2#_8#y8~`Rw@8!J+AuWYQ6UD#b17wlYl?Ns^Q?~@z_7ddR4!OdX*{hQXFGczpt8ATX2%s73< z^w@!2>*8zcnWjBuE54k(TbRLEc&6paopld6|NSt1{#4Cy0?;K4p00i_>zopr0EpF literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_item_quarktech_omnitool_beam.png b/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_item_quarktech_omnitool_beam.png new file mode 100644 index 0000000000000000000000000000000000000000..f6dbe03c12381dfb0383835d8d35df1e9591ccb2 GIT binary patch literal 526 zcmV+p0`dKcP)Ll09z|K@f(YIblHxu1Uj(V(HG7DJagiB3 zZ}>4OPAV-mFO8eeJGxWys5dH<`kqjD2!Jt$H}P!ML`}MYxAJ=Vz!QL8ai9^Q_^*zo z-lzbuTXUIAE-1KY*eB_5ul#{}qe9YdYBUd}e}7%;jSBq->pC7yGgC9b(LR#2n`(?< zw-yk$W;z~CX$`+huQ*T}cLA`c-JD-et^&x$(wFgQN;D58nupRW4m6sFlI%6rDcGOA z=^iZXHn(1Mw00OsDlwI9PrF3(PyoiGDQnl2k0-Odf}?$8^7O8{u1nhNzdV-mfhXzw zpSNauekOSZuv}+Y{=MtEl<(ZgKu*DO^_p;gCM0`JR literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_item_quarktech_omnitool_chassis.png b/src/main/resources/assets/gtceu/textures/item/tools/quarktech_omnitool/wrench_item_quarktech_omnitool_chassis.png new file mode 100644 index 0000000000000000000000000000000000000000..a7682f1133aaddd306fa74583b51907c0f04eaf8 GIT binary patch literal 490 zcmVLld*0SK@f(&u|VL$et|T(O=O4aE+@H9hb2m^xQUxQ zL7s@lG?DTE>5N2)ge*}&AS@K|3v7x&k^58FbFt5%;-t~u&fR?b&%e7SiT`<8%|r-6 zA%qR;qMH1hAPGs#s>gRpWLYK;&)wXgZ2TjMtwb~OJl_B{A@yp_!khaOW);jT$n#tt zuGT@%o@#5o=hMARG0x5XDT+cVWqiEGY7=9O)--OXHRW_KQ#t6d{w<}%yPv^W));vrnkqhC5h&^G8B&%zy}#IMoTGi zc9<*1XrDiQXEYw_;{4K@DuKGCCrw=UWi%dcv=U>q{r;{1uCIPC0Y@el)r1(M6-7~> z#B$KX6*wq_pmxXj`)4V_{4Ol22|w&TM<$kAl>p4;x*{Lj9r5a*Z}nZ+X-#oIQc85Y zT`LDY%0bTn_WQePcZ5T{u2#_8#y8~`Rw@8!J+A Date: Thu, 30 May 2024 11:04:00 -0400 Subject: [PATCH 2/4] The Mode swapping works now - kinda funky though. Does anyone know of a single-keypress solution --- .../gtceu/api/item/tool/GTOmniToolItem.java | 28 +++++++++---- .../renderer/item/ToolItemRenderer.java | 40 ++++++++++++++++++- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java b/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java index 5f1ddc60ab..ee7c460dba 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java +++ b/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java @@ -17,6 +17,8 @@ import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; import lombok.Getter; import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.client.Minecraft; +import net.minecraft.client.ToggleKeyMapping; import net.minecraft.client.renderer.item.ItemProperties; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; @@ -33,8 +35,9 @@ import javax.annotation.ParametersAreNonnullByDefault; import javax.naming.ldap.LdapContext; -import static com.gregtechceu.gtceu.api.item.tool.ToolHelper.getBehaviorsTag; -import static com.gregtechceu.gtceu.api.item.tool.ToolHelper.getMaxAoEDefinition; +import static com.gregtechceu.gtceu.api.item.tool.ToolHelper.*; +import static com.gregtechceu.gtceu.api.item.tool.ToolHelper.LAST_CRAFTING_USE_KEY; + @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault public class GTOmniToolItem extends GTToolItem implements IGTTool { @@ -74,10 +77,19 @@ public static GTOmniToolItem create(GTToolType toolType, MaterialToolTier tier, @Override public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) { super.inventoryTick(stack, level, entity, slotId, isSelected); - if (entity instanceof Player player && KeyBind.QUARK_TOOL_MODE_SWITCH.isKeyDown(player)){ + CompoundTag data = stack.getOrCreateTag(); + byte toggleTimer = data.contains("toggleTimer") ? data.getByte("toggleTimer") : 0; + + if (entity instanceof Player player && KeyBind.QUARK_TOOL_MODE_SWITCH.isKeyDown(player) && toggleTimer == 0){ + toggleTimer = 20; var tagCompound = getBehaviorsTag(stack); tagCompound.putByte("OmniToolMode", (byte) ((tagCompound.getByte("OmniToolMode") + 1) % ToolModeSwitchBehavior.OmniModeType.values().length)); player.displayClientMessage(Component.translatable("metaitem.machine_configuration.mode", ToolModeSwitchBehavior.OmniModeType.values()[tagCompound.getByte("OmniToolMode")].getName()), true); + setLastCraftingSoundTime(stack); + } + if (!level.isClientSide && toggleTimer > 0) { + --toggleTimer; + data.putByte("toggleTimer", toggleTimer); } } @@ -98,10 +110,12 @@ public InteractionResultHolder use(Level level, Player player, Intera public ModularUI createUI(Player entityPlayer, HeldItemUIFactory.HeldItemHolder holder) { CompoundTag tag = getBehaviorsTag(holder.getHeld()); AoESymmetrical defaultDefinition = getMaxAoEDefinition(holder.getHeld()); - return new ModularUI(450, 300, holder, entityPlayer).background(GuiTextures.BACKGROUND) - .widget(new LabelWidget(6, 10, "FUCK")) - .widget(new LabelWidget(49, 10, "SHIT")) - .widget(new LabelWidget(79, 10, "PISS")) + return new ModularUI(140, 120, holder, entityPlayer).background(GuiTextures.BACKGROUND) + .widget(new LabelWidget(6, 10, "item.gtceu.tool.aoe.columns")) + .widget(new LabelWidget(49, 10, "item.gtceu.tool.aoe.rows")) + .widget(new LabelWidget(79, 10, "item.gtceu.tool.aoe.layers")) + .widget(new LabelWidget(6, 85, "item.gtceu.tool.treefeller.mode")) + .widget(new LabelWidget(6, 105, "item.gtceu.tool.scythe.mode")) .widget(new ButtonWidget(15, 24, 20, 20, new TextTexture("+"), (data) -> { AoESymmetrical.increaseColumn(tag, defaultDefinition); holder.markAsDirty(); diff --git a/src/main/java/com/gregtechceu/gtceu/client/renderer/item/ToolItemRenderer.java b/src/main/java/com/gregtechceu/gtceu/client/renderer/item/ToolItemRenderer.java index 4fd47be00f..dffbb91a0a 100644 --- a/src/main/java/com/gregtechceu/gtceu/client/renderer/item/ToolItemRenderer.java +++ b/src/main/java/com/gregtechceu/gtceu/client/renderer/item/ToolItemRenderer.java @@ -1,12 +1,20 @@ package com.gregtechceu.gtceu.client.renderer.item; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import com.gregtechceu.gtceu.api.item.tool.GTToolType; import com.gregtechceu.gtceu.data.pack.GTDynamicResourcePack; +import net.minecraft.client.Minecraft; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.models.model.DelegatedModel; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.GsonHelper; import net.minecraft.world.item.Item; +import org.jetbrains.annotations.Nullable; +import java.io.BufferedReader; +import java.io.IOException; import java.util.HashSet; import java.util.Set; @@ -22,7 +30,15 @@ public class ToolItemRenderer { public static void reinitModels() { for (ToolItemRenderer model : MODELS) { GTDynamicResourcePack.addItemModel(BuiltInRegistries.ITEM.getKey(model.item), - new DelegatedModel(model.toolType.modelLocation)); + () -> { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("parent", model.toolType.modelLocation.toString()); + JsonArray clonedOverrides = cloneToolModelOverrides(model.toolType.modelLocation); + if (clonedOverrides != null) { + jsonObject.add("overrides", clonedOverrides); + } + return jsonObject; + }); } } @@ -37,4 +53,26 @@ protected ToolItemRenderer(Item item, GTToolType toolType) { public static void create(Item item, GTToolType toolType) { MODELS.add(new ToolItemRenderer(item, toolType)); } + + /** + * Clones the overrides for a single tool model. + * + * @param modelId the model id (usually {@code gtceu:item/tools/}) + */ + @Nullable + public static JsonArray cloneToolModelOverrides(ResourceLocation modelId) { + JsonObject original; + try (BufferedReader reader = Minecraft.getInstance().getResourceManager().openAsReader(modelId.withPrefix("models/").withSuffix(".json"))) { + original = GsonHelper.parse(reader, true); + } catch (IOException e) { + throw new RuntimeException(e); + } + + // clone it + JsonObject newJson = original.deepCopy(); + if (newJson.has("overrides")) { + return newJson.getAsJsonArray("overrides"); + } + return null; + } } From ac0825de27265520025f3cf3c126bf94a30d68be Mon Sep 17 00:00:00 2001 From: Ghostipedia Date: Fri, 31 May 2024 06:28:27 -0400 Subject: [PATCH 3/4] KeyPressed / KeyDown Packet Work --- .../gtceu/api/item/tool/GTOmniToolItem.java | 43 +++--- .../gtceu/common/network/GTNetwork.java | 6 +- .../network/packets/CPacketKeysDown.java | 44 +++++++ .../network/packets/CPacketKeysPressed.java | 43 +++--- .../utils/input/IKeyPressedListener.java | 7 + .../gtceu/utils/input/KeyBind.java | 123 ++++++++++++------ 6 files changed, 171 insertions(+), 95 deletions(-) create mode 100644 src/main/java/com/gregtechceu/gtceu/common/network/packets/CPacketKeysDown.java create mode 100644 src/main/java/com/gregtechceu/gtceu/utils/input/IKeyPressedListener.java diff --git a/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java b/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java index ee7c460dba..cb99716e5a 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java +++ b/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java @@ -8,6 +8,7 @@ import com.gregtechceu.gtceu.api.item.tool.aoe.AoESymmetrical; import com.gregtechceu.gtceu.client.renderer.item.ToolItemRenderer; import com.gregtechceu.gtceu.common.item.tool.behavior.ToolModeSwitchBehavior; +import com.gregtechceu.gtceu.utils.input.IKeyPressedListener; import com.gregtechceu.gtceu.utils.input.KeyBind; import com.lowdragmc.lowdraglib.LDLib; import com.lowdragmc.lowdraglib.gui.factory.HeldItemUIFactory; @@ -17,11 +18,10 @@ import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; import lombok.Getter; import net.minecraft.MethodsReturnNonnullByDefault; -import net.minecraft.client.Minecraft; -import net.minecraft.client.ToggleKeyMapping; import net.minecraft.client.renderer.item.ItemProperties; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.Entity; @@ -33,14 +33,13 @@ import org.jetbrains.annotations.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import javax.naming.ldap.LdapContext; -import static com.gregtechceu.gtceu.api.item.tool.ToolHelper.*; -import static com.gregtechceu.gtceu.api.item.tool.ToolHelper.LAST_CRAFTING_USE_KEY; +import static com.gregtechceu.gtceu.api.item.tool.ToolHelper.getBehaviorsTag; +import static com.gregtechceu.gtceu.api.item.tool.ToolHelper.getMaxAoEDefinition; @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault -public class GTOmniToolItem extends GTToolItem implements IGTTool { +public class GTOmniToolItem extends GTToolItem implements IGTTool, IKeyPressedListener { @Getter private final GTToolType toolType; @Getter @@ -49,7 +48,7 @@ public class GTOmniToolItem extends GTToolItem implements IGTTool { private final int electricTier; @Getter private final IGTToolDefinition omniToolStats; - + private static boolean onInit = false; protected GTOmniToolItem(GTToolType toolType, MaterialToolTier tier, Material material, IGTToolDefinition toolStats, Properties properties) { super(toolType, tier, material ,toolStats, properties); this.material = material; @@ -73,24 +72,26 @@ protected GTOmniToolItem(GTToolType toolType, MaterialToolTier tier, Material ma public static GTOmniToolItem create(GTToolType toolType, MaterialToolTier tier, Material material, IGTToolDefinition toolStats, Item.Properties properties){ return new GTOmniToolItem(toolType, tier, material, toolStats, properties); } - @Override - public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) { - super.inventoryTick(stack, level, entity, slotId, isSelected); - CompoundTag data = stack.getOrCreateTag(); - byte toggleTimer = data.contains("toggleTimer") ? data.getByte("toggleTimer") : 0; - - if (entity instanceof Player player && KeyBind.QUARK_TOOL_MODE_SWITCH.isKeyDown(player) && toggleTimer == 0){ - toggleTimer = 20; - var tagCompound = getBehaviorsTag(stack); + public void onKeyPressed(ServerPlayer player, KeyBind keyPressed) { + if (keyPressed.isPressed()){ + var stackHand = player.getMainHandItem(); + CompoundTag data = stackHand.getOrCreateTag(); + var tagCompound = getBehaviorsTag(stackHand); tagCompound.putByte("OmniToolMode", (byte) ((tagCompound.getByte("OmniToolMode") + 1) % ToolModeSwitchBehavior.OmniModeType.values().length)); player.displayClientMessage(Component.translatable("metaitem.machine_configuration.mode", ToolModeSwitchBehavior.OmniModeType.values()[tagCompound.getByte("OmniToolMode")].getName()), true); - setLastCraftingSoundTime(stack); + setLastCraftingSoundTime(stackHand); } - if (!level.isClientSide && toggleTimer > 0) { - --toggleTimer; - data.putByte("toggleTimer", toggleTimer); + } + @Override + public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) { + super.inventoryTick(stack, level, entity, slotId, isSelected); + if (!onInit){ + //Registers the listener then stops after the first tick. This is kinda hacky but it works. + KeyBind.QUARK_TOOL_MODE_SWITCH.registerListener((ServerPlayer) entity,this); + onInit = true; } + } @Override @@ -147,4 +148,6 @@ public ModularUI createUI(Player entityPlayer, HeldItemUIFactory.HeldItemHolder .widget(new LabelWidget(93, 65, () -> Integer.toString(1 + AoESymmetrical.getLayer(getBehaviorsTag(holder.getHeld()), defaultDefinition)))); } + + } diff --git a/src/main/java/com/gregtechceu/gtceu/common/network/GTNetwork.java b/src/main/java/com/gregtechceu/gtceu/common/network/GTNetwork.java index 9e4a974e8b..51b22b594d 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/network/GTNetwork.java +++ b/src/main/java/com/gregtechceu/gtceu/common/network/GTNetwork.java @@ -1,10 +1,7 @@ package com.gregtechceu.gtceu.common.network; import com.gregtechceu.gtceu.GTCEu; -import com.gregtechceu.gtceu.common.network.packets.CPacketKeysPressed; -import com.gregtechceu.gtceu.common.network.packets.SPacketSyncBedrockOreVeins; -import com.gregtechceu.gtceu.common.network.packets.SPacketSyncFluidVeins; -import com.gregtechceu.gtceu.common.network.packets.SPacketSyncOreVeins; +import com.gregtechceu.gtceu.common.network.packets.*; import com.lowdragmc.lowdraglib.networking.INetworking; import com.lowdragmc.lowdraglib.networking.forge.LDLNetworkingImpl; @@ -15,6 +12,7 @@ public class GTNetwork { public static void init() { NETWORK.registerC2S(CPacketKeysPressed.class); + NETWORK.registerC2S(CPacketKeysDown.class); NETWORK.registerS2C(SPacketSyncOreVeins.class); NETWORK.registerS2C(SPacketSyncFluidVeins.class); NETWORK.registerS2C(SPacketSyncBedrockOreVeins.class); diff --git a/src/main/java/com/gregtechceu/gtceu/common/network/packets/CPacketKeysDown.java b/src/main/java/com/gregtechceu/gtceu/common/network/packets/CPacketKeysDown.java new file mode 100644 index 0000000000..8970253253 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/common/network/packets/CPacketKeysDown.java @@ -0,0 +1,44 @@ +package com.gregtechceu.gtceu.common.network.packets; + +import com.gregtechceu.gtceu.utils.input.KeyBind; +import com.lowdragmc.lowdraglib.networking.IHandlerContext; +import com.lowdragmc.lowdraglib.networking.IPacket; +import it.unimi.dsi.fastutil.ints.Int2BooleanMap; +import it.unimi.dsi.fastutil.ints.Int2BooleanOpenHashMap; +import lombok.NoArgsConstructor; +import net.minecraft.network.FriendlyByteBuf; + +@NoArgsConstructor +public class CPacketKeysDown implements IPacket { + private Int2BooleanMap updateKeys; + + public CPacketKeysDown(Int2BooleanMap updateKeys) { + this.updateKeys = updateKeys; + } + + @Override + public void encode(FriendlyByteBuf buf) { + buf.writeVarInt(updateKeys.size()); + for (var entry : updateKeys.int2BooleanEntrySet()) { + buf.writeVarInt(entry.getIntKey()); + buf.writeBoolean(entry.getBooleanValue()); + } + } + + @Override + public void decode(FriendlyByteBuf buf) { + this.updateKeys = new Int2BooleanOpenHashMap(); + int size = buf.readVarInt(); + for (int i = 0; i < size; i++) { + updateKeys.put(buf.readVarInt(), buf.readBoolean()); + } + } + + @Override + public void execute(IHandlerContext handler) { + KeyBind[] keybinds = KeyBind.VALUES; + for (var entry : updateKeys.int2BooleanEntrySet()) { + keybinds[entry.getIntKey()].updateKeyDown(entry.getBooleanValue(), handler.getPlayer()); + } + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/common/network/packets/CPacketKeysPressed.java b/src/main/java/com/gregtechceu/gtceu/common/network/packets/CPacketKeysPressed.java index 2b3cd3db0f..1be0f093b5 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/network/packets/CPacketKeysPressed.java +++ b/src/main/java/com/gregtechceu/gtceu/common/network/packets/CPacketKeysPressed.java @@ -1,58 +1,45 @@ package com.gregtechceu.gtceu.common.network.packets; import com.gregtechceu.gtceu.utils.input.KeyBind; - import com.lowdragmc.lowdraglib.networking.IHandlerContext; import com.lowdragmc.lowdraglib.networking.IPacket; - -import net.minecraft.network.FriendlyByteBuf; - -import com.mojang.datafixers.util.Pair; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; import lombok.NoArgsConstructor; - -import java.util.List; +import net.minecraft.network.FriendlyByteBuf; @NoArgsConstructor public class CPacketKeysPressed implements IPacket { - private Object updateKeys; + private IntList pressedKeys; + - public CPacketKeysPressed(List updateKeys) { - this.updateKeys = updateKeys; + public CPacketKeysPressed(IntList pressedKeys) { + this.pressedKeys = pressedKeys; } @Override public void encode(FriendlyByteBuf buf) { - List updateKeys = (List) this.updateKeys; - buf.writeVarInt(updateKeys.size()); - for (KeyBind keyBind : updateKeys) { - buf.writeVarInt(keyBind.ordinal()); - buf.writeBoolean(keyBind.isPressed()); - buf.writeBoolean(keyBind.isKeyDown()); + buf.writeVarInt(pressedKeys.size()); + for (int key : pressedKeys) { + buf.writeVarInt(key); } } @Override public void decode(FriendlyByteBuf buf) { - this.updateKeys = new Pair[KeyBind.VALUES.length]; - Pair[] updateKeys = (Pair[]) this.updateKeys; + pressedKeys = new IntArrayList(); int size = buf.readVarInt(); for (int i = 0; i < size; i++) { - updateKeys[buf.readVarInt()] = Pair.of(buf.readBoolean(), buf.readBoolean()); + pressedKeys.add(buf.readVarInt()); } } @Override public void execute(IHandlerContext handler) { - if (handler.getPlayer() != null) { - KeyBind[] keybinds = KeyBind.VALUES; - Pair[] updateKeys = (Pair[]) this.updateKeys; - for (int i = 0; i < updateKeys.length; i++) { - Pair pair = updateKeys[i]; - if (pair != null) { - keybinds[i].update(pair.getFirst(), pair.getSecond(), handler.getPlayer()); - } - } + KeyBind[] keyBinds = KeyBind.VALUES; + for (int index : pressedKeys) { + keyBinds[index].onKeyPressed(handler.getPlayer()); } } } diff --git a/src/main/java/com/gregtechceu/gtceu/utils/input/IKeyPressedListener.java b/src/main/java/com/gregtechceu/gtceu/utils/input/IKeyPressedListener.java new file mode 100644 index 0000000000..181030686e --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/utils/input/IKeyPressedListener.java @@ -0,0 +1,7 @@ +package com.gregtechceu.gtceu.utils.input; + +import net.minecraft.server.level.ServerPlayer; + +public interface IKeyPressedListener { + void onKeyPressed(ServerPlayer player, KeyBind keyPressed); +} diff --git a/src/main/java/com/gregtechceu/gtceu/utils/input/KeyBind.java b/src/main/java/com/gregtechceu/gtceu/utils/input/KeyBind.java index f78420a319..e41221ac88 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/input/KeyBind.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/input/KeyBind.java @@ -1,11 +1,17 @@ package com.gregtechceu.gtceu.utils.input; import com.gregtechceu.gtceu.GTCEu; +import com.gregtechceu.gtceu.api.GTCEuAPI; import com.gregtechceu.gtceu.common.network.GTNetwork; +import com.gregtechceu.gtceu.common.network.packets.CPacketKeysDown; import com.gregtechceu.gtceu.common.network.packets.CPacketKeysPressed; import com.lowdragmc.lowdraglib.Platform; +import it.unimi.dsi.fastutil.ints.Int2BooleanMap; +import it.unimi.dsi.fastutil.ints.Int2BooleanOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.server.level.ServerPlayer; @@ -17,6 +23,7 @@ import net.minecraftforge.client.settings.IKeyConflictContext; import net.minecraftforge.client.settings.KeyConflictContext; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -44,7 +51,14 @@ public enum KeyBind { public static final KeyBind[] VALUES = values(); private static double mouseDelta = 0.0; - + @OnlyIn(Dist.CLIENT) + private KeyMapping keybinding; + @OnlyIn(Dist.CLIENT) + private boolean isKeyDown; + @OnlyIn(Dist.CLIENT) + private boolean isPressed; + private final WeakHashMap mapping = new WeakHashMap<>(); + private final WeakHashMap> listeners = new WeakHashMap<>(); public static void init() { GTCEu.LOGGER.info("Registering KeyBinds"); if (Platform.isClient()) { @@ -52,24 +66,6 @@ public static void init() { } } - @SubscribeEvent - @OnlyIn(Dist.CLIENT) - public static void onInputEvent(InputEvent.Key event) { - List updating = new ArrayList<>(); - for (KeyBind keybind : VALUES) { - boolean previousPressed = keybind.isPressed; - boolean previousKeyDown = keybind.isKeyDown; - keybind.isPressed = keybind.isPressed(); - keybind.isKeyDown = keybind.isKeyDown(); - if (previousPressed != keybind.isPressed || previousKeyDown != keybind.isKeyDown) { - updating.add(keybind); - } - } - if (!updating.isEmpty()) { - GTNetwork.NETWORK.sendToServer(new CPacketKeysPressed(updating)); - } - } - public static void onRegisterKeyBinds(RegisterKeyMappingsEvent event) { Arrays.stream(VALUES).forEach(value -> { if (value.keybindingGetter == null) { @@ -102,12 +98,40 @@ public static boolean scrollingDown() { @OnlyIn(Dist.CLIENT) private Supplier> keybindingGetter; + + + /** + * Handle Keys which we track for "holds" on the server, meaning if a key is being pressed + * down for a prolonged period of time. This is a state which gets saved on the server. + */ + @SubscribeEvent @OnlyIn(Dist.CLIENT) - private KeyMapping keybinding; - @OnlyIn(Dist.CLIENT) - private boolean isPressed, isKeyDown; + public static void onClientTick(TickEvent.ClientTickEvent event) { + if (event.phase == TickEvent.Phase.START) { + Int2BooleanMap updatingKeyDown = new Int2BooleanOpenHashMap(); + for (KeyBind keybind : VALUES) { + boolean previousKeyDown = keybind.isKeyDown; + keybind.isKeyDown = keybind.keybinding.isDown(); + if (previousKeyDown != keybind.isKeyDown) { + updatingKeyDown.put(keybind.ordinal(), keybind.isKeyDown()); + } + } + if (!updatingKeyDown.isEmpty()) { + GTNetwork.NETWORK.sendToServer(new CPacketKeysDown(updatingKeyDown)); + } + } + } + + public void updateKeyDown(boolean keyDown, ServerPlayer player) { + this.mapping.put(player, keyDown); + } - private final WeakHashMap> mapping = new WeakHashMap<>(); + public boolean isKeyDown(Player player) { + if (player.level().isClientSide) return keybinding.isDown(); + // potential NPE here on unboxing if it is returned directly + Boolean isKeyDown = mapping.get((ServerPlayer) player); + return isKeyDown != null ? isKeyDown : false; + } // For Vanilla/Other Mod keybinds // Double Supplier to keep client classes from loading @@ -136,7 +160,7 @@ public KeyMapping toMinecraft() { @OnlyIn(Dist.CLIENT) public boolean isPressed() { - return this.keybinding.isDown(); + return this.keybinding.consumeClick(); } @OnlyIn(Dist.CLIENT) @@ -144,31 +168,44 @@ public boolean isKeyDown() { return this.keybinding.isDown(); } - public void update(boolean pressed, boolean keyDown, ServerPlayer player) { - MutablePair pair = this.mapping.get(player); - if (pair == null) { - this.mapping.put(player, MutablePair.of(pressed, keyDown)); - } else { - pair.left = pressed; - pair.right = keyDown; + /** + * Handle Keys which we track for "presses" on the server, meaning a single input which + * sends a packet to the server which informs all listeners. + */ + @SubscribeEvent + @OnlyIn(Dist.CLIENT) + public static void onInputEvent(InputEvent.Key event) { + IntList updatingPressed = new IntArrayList(); + for (KeyBind keybind : VALUES) { + if (keybind.keybinding.consumeClick()) { + updatingPressed.add(keybind.ordinal()); + } + } + if (!updatingPressed.isEmpty()) { + GTNetwork.NETWORK.sendToServer(new CPacketKeysPressed(updatingPressed)); } } - public boolean isPressed(Player player) { - if (player.level().isClientSide) { - return isPressed(); - } else { - MutablePair pair = this.mapping.get((ServerPlayer) player); - return pair != null && pair.left; + public void onKeyPressed(ServerPlayer player) { + Set listenerSet = listeners.get(player); + if (listenerSet != null && !listenerSet.isEmpty()) { + for (var listener : listenerSet) { + listener.onKeyPressed(player, this); + } } } - public boolean isKeyDown(Player player) { - if (player.level().isClientSide) { - return isKeyDown(); - } else { - MutablePair pair = this.mapping.get((ServerPlayer) player); - return pair != null && pair.right; + public void registerListener(ServerPlayer player, IKeyPressedListener listener) { + Set listenerSet = listeners.computeIfAbsent(player, k -> new HashSet<>()); + listenerSet.add(listener); + } + + public void removeListener(ServerPlayer player, IKeyPressedListener listener) { + Set listenerSet = listeners.get(player); + if (listenerSet != null) { + listenerSet.remove(listener); } } + + } From 6694a0bdc3928a64b192659e30434c08eb2e6157 Mon Sep 17 00:00:00 2001 From: Ghostipedia Date: Fri, 31 May 2024 23:45:35 -0400 Subject: [PATCH 4/4] Wuh networking adding screrets stuff ( it's probs still going to not work ) --- .../com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java b/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java index cb99716e5a..17077ff763 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java +++ b/src/main/java/com/gregtechceu/gtceu/api/item/tool/GTOmniToolItem.java @@ -87,7 +87,7 @@ public void onKeyPressed(ServerPlayer player, KeyBind keyPressed) { public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) { super.inventoryTick(stack, level, entity, slotId, isSelected); if (!onInit){ - //Registers the listener then stops after the first tick. This is kinda hacky but it works. + //Registers the listener then stops after the first tick. KeyBind.QUARK_TOOL_MODE_SWITCH.registerListener((ServerPlayer) entity,this); onInit = true; }