Skip to content

Commit f0fe6bd

Browse files
committed
Improved Auto Chisel processing speed.
1 parent dba2759 commit f0fe6bd

8 files changed

Lines changed: 207 additions & 73 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
# v1.3.3
2+
## Chisel Integration
3+
- Improved Auto Chisel processing speed.
4+
5+
* * *
6+
17
# v1.3.2
8+
29
## Storage Drawers Integration
310
- Fixed `stickLong` recipe for materials without `Ingot` or `Gem`.
411

512
* * *
13+
614
# v1.3.1
715
## Tinkers' Construct Integration
816
- Fixed TiC main-hand + GT off-hand combination not using the GT off-hand tool when it is the appropriate tool for the block

dependencies.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ dependencies {
6161
runtimeOnly rfg.deobf("curse.maven:better-builders-wands-238403:2691084")
6262
}
6363

64-
// Debug TiC
64+
// Debug TiC: 2.13.0.207
6565
compileOnly rfg.deobf("curse.maven:mantle-74924:2713386")
66-
compileOnly rfg.deobf("curse.maven:tinkers-antique-1242239:7339332")
66+
compileOnly rfg.deobf("curse.maven:tinkers-antique-1242239:7999105")
6767
if (project.debug_all.toBoolean() || project.debug_tic.toBoolean()) {
6868
runtimeOnly rfg.deobf("curse.maven:mantle-74924:2713386")
69-
runtimeOnly rfg.deobf("curse.maven:tinkers-antique-1242239:7339332")
69+
runtimeOnly rfg.deobf("curse.maven:tinkers-antique-1242239:7999105")
7070
}
7171

7272
// Debug Storage Drawers: 1.12-5.5.3

src/main/java/com/github/gtexpert/gtmt/integration/chisel/metatileentities/MetaTileEntityAutoChisel.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
package com.github.gtexpert.gtmt.integration.chisel.metatileentities;
22

3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.HashMap;
6+
import java.util.List;
7+
import java.util.Map;
38
import java.util.function.Function;
49
import java.util.function.Supplier;
510

11+
import net.minecraft.item.Item;
12+
import net.minecraft.item.ItemStack;
613
import net.minecraft.util.ResourceLocation;
14+
import net.minecraftforge.items.IItemHandlerModifiable;
715

816
import gregtech.api.GTValues;
917
import gregtech.api.capability.IEnergyContainer;
18+
import gregtech.api.capability.IMultipleTankHandler;
1019
import gregtech.api.metatileentity.MetaTileEntity;
1120
import gregtech.api.metatileentity.SimpleMachineMetaTileEntity;
1221
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
22+
import gregtech.api.recipes.Recipe;
1323
import gregtech.api.recipes.RecipeMap;
24+
import gregtech.api.recipes.ingredients.GTRecipeInput;
1425
import gregtech.client.renderer.ICubeRenderer;
1526

1627
import com.github.gtexpert.gtmt.api.capability.SingleblockRecipeLogicNoCache;
@@ -32,9 +43,60 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
3243

3344
private static class AutoChiselRecipeLogic extends SingleblockRecipeLogicNoCache {
3445

46+
// Shared across all AutoChisel instances — built once from the recipe map on first use.
47+
private static volatile Map<Item, List<Recipe>> inputIndex;
48+
private static final Object INDEX_LOCK = new Object();
49+
3550
public AutoChiselRecipeLogic(MetaTileEntity tileEntity, RecipeMap<?> recipeMap,
3651
Supplier<IEnergyContainer> energyContainer) {
3752
super(tileEntity, recipeMap, energyContainer);
3853
}
54+
55+
@Override
56+
protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs,
57+
IMultipleTankHandler fluidInputs) {
58+
Map<Item, List<Recipe>> idx = inputIndex;
59+
if (idx == null) {
60+
synchronized (INDEX_LOCK) {
61+
idx = inputIndex;
62+
if (idx == null) {
63+
inputIndex = idx = buildIndex(getRecipeMap());
64+
}
65+
}
66+
}
67+
68+
for (int i = 0; i < inputs.getSlots(); i++) {
69+
ItemStack stack = inputs.getStackInSlot(i);
70+
if (stack.isEmpty()) continue;
71+
72+
List<Recipe> candidates = idx.get(stack.getItem());
73+
if (candidates == null) return null;
74+
75+
for (Recipe recipe : candidates) {
76+
if (recipe.getEUt() <= maxVoltage &&
77+
recipe.matches(false, inputs, fluidInputs)) {
78+
return recipe;
79+
}
80+
}
81+
return null; // primary slot found but no match — stop scanning
82+
}
83+
return null;
84+
}
85+
86+
private static Map<Item, List<Recipe>> buildIndex(RecipeMap<?> recipeMap) {
87+
Map<Item, List<Recipe>> idx = new HashMap<>();
88+
for (Recipe recipe : recipeMap.getRecipeList()) {
89+
for (GTRecipeInput input : recipe.getInputs()) {
90+
if (input.isNonConsumable()) continue;
91+
for (ItemStack match : input.getInputStacks()) {
92+
idx.computeIfAbsent(match.getItem(), k -> new ArrayList<>()).add(recipe);
93+
}
94+
break; // index by first consumable input only
95+
}
96+
}
97+
// Wrap lists as unmodifiable to prevent accidental mutation
98+
idx.replaceAll((k, v) -> Collections.unmodifiableList(v));
99+
return Collections.unmodifiableMap(idx);
100+
}
39101
}
40102
}

