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

Add durability-based decomposition to Rotors and Tools #2623

Merged
merged 2 commits into from
Jan 4, 2025
Merged
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
3 changes: 2 additions & 1 deletion src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,6 @@
"config.gtceu.option.enableCleanroom": "ɯooɹuɐǝןƆǝןqɐuǝ",
"config.gtceu.option.enableFEConverters": "sɹǝʇɹǝʌuoƆƎℲǝןqɐuǝ",
"config.gtceu.option.enableMaintenance": "ǝɔuɐuǝʇuıɐWǝןqɐuǝ",
"config.gtceu.option.enableMoreDualHatchAbility": "ʎʇıןıqⱯɥɔʇɐHןɐnᗡǝɹoWǝןqɐuǝ",
"config.gtceu.option.enableResearch": "ɥɔɹɐǝsǝᴚǝןqɐuǝ",
"config.gtceu.option.enableTieredCasings": "sbuısɐƆpǝɹǝı⟘ǝןqɐuǝ",
"config.gtceu.option.enableWorldAccelerators": "sɹoʇɐɹǝןǝɔɔⱯpןɹoMǝןqɐuǝ",
Expand Down Expand Up @@ -2128,6 +2127,8 @@
"gtceu.arc_furnace": "ǝɔɐuɹnℲ ɔɹⱯ",
"gtceu.assembler": "ɹǝןqɯǝssⱯ",
"gtceu.assembly_line": "ǝuıꞀ ʎןqɯǝssⱯ",
"gtceu.auto_decomp.rotor": "ɹoʇoᴚ ǝuıqɹn⟘",
"gtceu.auto_decomp.tool": "ןooʇ ɔıɹʇɔǝןǝ-uoN",
"gtceu.autoclave": "ǝʌɐןɔoʇnⱯ",
"gtceu.battery_buffer.average_input": "ʇ/∩Ǝ %s :ʇnduı ǝbɐɹǝʌⱯ",
"gtceu.battery_buffer.average_output": "ʇ/∩Ǝ %s :ʇndʇno ǝbɐɹǝʌⱯ",
Expand Down
3 changes: 2 additions & 1 deletion src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,6 @@
"config.gtceu.option.enableCleanroom": "enableCleanroom",
"config.gtceu.option.enableFEConverters": "enableFEConverters",
"config.gtceu.option.enableMaintenance": "enableMaintenance",
"config.gtceu.option.enableMoreDualHatchAbility": "enableMoreDualHatchAbility",
"config.gtceu.option.enableResearch": "enableResearch",
"config.gtceu.option.enableTieredCasings": "enableTieredCasings",
"config.gtceu.option.enableWorldAccelerators": "enableWorldAccelerators",
Expand Down Expand Up @@ -2128,6 +2127,8 @@
"gtceu.arc_furnace": "Arc Furnace",
"gtceu.assembler": "Assembler",
"gtceu.assembly_line": "Assembly Line",
"gtceu.auto_decomp.rotor": "Turbine Rotor",
"gtceu.auto_decomp.tool": "Non-electric tool",
"gtceu.autoclave": "Autoclave",
"gtceu.battery_buffer.average_input": "Average input: %s EU/t",
"gtceu.battery_buffer.average_output": "Average output: %s EU/t",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class GTToolType {
.toolStats(b -> b.attacking().attackDamage(3.0F).attackSpeed(-2.4F))
.constructor(GTSwordItem::create)
.toolClassNames("sword")
.materialAmount(2 * GTValues.M)
.build();
public static final GTToolType PICKAXE = GTToolType.builder("pickaxe")
.toolTag(TagUtil.createItemTag("pickaxes", true))
Expand All @@ -56,6 +57,7 @@ public class GTToolType {
.toolStats(b -> b.blockBreaking().attackDamage(1.0F).attackSpeed(-2.8F)
.behaviors(TorchPlaceBehavior.INSTANCE))
.toolClassNames("pickaxe")
.materialAmount(3 * GTValues.M)
.build();
public static final GTToolType SHOVEL = GTToolType.builder("shovel")
.toolTag(TagUtil.createItemTag("shovels", true))
Expand All @@ -64,6 +66,7 @@ public class GTToolType {
b -> b.blockBreaking().attackDamage(1.5F).attackSpeed(-3.0F).behaviors(GrassPathBehavior.INSTANCE))
.constructor(GTShovelItem::create)
.toolClassNames("shovel")
.materialAmount(GTValues.M)
.build();
public static final GTToolType AXE = GTToolType.builder("axe")
.toolTag(TagUtil.createItemTag("axes", true))
Expand All @@ -74,13 +77,15 @@ public class GTToolType {
ScrapeBehavior.INSTANCE, WaxOffBehavior.INSTANCE))
.constructor(GTAxeItem::create)
.toolClassNames("axe")
.materialAmount(3 * GTValues.M)
.build();
public static final GTToolType HOE = GTToolType.builder("hoe")
.toolTag(TagUtil.createItemTag("hoes", true))
.harvestTag(TagUtil.createBlockTag("mineable/hoe", true))
.toolStats(b -> b.cannotAttack().attackSpeed(-1.0F).behaviors(HoeGroundBehavior.INSTANCE))
.constructor(GTHoeItem::create)
.toolClassNames("hoe")
.materialAmount(2 * GTValues.M)
.build();

public static final GTToolType MINING_HAMMER = GTToolType.builder("mining_hammer")
Expand All @@ -91,6 +96,7 @@ public class GTToolType {
.durabilityMultiplier(3.0F)
.behaviors(TorchPlaceBehavior.INSTANCE))
.toolClasses(GTToolType.PICKAXE)
.materialAmount(6 * GTValues.M)
.build();
public static final GTToolType SPADE = GTToolType.builder("spade")
.toolTag(TagUtil.createItemTag("tools/spades", false))
Expand All @@ -100,6 +106,7 @@ public class GTToolType {
.durabilityMultiplier(3.0F)
.behaviors(GrassPathBehavior.INSTANCE))
.toolClasses(GTToolType.SHOVEL)
.materialAmount(3 * GTValues.M)
.build();
public static final GTToolType SCYTHE = GTToolType.builder("scythe")
.toolTag(TagUtil.createItemTag("tools/scythes", false))
Expand All @@ -112,6 +119,7 @@ public class GTToolType {
.constructor(GTHoeItem::create)
.toolClassNames("scythe")
.toolClasses(GTToolType.HOE)
.materialAmount(3 * GTValues.M)
.build();

public static final GTToolType SAW = GTToolType.builder("saw")
Expand All @@ -122,6 +130,7 @@ public class GTToolType {
.behaviors(HarvestIceBehavior.INSTANCE))
.sound(GTSoundEntries.SAW_TOOL)
.symbol('s')
.materialAmount(2 * GTValues.M)
.build();
public static final GTToolType HARD_HAMMER = GTToolType.builder("hammer")
.toolTag(TagUtil.createItemTag("tools/hammers", false))
Expand All @@ -133,13 +142,15 @@ public class GTToolType {
.sound(GTSoundEntries.FORGE_HAMMER)
.symbol('h')
.toolClasses(GTToolType.PICKAXE)
.materialAmount(6 * GTValues.M)
.build();
public static final GTToolType SOFT_MALLET = GTToolType.builder("mallet")
.toolTag(TagUtil.createItemTag("tools/mallets", false))
.toolStats(b -> b.crafting().cannotAttack().attackSpeed(-2.4F).sneakBypassUse()
.behaviors(ToolModeSwitchBehavior.INSTANCE))
.sound(GTSoundEntries.SOFT_MALLET_TOOL)
.symbol('r')
.materialAmount(6 * GTValues.M)
.build();
public static final GTToolType WRENCH = GTToolType.builder("wrench")
.toolTag(TagUtil.createItemTag("tools/wrenches", false))
Expand All @@ -151,13 +162,15 @@ public class GTToolType {
ToolModeSwitchBehavior.INSTANCE))
.sound(GTSoundEntries.WRENCH_TOOL, true)
.symbol('w')
.materialAmount(4 * GTValues.M)
.build();
public static final GTToolType FILE = GTToolType.builder("file")
.toolTag(TagUtil.createItemTag("tools/files", false))
.toolStats(b -> b.crafting().damagePerCraftingAction(4)
.cannotAttack().attackSpeed(-2.4F))
.sound(GTSoundEntries.FILE_TOOL)
.symbol('f')
.materialAmount(2 * GTValues.M)
.build();
public static final GTToolType CROWBAR = GTToolType.builder("crowbar")
.toolTag(TagUtil.createItemTag("tools/crowbars", false))
Expand All @@ -167,6 +180,7 @@ public class GTToolType {
.sneakBypassUse().behaviors(RotateRailBehavior.INSTANCE))
.sound(new ExistingSoundEntry(SoundEvents.ITEM_BREAK, SoundSource.BLOCKS), true)
.symbol('c')
.materialAmount(3 * GTValues.M / 2)
.build();
public static final GTToolType SCREWDRIVER = GTToolType.builder("screwdriver")
.toolTag(TagUtil.createItemTag("tools/screwdrivers", false))
Expand All @@ -175,12 +189,14 @@ public class GTToolType {
.behaviors(new EntityDamageBehavior(3.0F, Spider.class)))
.sound(GTSoundEntries.SCREWDRIVER_TOOL)
.symbol('d')
.materialAmount(GTValues.M)
.build();
public static final GTToolType MORTAR = GTToolType.builder("mortar")
.toolTag(TagUtil.createItemTag("tools/mortars", false))
.toolStats(b -> b.crafting().damagePerCraftingAction(2).cannotAttack().attackSpeed(-2.4F))
.sound(GTSoundEntries.MORTAR_TOOL)
.symbol('m')
.materialAmount(2 * GTValues.M)
.build();
public static final GTToolType WIRE_CUTTER = GTToolType.builder("wire_cutter")
.toolTag(TagUtil.createItemTag("tools/wire_cutters", false))
Expand All @@ -189,6 +205,7 @@ public class GTToolType {
.damagePerCraftingAction(4).attackDamage(-1.0F).attackSpeed(-2.4F))
.sound(GTSoundEntries.WIRECUTTER_TOOL, true)
.symbol('x')
.materialAmount(4 * GTValues.M) // 3 plates + 2 rods
.build();
public static final GTToolType KNIFE = GTToolType.builder("knife")
.toolTag(TagUtil.createItemTag("tools/knives", false))
Expand All @@ -197,12 +214,14 @@ public class GTToolType {
.constructor(GTSwordItem::create)
.symbol('k')
.toolClasses(GTToolType.SWORD)
.materialAmount(GTValues.M)
.build();
public static final GTToolType BUTCHERY_KNIFE = GTToolType.builder("butchery_knife")
.toolTag(TagUtil.createItemTag("tools/butchery_knives", false))
.toolStats(b -> b.attacking().attackDamage(1.5F).attackSpeed(-1.3F)
.defaultEnchantment(Enchantments.MOB_LOOTING, 3))
.constructor(GTSwordItem::create)
.materialAmount(4 * GTValues.M)
.build();
// public static GTToolType GRAFTER = new GTToolType("grafter", 1, 1, GTCEu.id("item/tools/handle_hammer"),
// GTCEu.id("item/tools/hammer"));
Expand Down Expand Up @@ -426,15 +445,16 @@ public class GTToolType {
public final SoundEntry soundEntry;
public final boolean playSoundOnBlockDestroy;
public final Character symbol;

public final long materialAmount;
public final IGTToolDefinition toolDefinition;
public final ToolConstructor constructor;
public final int electricTier;

public GTToolType(String name, String idFormat, Character symbol, Set<GTToolType> toolClasses,
IGTToolDefinition toolDefinition, ToolConstructor constructor, List<TagKey<Block>> harvestTags,
List<TagKey<Item>> itemTags, ResourceLocation modelLocation, Set<String> toolClassNames,
@Nullable SoundEntry soundEntry, boolean playSoundOnBlockDestroy, int electricTier) {
@Nullable SoundEntry soundEntry, boolean playSoundOnBlockDestroy, int electricTier,
long materialAmount) {
this.name = name;
this.idFormat = idFormat;
this.symbol = symbol;
Expand All @@ -449,6 +469,7 @@ public GTToolType(String name, String idFormat, Character symbol, Set<GTToolType
this.soundEntry = soundEntry;
this.playSoundOnBlockDestroy = playSoundOnBlockDestroy;
this.electricTier = electricTier;
this.materialAmount = materialAmount;

types.put(name, this);
}
Expand Down Expand Up @@ -488,6 +509,8 @@ public static class Builder {
@Setter
private IGTToolDefinition toolStats;
@Setter
private long materialAmount;
@Setter
private int tier = -1;
@Setter
private Character symbol = null;
Expand Down Expand Up @@ -562,7 +585,8 @@ private GTToolType get() {
toolClassNames,
sound,
playSoundOnBlockDestroy,
tier);
tier,
materialAmount);
}

public GTToolType build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import com.gregtechceu.gtceu.api.sound.ExistingSoundEntry;
import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank;
import com.gregtechceu.gtceu.common.machine.multiblock.electric.FusionReactorMachine;
import com.gregtechceu.gtceu.common.machine.trait.customlogic.BreweryLogic;
import com.gregtechceu.gtceu.common.machine.trait.customlogic.CannerLogic;
import com.gregtechceu.gtceu.common.machine.trait.customlogic.FormingPressLogic;
import com.gregtechceu.gtceu.common.machine.trait.customlogic.*;
import com.gregtechceu.gtceu.common.recipe.condition.RockBreakerCondition;
import com.gregtechceu.gtceu.data.recipe.RecipeHelper;
import com.gregtechceu.gtceu.data.recipe.builder.GTRecipeBuilder;
Expand Down Expand Up @@ -113,7 +111,8 @@ public class GTRecipeTypes {
.isEmpty()) {
recipeBuilder.inputFluids(GTMaterials.Oxygen.getFluid(recipeBuilder.duration));
}
});
})
.addCustomRecipeLogic(new ArcFurnaceLogic());

