Skip to content

Commit e37d111

Browse files
committed
一些处理
1 parent b8ac279 commit e37d111

File tree

10 files changed

+105
-41
lines changed

10 files changed

+105
-41
lines changed

src/main/java/github/kasuminova/novaeng/client/book/BookTransformerAppendModifiers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class BookTransformerAppendModifiers extends SectionTransformer {
1919
private final boolean armour;
2020
private final List<Modifier> modCollector;
2121
public static BookTransformerAppendModifiers INSTANCE_FALSE = new BookTransformerAppendModifiers(new FileRepository("tconstruct:book"), false, Register.TRAITREGISTER.modifierTraitsF);
22-
public static BookTransformerAppendModifiers INSTANCE_TRUE= new BookTransformerAppendModifiers(new FileRepository("tconstruct:book"), true, Register.TRAITREGISTER.modifierTraitsT);
22+
public static BookTransformerAppendModifiers INSTANCE_TRUE = new BookTransformerAppendModifiers(new FileRepository("tconstruct:book"), true, Register.TRAITREGISTER.modifierTraitsT);
2323

2424
public BookTransformerAppendModifiers(BookRepository source, boolean armour, List<Modifier> modCollector) {
2525
super("modifiers");
@@ -42,4 +42,4 @@ public void transform(BookData book, SectionData section) {
4242
listing.addEntry(mod.getLocalizedName(), page);
4343
}
4444
}
45-
}
45+
}

src/main/java/github/kasuminova/novaeng/common/adapter/astralsorcery/AdapterStarlightInfuser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import github.kasuminova.mmce.common.event.recipe.RecipeCheckEvent;
88
import github.kasuminova.mmce.common.event.recipe.RecipeEvent;
99
import github.kasuminova.novaeng.common.machine.IllumPool;
10-
import github.kasuminova.novaeng.common.util.Function;
10+
import github.kasuminova.novaeng.common.util.Functions;
1111
import hellfirepvp.astralsorcery.common.crafting.ItemHandle;
1212
import hellfirepvp.astralsorcery.common.crafting.infusion.AbstractInfusionRecipe;
1313
import hellfirepvp.astralsorcery.common.crafting.infusion.InfusionRecipeRegistry;
@@ -111,10 +111,10 @@ public Collection<MachineRecipe> createRecipesFor(final ResourceLocation owningM
111111
if (event.phase != Phase.START) return;
112112
IllumPool.onRecipeTick(event, manaToConsume);
113113
});
114-
recipe.addTooltip(Function.getText("novaeng.illum_pool.input.mana", manaToConsume));
114+
recipe.addTooltip(Functions.getText("novaeng.illum_pool.input.mana", manaToConsume));
115115
addStarlightCatalystHandler(recipe);
116-
recipe.addTooltip(Function.getText("novaeng.illum_pool.illum_pool.mode",
117-
Function.getText("top.illum_pool.mode.d")));
116+
recipe.addTooltip(Functions.getText("novaeng.illum_pool.illum_pool.mode",
117+
Functions.getText("top.illum_pool.mode.d")));
118118
recipe.addTooltip("novaeng.illum_pool.input.illum");
119119

120120
recipes.add(recipe);

src/main/java/github/kasuminova/novaeng/common/adapter/botania/AdapterBotaniaManaPool.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import github.kasuminova.mmce.common.event.recipe.RecipeCheckEvent;
99
import github.kasuminova.mmce.common.event.recipe.RecipeEvent;
1010
import github.kasuminova.novaeng.common.machine.IllumPool;
11-
import github.kasuminova.novaeng.common.util.Function;
11+
import github.kasuminova.novaeng.common.util.Functions;
1212
import hellfirepvp.modularmachinery.common.crafting.MachineRecipe;
1313
import hellfirepvp.modularmachinery.common.crafting.adapter.RecipeAdapter;
1414
import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement;
@@ -79,14 +79,14 @@ public Collection<MachineRecipe> createRecipesFor(final ResourceLocation owningM
7979
if (event.phase != Phase.START) return;
8080
IllumPool.onRecipeTick(event, manaToConsume);
8181
});
82-
recipe.addTooltip(Function.getText("novaeng.illum_pool.input.mana",manaToConsume));
82+
recipe.addTooltip(Functions.getText("novaeng.illum_pool.input.mana",manaToConsume));
8383