src/main/java/com/github/gtexpert/gtmt/integration/tic/TiCClientEvents.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.gtexpert.gtmt.integration.tic;
22

3+
import net.minecraftforge.client.event.ModelBakeEvent;
34
import net.minecraftforge.client.event.ModelRegistryEvent;
45
import net.minecraftforge.client.event.TextureStitchEvent;
56
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@@ -8,29 +9,21 @@
89

910
import com.github.gtexpert.gtmt.integration.tic.materials.ToolMaterialRegistrar;
1011

11-
/**
12-
* Client-side event handlers for the TiC integration.
13-
*
14-
* <p>
15-
* Registered only on the client via {@link TiCModule#getEventBusSubscribers()}.
16-
*/
1712
@SideOnly(Side.CLIENT)
1813
public class TiCClientEvents {
1914

2015
@SubscribeEvent
2116
public static void onRegisterModels(ModelRegistryEvent event) {
2217
ToolMaterialRegistrar.registerFluidModels();
18+
ToolMaterialRegistrar.registerFluidBlockModelLoader();
19+
ToolMaterialRegistrar.suppressFluidBlockModels();
20+
}
21+
22+
@SubscribeEvent
23+
public static void onModelBake(ModelBakeEvent event) {
24+
ToolMaterialRegistrar.injectFluidItemModels(event.getModelRegistry());
2325
}
2426

25-
/**
26-
* Re-inject dynamic material name translations after every resource reload.
27-
*
28-
* <p>
29-
* {@link net.minecraft.util.text.translation.LanguageMap#inject} entries are wiped
30-
* whenever the language manager reloads (F3+T or in-game language change).
31-
* {@link TextureStitchEvent.Post} fires after the language map has already been
32-
* refreshed from disk, so this is the correct point to restore the dynamic entries.
33-
*/
3427
@SubscribeEvent
3528
public static void onTextureStitchPost(TextureStitchEvent.Post event) {
3629
ToolMaterialRegistrar.reinjectTranslations();

src/main/java/com/github/gtexpert/gtmt/integration/tic/TiCModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ public void registerBlocks(RegistryEvent.Register<Block> event) {
4343
ElasticMaterialRegistrar.register(event.getRegistry());
4444
TiCSmeltery.register();
4545
}
46+
4647
}

src/main/java/com/github/gtexpert/gtmt/integration/tic/materials/ElasticMaterialRegistrar.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import slimeknights.tconstruct.library.TinkerRegistry;
1717
import slimeknights.tconstruct.library.materials.BowStringMaterialStats;
1818
import slimeknights.tconstruct.library.materials.FletchingMaterialStats;
19+
import slimeknights.tconstruct.tools.TinkerTraits;
1920

2021
/**
2122
* Registers GT polymer materials as TiC BowString and Fletching part materials.
@@ -69,6 +70,15 @@ private static void registerElastic(Material gtMaterial,
6970
TinkerRegistry.addMaterialStats(ticMaterial,
7071
new FletchingMaterialStats(fletchAcc, fletchMod));
7172

73+
if (stringMod >= 1.1f) {
74+
ticMaterial.addTrait(TinkerTraits.momentum, "bowstring");
75+
} else if (stringMod >= 1.05f) {
76+
ticMaterial.addTrait(TinkerTraits.stiff, "bowstring");
77+
}
78+
if (fletchMod >= 1.05f) {
79+
ticMaterial.addTrait(TinkerTraits.heavy, "fletching");
80+
}
81+
7282
// Register whichever GT item forms exist for this material
7383
String suffix = gtMaterial.toCamelCaseString();
7484
for (OrePrefix prefix : new OrePrefix[] { OrePrefix.plate, OrePrefix.foil, OrePrefix.ring }) {
@@ -82,6 +92,7 @@ private static void registerElastic(Material gtMaterial,
8292
MaterialIntegration integration;
8393
if (fluid != null) {
8494
integration = new MaterialIntegration(ticMaterial, fluid, suffix);
95+
ToolMaterialRegistrar.trackIntegratedFluid(fluid);
8596
} else {
8697
integration = new MaterialIntegration(ticMaterial);
8798
for (OrePrefix prefix : new OrePrefix[] { OrePrefix.plate, OrePrefix.foil }) {

0 commit comments

Comments
 (0)