public final static GTRecipeType ASSEMBLER_RECIPES = register("assembler", ELECTRIC).setMaxIOSize(9, 1, 1, 0)
.setEUIO(IO.IN)
Expand Down Expand Up @@ -151,6 +150,7 @@ public class GTRecipeTypes {
.setProgressBar(GuiTextures.PROGRESS_BAR_MACERATE, LEFT_TO_RIGHT)
.setIconSupplier(() -> GTMachines.MACERATOR[GTValues.LV].asStack())
.setSteamProgressBar(GuiTextures.PROGRESS_BAR_MACERATE_STEAM, LEFT_TO_RIGHT)
.addCustomRecipeLogic(new MaceratorLogic())
.setSound(GTSoundEntries.MACERATOR);

public final static GTRecipeType CANNER_RECIPES = register("canner", ELECTRIC).setMaxIOSize(2, 2, 1, 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.gregtechceu.gtceu.common.machine.trait.customlogic;

import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.api.capability.recipe.IO;
import com.gregtechceu.gtceu.api.capability.recipe.IRecipeCapabilityHolder;
import com.gregtechceu.gtceu.api.capability.recipe.ItemRecipeCapability;
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey;
import com.gregtechceu.gtceu.api.item.IGTTool;
import com.gregtechceu.gtceu.api.item.tool.GTToolType;
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
import com.gregtechceu.gtceu.api.recipe.GTRecipeType;
import com.gregtechceu.gtceu.common.data.GTItems;
import com.gregtechceu.gtceu.common.data.GTMaterialItems;
import com.gregtechceu.gtceu.common.data.GTMaterials;
import com.gregtechceu.gtceu.common.item.TurbineRotorBehaviour;

import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.wrapper.CombinedInvWrapper;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Objects;

import static com.gregtechceu.gtceu.api.data.tag.TagPrefix.*;
import static com.gregtechceu.gtceu.common.data.GTRecipeTypes.ARC_FURNACE_RECIPES;

public class ArcFurnaceLogic implements GTRecipeType.ICustomRecipeLogic {

@Override
public @Nullable GTRecipe createCustomRecipe(IRecipeCapabilityHolder holder) {
var itemInputs = Objects
.requireNonNullElseGet(holder.getCapabilitiesProxy().get(IO.IN, ItemRecipeCapability.CAP),
ArrayList::new)
.stream()
.filter(IItemHandlerModifiable.class::isInstance)
.map(IItemHandlerModifiable.class::cast)
.toArray(IItemHandlerModifiable[]::new);

var inputs = new CombinedInvWrapper(itemInputs);
var stack = inputs.getStackInSlot(0);

var turbineBehaviour = TurbineRotorBehaviour.getBehaviour(stack);
if (turbineBehaviour != null) {
float durability = 1.f - (float) turbineBehaviour.getPartDamage(stack) /
(float) turbineBehaviour.getPartMaxDurability(stack);
return applyDurabilityRecipe("rotor_decomp", stack, turbineBehaviour.getPartMaterial(stack),
(float) (turbineBlade.materialAmount() * 8) / GTValues.M, durability, GTValues.VH[GTValues.EV], 1);
}

if (stack.getItem() instanceof IGTTool tool && !tool.isElectric()) {
float durability = (float) (tool.getTotalMaxDurability(stack) - stack.getDamageValue() + 1) /
(tool.getTotalMaxDurability(stack) + 1);
return applyDurabilityRecipe("tool_decomp", stack, tool.getMaterial(),
(float) (tool.getToolType().materialAmount / GTValues.M), durability,
GTValues.VH[GTValues.LV], 2);
}

return null;
}

public @Nullable GTRecipe applyDurabilityRecipe(String id, ItemStack inputStack, @NotNull Material mat,
float fullAmount, float durability, long voltage,
int durationFactor) {
if (!mat.hasProperty(PropertyKey.INGOT))
return null;

var material = mat.getProperty(PropertyKey.INGOT);
var materialArc = material.getArcSmeltingInto();

float outputAmount = (durability * fullAmount);
int dustAmount = (int) outputAmount;
int leftover = (int) ((outputAmount - (float) dustAmount) * 9.f);

if (dustAmount == 0 && leftover == 0)
return null;

var builder = ARC_FURNACE_RECIPES.recipeBuilder(id + "/" + mat.getName())
.inputItems(inputStack)
.inputFluids(GTMaterials.Oxygen.getFluid((int) (materialArc.getMass() * outputAmount) * durationFactor))
.EUt(voltage)
.duration((int) (materialArc.getMass() * outputAmount) * durationFactor);

if (dustAmount > 0) {
builder.outputItems(ingot, materialArc, dustAmount);
}
if (leftover > 0) {
builder.outputItems(nugget, materialArc, leftover);
}

return builder.buildRawRecipe();
}

@Override
public void buildRepresentativeRecipes() {
ItemStack stack = GTItems.TURBINE_ROTOR.asStack();
stack.setHoverName(Component.translatable("gtceu.auto_decomp.rotor"));
GTRecipe rotorRecipe;
GTRecipe pickaxeRecipe;
float durability = 0.69f;
// noinspection ConstantConditions
TurbineRotorBehaviour.getBehaviour(stack).setPartMaterial(stack, GTMaterials.Iron);
TurbineRotorBehaviour.getBehaviour(stack).setPartDamage(stack, 8928);
var turbineBehaviour = TurbineRotorBehaviour.getBehaviour(stack);

rotorRecipe = applyDurabilityRecipe("rotor_decomp", stack, turbineBehaviour.getPartMaterial(stack),
(float) (turbineBlade.materialAmount() * 8) / GTValues.M, durability, GTValues.VH[GTValues.EV], 1);
rotorRecipe.setId(rotorRecipe.getId().withPrefix("/"));

stack = GTMaterialItems.TOOL_ITEMS.get(GTMaterials.Iron, GTToolType.PICKAXE).asStack();
stack.setHoverName(Component.translatable("gtceu.auto_decomp.tool"));
stack.setDamageValue(79);
pickaxeRecipe = applyDurabilityRecipe("tool_decomp", stack, GTMaterials.Iron,
(float) (GTToolType.PICKAXE.materialAmount / GTValues.M), durability,
GTValues.VH[GTValues.LV], 2);

pickaxeRecipe.setId(pickaxeRecipe.getId().withPrefix("/"));
ARC_FURNACE_RECIPES.addToMainCategory(pickaxeRecipe);
ARC_FURNACE_RECIPES.addToMainCategory(rotorRecipe);
GTRecipeType.ICustomRecipeLogic.super.buildRepresentativeRecipes();
}
}
Loading
Loading