8484
// Catalyst
8585
IBlockState catalyst = infusionRecipe.getCatalyst();
8686
if (catalyst == null) {
8787
addDefaultCatalystHandler(recipe);
88-
recipe.addTooltip(Function.getText("novaeng.illum_pool.illum_pool.mode",
89-
Function.getText("top.illum_pool.mode.e")));
88+
recipe.addTooltip(Functions.getText("novaeng.illum_pool.illum_pool.mode",
89+
Functions.getText("top.illum_pool.mode.e")));
9090
} else if (catalyst.equals(RecipeManaInfusion.conjurationState)) {
9191
recipe.addRecipeEventHandler(RecipeCheckEvent.class, (IEventHandler<RecipeCheckEvent>) event -> {
9292
if (event.phase != Phase.START) return;
@@ -95,8 +95,8 @@ public Collection<MachineRecipe> createRecipesFor(final ResourceLocation owningM
9595
event.setFailed("novaeng.illum_pool.failed.input");
9696
}
9797
});
98-
recipe.addTooltip(Function.getText("novaeng.illum_pool.illum_pool.mode",
99-
Function.getText("top.illum_pool.mode.b")));
98+
recipe.addTooltip(Functions.getText("novaeng.illum_pool.illum_pool.mode",
99+
Functions.getText("top.illum_pool.mode.b")));
100100
} else if (catalyst.equals(RecipeManaInfusion.alchemyState)) {
101101
recipe.addRecipeEventHandler(RecipeCheckEvent.class, (IEventHandler<RecipeCheckEvent>) event -> {
102102
if (event.phase != Phase.START) return;
@@ -105,8 +105,8 @@ public Collection<MachineRecipe> createRecipesFor(final ResourceLocation owningM
105105
event.setFailed("novaeng.illum_pool.failed.input");
106106
}
107107
});
108-
recipe.addTooltip(Function.getText("novaeng.illum_pool.illum_pool.mode",
109-
Function.getText("top.illum_pool.mode.a")));
108+
recipe.addTooltip(Functions.getText("novaeng.illum_pool.illum_pool.mode",
109+
Functions.getText("top.illum_pool.mode.a")));
110110
} else if (catalyst.equals(ExtraBotanyAPI.dimensionState)) {
111111
recipe.addRecipeEventHandler(RecipeCheckEvent.class, (IEventHandler<RecipeCheckEvent>) event -> {
112112
if (event.phase != Phase.START) return;
@@ -115,8 +115,8 @@ public Collection<MachineRecipe> createRecipesFor(final ResourceLocation owningM
115115
event.setFailed("novaeng.illum_pool.failed.input");
116116
}
117117
});
118-
recipe.addTooltip(Function.getText("novaeng.illum_pool.illum_pool.mode",
119-
Function.getText("top.illum_pool.mode.c")));
118+
recipe.addTooltip(Functions.getText("novaeng.illum_pool.illum_pool.mode",
119+
Functions.getText("top.illum_pool.mode.c")));
120120
} else {
121121
addDefaultCatalystHandler(recipe);
122122
}

