Skip to content
Closed
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
@@ -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;
Expand All @@ -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(
Expand All @@ -22,6 +38,32 @@
description = "Chisel Integration Module")
public class ChiselModule extends GTEIntegrationSubmodule {

@NotNull
@Override
public List<Class<?>> getEventBusSubscribers() {
return Collections.singletonList(ChiselModule.class);
}

@Override
public void preInit(FMLPreInitializationEvent event) {
ChiselToolItems.init();
ChiselToolRecipeHandler.registerRecipes();
}

@SubscribeEvent
public static void onRegisterItems(RegistryEvent.Register<Item> event) {
IForgeRegistry<Item> 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<Block> event) {
ChiselMetaTileEntities.init();
Expand All @@ -30,11 +72,17 @@ public void registerBlocks(RegistryEvent.Register<Block> event) {
@Override
public void registerRecipesNormal(RegistryEvent.Register<IRecipe> event) {
ChiselOreDictionaryLoader.init();
ChiselToolItems.registerOreDict();
}

@Override
public void registerRecipesLowest(RegistryEvent.Register<IRecipe> event) {
ChiselBlocksRecipe.init();
ChiselToolsRecipe.init();
}

@SideOnly(Side.CLIENT)
public static void registerColors() {
ChiselToolItems.registerColors();
}
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,19 @@
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;

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));
}
}
}
Original file line number Diff line number Diff line change
@@ -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<IGTTool> TOOLS = new ArrayList<>();

public static IGTTool CHISEL;

private ChiselToolItems() {}

public static List<IGTTool> 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));
});
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
item.gt.tool.chisel.name=%s Chisel
gt.tool.class.chisel=Chisel
2 changes: 2 additions & 0 deletions src/main/resources/assets/gregtech/lang/ja_jp.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
item.gt.tool.chisel.name=%sのチゼル
gt.tool.class.chisel=チゼル
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "item/handheld",
"textures": {
"layer0": "gtexpert:items/tools/chisel_base",
"layer1": "gtexpert:items/tools/chisel"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/main/resources/mixins.gtexpert.chisel.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": [
"BlockCarvableMixin"
"BlockCarvableMixin",
"ItemGTToolChiselMixin"
]
}