diff --git a/src/main/java/com/github/gtexpert/core/integration/chisel/ChiselModule.java b/src/main/java/com/github/gtexpert/core/integration/chisel/ChiselModule.java index a7f0696f..8db6a61f 100644 --- a/src/main/java/com/github/gtexpert/core/integration/chisel/ChiselModule.java +++ b/src/main/java/com/github/gtexpert/core/integration/chisel/ChiselModule.java @@ -1,8 +1,22 @@ package com.github.gtexpert.core.integration.chisel; +import java.util.Collections; +import java.util.List; + import net.minecraft.block.Block; +import net.minecraft.item.Item; import net.minecraft.item.crafting.IRecipe; +import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.registries.IForgeRegistry; + +import org.jetbrains.annotations.NotNull; + +import gregtech.api.items.toolitem.IGTTool; import com.github.gtexpert.core.api.GTEValues; import com.github.gtexpert.core.api.modules.GTEModule; @@ -12,6 +26,8 @@ import com.github.gtexpert.core.integration.chisel.metatileentities.ChiselMetaTileEntities; import com.github.gtexpert.core.integration.chisel.recipes.ChiselBlocksRecipe; import com.github.gtexpert.core.integration.chisel.recipes.ChiselToolsRecipe; +import com.github.gtexpert.core.integration.chisel.tools.ChiselToolItems; +import com.github.gtexpert.core.integration.chisel.tools.ChiselToolRecipeHandler; import com.github.gtexpert.core.modules.GTEModules; @GTEModule( @@ -22,6 +38,32 @@ description = "Chisel Integration Module") public class ChiselModule extends GTEIntegrationSubmodule { + @NotNull + @Override + public List> getEventBusSubscribers() { + return Collections.singletonList(ChiselModule.class); + } + + @Override + public void preInit(FMLPreInitializationEvent event) { + ChiselToolItems.init(); + ChiselToolRecipeHandler.registerRecipes(); + } + + @SubscribeEvent + public static void onRegisterItems(RegistryEvent.Register event) { + IForgeRegistry registry = event.getRegistry(); + for (IGTTool tool : ChiselToolItems.getAllTools()) { + registry.register(tool.get()); + } + } + + @SubscribeEvent + @SideOnly(Side.CLIENT) + public static void onRegisterModels(ModelRegistryEvent event) { + ChiselToolItems.registerModels(); + } + @Override public void registerBlocks(RegistryEvent.Register event) { ChiselMetaTileEntities.init(); @@ -30,6 +72,7 @@ public void registerBlocks(RegistryEvent.Register event) { @Override public void registerRecipesNormal(RegistryEvent.Register event) { ChiselOreDictionaryLoader.init(); + ChiselToolItems.registerOreDict(); } @Override @@ -37,4 +80,9 @@ public void registerRecipesLowest(RegistryEvent.Register event) { ChiselBlocksRecipe.init(); ChiselToolsRecipe.init(); } + + @SideOnly(Side.CLIENT) + public static void registerColors() { + ChiselToolItems.registerColors(); + } } diff --git a/src/main/java/com/github/gtexpert/core/integration/chisel/recipes/ChiselToolsRecipe.java b/src/main/java/com/github/gtexpert/core/integration/chisel/recipes/ChiselToolsRecipe.java index fb968370..392767bd 100644 --- a/src/main/java/com/github/gtexpert/core/integration/chisel/recipes/ChiselToolsRecipe.java +++ b/src/main/java/com/github/gtexpert/core/integration/chisel/recipes/ChiselToolsRecipe.java @@ -1,13 +1,8 @@ package com.github.gtexpert.core.integration.chisel.recipes; -import static gregtech.api.unification.ore.OrePrefix.*; - import gregtech.api.recipes.ModHandler; -import gregtech.api.unification.material.Materials; -import gregtech.api.unification.stack.UnificationEntry; import gregtech.common.ConfigHolder; -import com.github.gtexpert.core.api.util.GTEUtility; import com.github.gtexpert.core.api.util.Mods; import com.github.gtexpert.core.integration.chisel.ChiselConfigHolder; @@ -15,32 +10,10 @@ public class ChiselToolsRecipe { public static void init() { if (ConfigHolder.recipes.hardToolArmorRecipes && ChiselConfigHolder.hardToolRecipes) { - // Iron Chisel + // Remove original Chisel mod recipes - replaced by GregTech-style chisel ModHandler.removeRecipeByName(Mods.Chisel.getResource("chisel_iron")); - ModHandler.addShapedRecipe(true, "chisel_iron", - GTEUtility.getModItem(Mods.Names.CHISEL, "chisel_iron"), - "fPP", " CP", "S h", - 'P', new UnificationEntry(plate, Materials.Iron), - 'C', new UnificationEntry(screw, Materials.Iron), - 'S', new UnificationEntry(stick, Materials.Bronze)); - - // Diamond Chisel ModHandler.removeRecipeByName(Mods.Chisel.getResource("chisel_diamond")); - ModHandler.addShapedRecipe(true, "chisel_diamond", - GTEUtility.getModItem(Mods.Names.CHISEL, "chisel_diamond"), - "fPP", " CP", "S h", - 'P', new UnificationEntry(plate, Materials.Diamond), - 'C', GTEUtility.getModItem(Mods.Names.CHISEL, "chisel_iron"), - 'S', new UnificationEntry(stick, Materials.RoseGold)); - - // iChisel ModHandler.removeRecipeByName(Mods.Chisel.getResource("chisel_hitech")); - ModHandler.addShapedRecipe(true, "chisel_hitech", - GTEUtility.getModItem(Mods.Names.CHISEL, "chisel_hitech"), - "fPP", " CP", "S h", - 'P', new UnificationEntry(plate, Materials.Diamond), - 'C', GTEUtility.getModItem(Mods.Names.CHISEL, "chisel_diamond"), - 'S', new UnificationEntry(stick, Materials.StainlessSteel)); } } } diff --git a/src/main/java/com/github/gtexpert/core/integration/chisel/tools/ChiselToolItems.java b/src/main/java/com/github/gtexpert/core/integration/chisel/tools/ChiselToolItems.java new file mode 100644 index 00000000..6a67b0c2 --- /dev/null +++ b/src/main/java/com/github/gtexpert/core/integration/chisel/tools/ChiselToolItems.java @@ -0,0 +1,65 @@ +package com.github.gtexpert.core.integration.chisel.tools; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import gregtech.api.GTValues; +import gregtech.api.items.toolitem.IGTTool; +import gregtech.api.items.toolitem.ItemGTTool; +import gregtech.api.unification.OreDictUnifier; + +import com.github.gtexpert.core.api.GTEValues; + +public final class ChiselToolItems { + + private static final List TOOLS = new ArrayList<>(); + + public static IGTTool CHISEL; + + private ChiselToolItems() {} + + public static List getAllTools() { + return TOOLS; + } + + public static void init() { + CHISEL = register(ItemGTTool.Builder.of(GTEValues.MODID, "chisel") + .toolStats(b -> b.cannotAttack().attackSpeed(-2.4F).durabilityMultiplier(2.0F)) + .oreDict("toolChisel") + .secondaryOreDicts("craftingToolChisel") + .toolClasses("chisel") + .build()); + } + + public static IGTTool register(IGTTool tool) { + TOOLS.add(tool); + return tool; + } + + @SideOnly(Side.CLIENT) + public static void registerModels() { + TOOLS.forEach(tool -> ModelLoader.setCustomModelResourceLocation(tool.get(), 0, tool.getModelLocation())); + } + + @SideOnly(Side.CLIENT) + public static void registerColors() { + TOOLS.forEach( + tool -> Minecraft.getMinecraft().getItemColors().registerItemColorHandler(tool::getColor, tool.get())); + } + + public static void registerOreDict() { + TOOLS.forEach(tool -> { + final ItemStack stack = new ItemStack(tool.get(), 1, GTValues.W); + if (tool.getOreDictName() != null) { + OreDictUnifier.registerOre(stack, tool.getOreDictName()); + } + tool.getSecondaryOreDicts().forEach(oreDict -> OreDictUnifier.registerOre(stack, oreDict)); + }); + } +} diff --git a/src/main/java/com/github/gtexpert/core/integration/chisel/tools/ChiselToolRecipeHandler.java b/src/main/java/com/github/gtexpert/core/integration/chisel/tools/ChiselToolRecipeHandler.java new file mode 100644 index 00000000..98924166 --- /dev/null +++ b/src/main/java/com/github/gtexpert/core/integration/chisel/tools/ChiselToolRecipeHandler.java @@ -0,0 +1,39 @@ +package com.github.gtexpert.core.integration.chisel.tools; + +import static gregtech.api.unification.material.info.MaterialFlags.*; + +import gregtech.api.recipes.ModHandler; +import gregtech.api.unification.material.Material; +import gregtech.api.unification.material.Materials; +import gregtech.api.unification.material.properties.PropertyKey; +import gregtech.api.unification.material.properties.ToolProperty; +import gregtech.api.unification.ore.OrePrefix; +import gregtech.api.unification.stack.UnificationEntry; +import gregtech.common.ConfigHolder; + +import com.github.gtexpert.core.integration.chisel.ChiselConfigHolder; + +public class ChiselToolRecipeHandler { + + public static void registerRecipes() { + OrePrefix.plate.addProcessingHandler(PropertyKey.TOOL, ChiselToolRecipeHandler::processChiselRecipe); + } + + private static void processChiselRecipe(OrePrefix prefix, Material material, ToolProperty property) { + if (!material.hasFlag(GENERATE_PLATE)) return; + + if (ConfigHolder.recipes.hardToolArmorRecipes && ChiselConfigHolder.hardToolRecipes) { + ModHandler.addShapedRecipe(String.format("chisel_%s", material.getName()), + ChiselToolItems.CHISEL.get(material), + "fPh", " S ", + 'P', new UnificationEntry(OrePrefix.plate, material), + 'S', new UnificationEntry(OrePrefix.stick, Materials.Wood)); + } else { + ModHandler.addShapedRecipe(String.format("chisel_%s", material.getName()), + ChiselToolItems.CHISEL.get(material), + " I", "S ", + 'I', new UnificationEntry(OrePrefix.ingot, material), + 'S', new UnificationEntry(OrePrefix.stick, Materials.Wood)); + } + } +} diff --git a/src/main/java/com/github/gtexpert/core/mixins/chisel/ItemGTToolChiselMixin.java b/src/main/java/com/github/gtexpert/core/mixins/chisel/ItemGTToolChiselMixin.java new file mode 100644 index 00000000..e5aa4e7e --- /dev/null +++ b/src/main/java/com/github/gtexpert/core/mixins/chisel/ItemGTToolChiselMixin.java @@ -0,0 +1,87 @@ +package com.github.gtexpert.core.mixins.chisel; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import org.spongepowered.asm.mixin.Mixin; + +import gregtech.api.items.toolitem.ItemGTTool; +import gregtech.api.items.toolitem.ToolHelper; + +import team.chisel.api.IChiselGuiType; +import team.chisel.api.IChiselGuiType.ChiselGuiType; +import team.chisel.api.IChiselItem; +import team.chisel.api.carving.ICarvingVariation; +import team.chisel.api.carving.IChiselMode; +import team.chisel.common.item.ChiselMode; + +/** + * Mixin to make GregTech tools with "chisel" tool class implement Chisel mod's IChiselItem interface. + * This allows GT chisel tools to work with the Chisel mod's chiseling functionality. + */ +@Mixin(value = ItemGTTool.class, remap = false) +public abstract class ItemGTToolChiselMixin implements IChiselItem { + + /** + * Check if this tool has the "chisel" tool class + */ + private boolean gtexpert$isChiselTool() { + ItemGTTool tool = (ItemGTTool) (Object) this; + return tool.getToolClasses(ItemStack.EMPTY).contains("chisel"); + } + + @Override + public boolean canOpenGui(World world, EntityPlayer player, EnumHand hand) { + return gtexpert$isChiselTool(); + } + + @Override + public IChiselGuiType getGuiType(World world, EntityPlayer player, EnumHand hand) { + return ChiselGuiType.NORMAL; + } + + @Override + public boolean onChisel(World world, EntityPlayer player, ItemStack chisel, ICarvingVariation target) { + return gtexpert$isChiselTool(); + } + + @Override + public boolean canChisel(World world, EntityPlayer player, ItemStack chisel, ICarvingVariation target) { + return gtexpert$isChiselTool() && !chisel.isEmpty(); + } + + @Override + public boolean canChiselBlock(World world, EntityPlayer player, EnumHand hand, BlockPos pos, IBlockState state) { + return gtexpert$isChiselTool(); + } + + @Override + public boolean supportsMode(EntityPlayer player, ItemStack chisel, IChiselMode mode) { + if (!gtexpert$isChiselTool()) return false; + // Support basic modes, exclude advanced contiguous modes + return mode != ChiselMode.CONTIGUOUS && mode != ChiselMode.CONTIGUOUS_2D; + } + + @Override + public ItemStack craftItem(ItemStack chisel, ItemStack source, ItemStack target, EntityPlayer player) { + if (!gtexpert$isChiselTool() || chisel.isEmpty()) return ItemStack.EMPTY; + + int toCraft = Math.min(source.getCount(), target.getMaxStackSize()); + + // Check remaining durability + int durabilityLeft = chisel.getMaxDamage() - chisel.getItemDamage() + 1; + toCraft = Math.min(toCraft, durabilityLeft); + + // Damage the tool using GT's damage system + ToolHelper.damageItem(chisel, player, toCraft); + + ItemStack result = target.copy(); + source.shrink(toCraft); + result.setCount(toCraft); + return result; + } +} diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang new file mode 100644 index 00000000..427ccaeb --- /dev/null +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -0,0 +1,2 @@ +item.gt.tool.chisel.name=%s Chisel +gt.tool.class.chisel=Chisel diff --git a/src/main/resources/assets/gregtech/lang/ja_jp.lang b/src/main/resources/assets/gregtech/lang/ja_jp.lang new file mode 100644 index 00000000..6f879aea --- /dev/null +++ b/src/main/resources/assets/gregtech/lang/ja_jp.lang @@ -0,0 +1,2 @@ +item.gt.tool.chisel.name=%sのチゼル +gt.tool.class.chisel=チゼル diff --git a/src/main/resources/assets/gtexpert/models/item/tools/chisel.json b/src/main/resources/assets/gtexpert/models/item/tools/chisel.json new file mode 100644 index 00000000..9f21c078 --- /dev/null +++ b/src/main/resources/assets/gtexpert/models/item/tools/chisel.json @@ -0,0 +1,7 @@ +{ + "parent": "item/handheld", + "textures": { + "layer0": "gtexpert:items/tools/chisel_base", + "layer1": "gtexpert:items/tools/chisel" + } +} diff --git a/src/main/resources/assets/gtexpert/textures/items/tools/chisel.png b/src/main/resources/assets/gtexpert/textures/items/tools/chisel.png new file mode 100644 index 00000000..19e94870 Binary files /dev/null and b/src/main/resources/assets/gtexpert/textures/items/tools/chisel.png differ diff --git a/src/main/resources/assets/gtexpert/textures/items/tools/chisel_base.png b/src/main/resources/assets/gtexpert/textures/items/tools/chisel_base.png new file mode 100644 index 00000000..684bc37d Binary files /dev/null and b/src/main/resources/assets/gtexpert/textures/items/tools/chisel_base.png differ diff --git a/src/main/resources/mixins.gtexpert.chisel.json b/src/main/resources/mixins.gtexpert.chisel.json index 80ea5410..807ffdec 100644 --- a/src/main/resources/mixins.gtexpert.chisel.json +++ b/src/main/resources/mixins.gtexpert.chisel.json @@ -5,6 +5,7 @@ "minVersion": "0.8", "compatibilityLevel": "JAVA_8", "mixins": [ - "BlockCarvableMixin" + "BlockCarvableMixin", + "ItemGTToolChiselMixin" ] } \ No newline at end of file