src/main/java/github/kasuminova/novaeng/common/crafttweaker/expansion/RecipePrimerIllumPool.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import crafttweaker.annotations.ZenRegister;
44
import github.kasuminova.novaeng.common.crafttweaker.util.NovaEngUtils;
55
import github.kasuminova.novaeng.common.machine.IllumPool;
6-
import github.kasuminova.novaeng.common.util.Function;
6+
import github.kasuminova.novaeng.common.util.Functions;
77
import hellfirepvp.modularmachinery.common.integration.crafttweaker.RecipePrimer;
88
import stanhebben.zenscript.annotations.ZenExpansion;
99
import stanhebben.zenscript.annotations.ZenMethod;
@@ -16,15 +16,15 @@ public class RecipePrimerIllumPool {
1616
public static RecipePrimer addIllumPoolManaAddHandler(RecipePrimer primer, int amount) {
1717
primer.addPreCheckHandler(event -> IllumPool.onAddManaRecipeCheck(event, amount));
1818
primer.addFactoryPreTickHandler(event -> IllumPool.onAddManaRecipeTick(event, amount));
19-
primer.addRecipeTooltip(Function.getText("novaeng.illum_pool.recipe.mana", NovaEngUtils.formatDecimal(amount)));
19+
primer.addRecipeTooltip(Functions.getText("novaeng.illum_pool.recipe.mana", NovaEngUtils.formatDecimal(amount)));
2020
return primer;
2121
}
2222

2323
@ZenMethod
2424
public static RecipePrimer addIllumPoolIllumAddHandler(RecipePrimer primer, int amount) {
2525
primer.addPreCheckHandler(event -> IllumPool.onAddIllumRecipeCheck(event, amount));
2626
primer.addFactoryPreTickHandler(event -> IllumPool.onAddIllumRecipeTick(event, amount));
27-
primer.addRecipeTooltip(Function.getText("novaeng.illum_pool.recipe.illum", NovaEngUtils.formatDecimal(amount)));
27+
primer.addRecipeTooltip(Functions.getText("novaeng.illum_pool.recipe.illum", NovaEngUtils.formatDecimal(amount)));
2828
return primer;
2929
}
3030

src/main/java/github/kasuminova/novaeng/common/machine/IllumPool.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import github.kasuminova.mmce.common.event.recipe.FactoryRecipeTickEvent;
66
import github.kasuminova.mmce.common.event.recipe.RecipeCheckEvent;
77
import github.kasuminova.novaeng.common.crafttweaker.util.NovaEngUtils;
8-
import github.kasuminova.novaeng.common.util.Function;
8+
import github.kasuminova.novaeng.common.util.Functions;
99
import github.kasuminova.novaeng.common.util.RandomUtils;
1010
import github.kasuminova.novaeng.common.util.StringUtils;
1111
import hellfirepvp.astralsorcery.AstralSorcery;
@@ -64,7 +64,7 @@ public class IllumPool implements MachineSpecial {
6464
* x x x x x
6565
* x x x
6666
*/
67-
public static final List<BlockPos> CATALYST_POS_PRESET = Function.asList(
67+
public static final List<BlockPos> CATALYST_POS_PRESET = Functions.asList(
6868
withXZ(1, 1), withXZ(0, 1), withXZ(-1, 1),
6969
withXZ(2, 2), withXZ(1, 2), withXZ(0, 2), withXZ(-1, 2), withXZ(-2, 2),
7070
withXZ(2, 3), withXZ(1, 3), withXZ(0, 3), withXZ(-1, 3), withXZ(-2, 3),
@@ -80,7 +80,7 @@ public class IllumPool implements MachineSpecial {
8080
* x x x x x x x
8181
* c x x x x x c
8282
*/
83-
public static final List<BlockPos> CRYSTAL_POS_PRESET = Function.asList(
83+
public static final List<BlockPos> CRYSTAL_POS_PRESET = Functions.asList(
8484
new BlockPos(3, 2, 6), new BlockPos(-3, 2, 6),
8585
new BlockPos(3, 2, 0), new BlockPos(-3, 2, 0)
8686
);

src/main/java/github/kasuminova/novaeng/common/trait/Register.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package github.kasuminova.novaeng.common.trait;
22

3-
import com.google.common.collect.Lists;
43
import github.kasuminova.novaeng.common.enchantment.MagicBreaking;
54
import github.kasuminova.novaeng.common.item.ItemBasic;
5+
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
66
import slimeknights.tconstruct.library.modifiers.Modifier;
77
import slimeknights.tconstruct.tools.AbstractToolPulse;
88

@@ -11,8 +11,8 @@
1111
public class Register extends AbstractToolPulse {
1212

1313
public static Register TRAITREGISTER = new Register();
14-
public List<Modifier> modifierTraitsF = Lists.newLinkedList();
15-
public List<Modifier> modifierTraitsT = Lists.newLinkedList();
14+
public List<Modifier> modifierTraitsF = new ObjectArrayList<>();
15+
public List<Modifier> modifierTraitsT = new ObjectArrayList<>();
1616

1717
public void registerModifiers() {
1818
TraitMagicBreaking traitMagicBreaking = registerModifier(new TraitMagicBreaking());

src/main/java/github/kasuminova/novaeng/common/util/Function.java renamed to src/main/java/github/kasuminova/novaeng/common/util/Functions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
@ZenRegister
3838
@ZenClass("novaeng.Function")
39-
public class Function {
39+
public class Functions {
4040

4141
@SafeVarargs
4242
public static <T> ObjectList<T> asList(T... s){

src/main/java/github/kasuminova/novaeng/common/util/SimpleItem.java

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,59 @@
11
package github.kasuminova.novaeng.common.util;
22

33
import com.github.bsideup.jabel.Desugar;
4+
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
5+
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
6+
import it.unimi.dsi.fastutil.objects.Reference2ObjectMaps;
7+
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
48
import net.minecraft.item.Item;
59
import net.minecraft.item.ItemStack;
610
import net.minecraft.nbt.NBTTagCompound;
711

12+
import java.util.Map;
813
import java.util.Objects;
14+
import java.util.concurrent.ConcurrentHashMap;
15+
import java.util.function.Function;
916

1017
@Desugar
1118
public record SimpleItem(Item item, int meta, NBTTagCompound nbt) {
1219

13-
public static SimpleItem getInstance(ItemStack stack) {
14-
return new SimpleItem(stack.getItem(), stack.getMetadata(), stack.getTagCompound());
20+
private static final NBTTagCompound NullNbt = new NBTTagCompound() {
21+
@Override
22+
public boolean equals(Object nbt) {
23+
return nbt == this;
24+
}
25+
26+
@Override
27+
public int hashCode() {
28+
return Integer.MIN_VALUE;
29+
}
30+
};
31+
32+
private SimpleItem(ItemStack stack) {
33+
this(stack.getItem(), stack.getItemDamage(), stack.getTagCompound());
34+
}
35+
36+
public static final SimpleItem empty = new SimpleItem(ItemStack.EMPTY);
37+
private static final Reference2ObjectMap<Item, Int2ObjectOpenHashMapS> chane = Reference2ObjectMaps.synchronize(new Reference2ObjectOpenHashMap<>());
38+
private static final Function<Item, Int2ObjectOpenHashMapS> intMap = item -> new Int2ObjectOpenHashMapS();
39+
40+
public static SimpleItem getInstance(final ItemStack stack) {
41+
if (stack.isEmpty()) return empty;
42+
var nbt = stack.getTagCompound();
43+
return chane.computeIfAbsent(stack.getItem(), intMap)
44+
.computeIfAbsent(stack.getItemDamage())
45+
.computeIfAbsent(nbt == null ? NullNbt : nbt, n -> new SimpleItem(stack));
46+
}
47+
48+
public static SimpleItem getNoNBTInstance(final ItemStack stack) {
49+
if (stack.isEmpty()) return empty;
50+
return chane.computeIfAbsent(stack.getItem(), intMap)
51+
.computeIfAbsent(stack.getItemDamage())
52+
.computeIfAbsent(NullNbt, n -> new SimpleItem(stack));
53+
}
54+
55+
public boolean isEmpty() {
56+
return this == empty;
1557
}
1658

1759
@Override
@@ -28,4 +70,23 @@ public int hashCode() {
2870
result = 31 * result + (nbt != null ? nbt.hashCode() : 0);
2971
return result;
3072
}
31-
}
73+
74+
private static class Int2ObjectOpenHashMapS extends Int2ObjectOpenHashMap<Map<NBTTagCompound, SimpleItem>> {
75+
76+
public Map<NBTTagCompound, SimpleItem> computeIfAbsent(int key) {
77+
Map<NBTTagCompound, SimpleItem> v;
78+
79+
if ((v = get(key)) == null) {
80+
synchronized (this) {
81+
if ((v = get(key)) == null) {
82+
v = new ConcurrentHashMap<>();
83+
put(key, v);
84+
}
85+
}
86+
}
87+
88+
return v;
89+
}
90+
91+
}
92+
}

src/main/java/github/kasuminova/novaeng/common/util/StringUtils.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,26 @@ public static List<String> sortWithMatchRate(final Collection<String> source, fi
3636
for (final String s : source) {
3737
String str = s.replace(" ", "").toLowerCase();
3838

39-
char[] targetCharArr = str.toCharArray();
40-
41-
int matchRate = getMatchRate(filterCharArr, targetCharArr);
39+
int matchRate = getMatchRate(filterCharArr, str);
4240
if (matchRate > 0) {
4341
sorted.add(new MatchResult(s, matchRate));
4442
}
4543
}
4644

47-
return sorted.stream().map(e -> e.str).collect(Collectors.toList());
45+
return sorted.stream().map(e -> e.str).collect(Collectors.toCollection(ObjectArrayList::new));
4846
}
4947

50-
private static int getMatchRate(final char[] filterCharArr, final char[] targetCharArr) {
48+
private static int getMatchRate(final char[] filterCharArr, final String targetCharArr) {
5149
int matchRate = 0;
5250
int matchedCharCount = 0;
5351
int targetIndex = 0;
5452

5553
filter:
56-
for (final char c : filterCharArr) {
57-
for (int i = targetIndex; i < targetCharArr.length; i++) {
58-
char tc = targetCharArr[i];
54+
for (char c : filterCharArr) {
55+
for (int i = targetIndex; i < targetCharArr.length(); i++) {
56+
char tc = targetCharArr.charAt(i);
5957
if (c == tc) {
60-
matchRate += targetCharArr.length - targetIndex + 1;
58+
matchRate += targetCharArr.length() - targetIndex + 1;
6159

6260
targetIndex++;
6361
matchedCharCount++;
@@ -66,7 +64,7 @@ private static int getMatchRate(final char[] filterCharArr, final char[] targetC
6664
}
6765
}
6866

69-
if (targetCharArr.length >= filterCharArr.length && matchedCharCount == filterCharArr.length) {
67+
if (targetCharArr.length() >= filterCharArr.length && matchedCharCount == filterCharArr.length) {
7068
return Integer.MAX_VALUE;
7169
}
7270
return matchRate;
@@ -98,6 +96,11 @@ public static List<String> getText(String key, Object... objs) {
9896
return ObjectLists.singleton(key);
9997
}
10098

99+
/**
100+
* @param str 驼峰结构的字符串
101+
* @return 蛇形结构的字符串
102+
*/
103+
@ZenMethod
101104
@NotNull
102105
public static String camelToSnake(@NotNull String str) {
103106
if (str == null || str.isEmpty()) return str;
@@ -115,7 +118,7 @@ public static String camelToSnake(@NotNull String str) {
115118
if (prevWasLower) {
116119
buffer[index++] = '_';
117120
}
118-
buffer[index++] = (char)(c + 32);
121+
buffer[index++] = (char) (c + 32);
119122
prevWasLower = false;
120123
} else {
121124
buffer[index++] = c;

src/main/resources/mixins.novaeng_core_ae2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
],
1515
"mixins": [
1616
"AccessorAbstractCellInventory",
17+
"AccessorCellRegistry",
1718
"AccessorContainerPatternEncoder",
1819
"MixinAppEngServerPacketHandler",
19-
"AccessorCellRegistry",
2020
"MixinCraftingCPUCluster",
2121
"MixinCraftingCPUClusterTwo",
2222
"MixinCraftingCPUClusterTwo$AccessorTaskProgress",

0 commit comments

Comments
 (0)