Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuarkTech Omnitool #1351

Draft
wants to merge 6 commits into
base: 1.20.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"page": "gtceu:tools/crowbar",
"position": [
-250,
-200,
250
],
"section": "gtceu:tools"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"page": "gtceu:tools/hoe",
"position": [
-200,
-150,
250
],
"section": "gtceu:tools"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 2 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -1996,6 +1996,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",
Expand Down Expand Up @@ -4603,6 +4604,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",
Expand Down
2 changes: 2 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1996,6 +1996,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",
Expand Down Expand Up @@ -4603,6 +4604,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",
Expand Down
9 changes: 9 additions & 0 deletions src/generated/resources/assets/gtceu/sounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public static Builder of(float harvestSpeed, float attackDamage, int durability,
WRENCH_IV,
BUZZSAW,
SCREWDRIVER_LV,
QUARKTECH_OMNITOOL
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
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.IKeyPressedListener;
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.server.level.ServerPlayer;
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 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, IKeyPressedListener {
@Getter
private final GTToolType toolType;
@Getter
private final Material material;
@Getter
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;
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 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(stackHand);
}
}
@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.
KeyBind.QUARK_TOOL_MODE_SWITCH.registerListener((ServerPlayer) entity,this);
onInit = 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<ItemStack> 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(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();
}))
.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))));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
});
}
}

Expand All @@ -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/<tool id path>})
*/
@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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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;
Expand All @@ -32,6 +33,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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading
Loading