Skip to content

Commit e7b4f0a

Browse files
committed
仍然是解决硬编码...
新的本地化方法,在服务端时直接返回key,确保传输到客户端的仍然是key 重构了一下IData的get方法调用
1 parent 744b196 commit e7b4f0a

File tree

7 files changed

+440
-189
lines changed

7 files changed

+440
-189
lines changed

src/main/java/github/kasuminova/novaeng/common/hypernet/old/ComputationCenter.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import hellfirepvp.modularmachinery.common.machine.factory.FactoryRecipeThread;
1313
import hellfirepvp.modularmachinery.common.tiles.TileFactoryController;
1414
import hellfirepvp.modularmachinery.common.tiles.base.TileMultiblockMachineController;
15+
import lombok.Getter;
1516
import net.minecraft.nbt.NBTTagCompound;
1617
import net.minecraft.tileentity.TileEntity;
1718
import net.minecraft.util.math.BlockPos;
@@ -35,6 +36,7 @@
3536
public class ComputationCenter {
3637
private static final Map<TileMultiblockMachineController, ComputationCenter> CACHED_COMPUTATION_CENTER = new WeakHashMap<>();
3738

39+
@Getter
3840
private final TileMultiblockMachineController owner;
3941
private final Map<Class<?>, Map<BlockPos, NetNode>> nodes = new ConcurrentHashMap<>();
4042

@@ -43,6 +45,7 @@ public class ComputationCenter {
4345
// 计算点计数器,计算当前 Tick 总共消耗了多少算力。
4446
private final AtomicReference<Double> computationPointCounter = new AtomicReference<>(0D);
4547

48+
@Getter
4649
private UUID networkOwner = null;
4750

4851
private int circuitDurability = 0;
@@ -295,10 +298,6 @@ public void setCircuitDurability(final int circuitDurability) {
295298
writeNBT();
296299
}
297300

298-
public UUID getNetworkOwner() {
299-
return networkOwner;
300-
}
301-
302301
public void setNetworkOwner(final UUID networkOwner) {
303302
this.networkOwner = networkOwner;
304303
writeNBT();
@@ -339,7 +338,4 @@ public double getComputationPointConsumption() {
339338
return sum;
340339
}
341340

342-
public TileMultiblockMachineController getOwner() {
343-
return owner;
344-
}
345341
}

src/main/java/github/kasuminova/novaeng/common/integration/theoneprobe/HyperNetInfoProvider.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import net.minecraft.util.text.TextFormatting;
2727
import net.minecraft.world.World;
2828

29+
import static github.kasuminova.novaeng.common.crafttweaker.util.NovaEngUtils.formatPercent;
30+
2931
public class HyperNetInfoProvider implements IProbeInfoProvider {
3032
public static final HyperNetInfoProvider INSTANCE = new HyperNetInfoProvider();
3133

@@ -151,14 +153,14 @@ private static void processDataProcessorTOP(final DataProcessor processor,
151153
" / " + NovaEngUtils.formatFLOPS(maxGeneration));
152154

153155
leftInfo.text("{*top.hypernet.processor.load*}");
154-
rightInfo.text(TextFormatting.AQUA + NovaEngUtils.formatPercent(load, maxGeneration));
156+
rightInfo.text(TextFormatting.AQUA + formatPercent(load, maxGeneration));
155157

156158
leftInfo.text("{*top.hypernet.processor.efficiency*}");
157-
rightInfo.text(TextFormatting.GREEN + NovaEngUtils.formatPercent(efficiency, 1.0F));
159+
rightInfo.text(TextFormatting.GREEN + formatPercent(efficiency, 1.0F));
158160

159161
leftInfo.text("{*top.hypernet.processor.heat*}");
160162
rightInfo.text(TextFormatting.RED + MiscUtils.formatDecimal(storedHU) + "HU (" +
161-
NovaEngUtils.formatPercent(heatPercent, 1.0F) + ")");
163+
formatPercent(heatPercent, 1.0F) + ")");
162164
}
163165

164166
private static IProbeInfo newVertical(final IProbeInfo probeInfo) {
@@ -228,8 +230,10 @@ private static void processCenterTOP(final ComputationCenter center, final IProb
228230
{
229231
if (center.isWorking()) {
230232
probeInfo.text("{*top.hypernet.online*}");
233+
probeInfo.text("{*top.hypernet.processor.circuit_durability*}" + center.getCircuitDurability() + "(" + formatPercent(center.getCircuitDurability(), center.getType().getCircuitDurability()) + ")");
231234
} else {
232235
probeInfo.text("{*top.hypernet.offline*}");
236+
probeInfo.text("{*top.hypernet.processor.circuit_durability*}" + center.getCircuitDurability() + "(" + formatPercent(center.getCircuitDurability(), center.getType().getCircuitDurability()) + ")");
233237
return;
234238
}
235239

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ public static String getText(String key){
2323
if (NovaEngineeringCore.proxy.isClient()){
2424
return I18n.translateToLocal(key);
2525
}
26-
return "empty";
26+
return key;
2727
}
2828

2929
@ZenMethod
3030
public static String getText(String key,Object... objs){
3131
if (NovaEngineeringCore.proxy.isClient()){
3232
return I18n.translateToLocalFormatted(key, objs);
3333
}
34-
return "empty";
34+
return key;
3535
}
3636
}

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package github.kasuminova.novaeng.common.util;
22

33
import crafttweaker.annotations.ZenRegister;
4+
import crafttweaker.api.data.DataMap;
45
import crafttweaker.api.data.IData;
5-
import crafttweaker.api.minecraft.CraftTweakerMC;
6-
import net.minecraft.nbt.NBTTagCompound;
6+
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
77
import stanhebben.zenscript.annotations.Optional;
88
import stanhebben.zenscript.annotations.ZenExpansion;
99
import stanhebben.zenscript.annotations.ZenMethod;
@@ -15,104 +15,97 @@
1515
@ZenExpansion("crafttweaker.data.IData")
1616
public class IDataUtils {
1717

18-
private static NBTTagCompound get(IData data) {
19-
return get(data,"NULL");
20-
}
21-
22-
private static NBTTagCompound get(IData data,String path) {
23-
var datan = CraftTweakerMC.getNBT(data);
24-
if (datan instanceof NBTTagCompound nt){
25-
return nt;
18+
private static Map<String,IData> get(IData data) {
19+
if (data instanceof DataMap){
20+
return data.asMap();
2621
}
27-
var nbt = new NBTTagCompound();
28-
nbt.setTag(path,datan);
29-
return nbt;
22+
return Object2ObjectMaps.emptyMap();
3023
}
3124

3225
@ZenMethod
3326
public static IData get(IData data,String path,@Optional IData defaultValue) {
3427
if (check(data,path)){
35-
return CraftTweakerMC.getIData(get(data,path).getTag(path));
28+
return get(data).get(path);
3629
}
3730
return defaultValue;
3831
}
3932

4033
@ZenMethod
4134
public static boolean getBool(IData data, String path,@Optional boolean defaultValue){
4235
if (check(data,path)){
43-
return get(data,path).getBoolean(path);
36+
return get(data).get(path).asBool();
4437
}
4538
return defaultValue;
4639
}
4740

4841
@ZenMethod
4942
public static byte getByte(IData data, String path,@Optional byte defaultValue) {
5043
if (check(data,path)){
51-
return get(data,path).getByte(path);
44+
return get(data).get(path).asByte();
5245
}
5346
return defaultValue;
5447
}
5548

5649
@ZenMethod
5750
public static double getDouble(IData data, String path, @Optional double defaultValue) {
5851
if (check(data, path)) {
59-
return get(data,path).getDouble(path);
52+
return get(data).get(path).asDouble();
6053
}
6154
return defaultValue;
6255
}
6356

6457
@ZenMethod
6558
public static float getFloat(IData data, String path, @Optional float defaultValue) {
6659
if (check(data, path)) {
67-
return get(data,path).getFloat(path);
60+
return get(data).get(path).asFloat();
6861
}
6962
return defaultValue;
7063
}
7164

7265
@ZenMethod
7366
public static int getInt(IData data, String path, @Optional int defaultValue) {
7467
if (check(data, path)) {
75-
return get(data,path).getInteger(path);
68+
return get(data).get(path).asInt();
7669
}
7770
return defaultValue;
7871
}
7972

8073
@ZenMethod
8174
public static List<IData> getList(IData data, String path, @Optional List<IData> defaultValue) {
8275
if (check(data, path)) {
83-
return CraftTweakerMC.getIData(get(data,path).getTag(path)).asList();
76+
return get(data).get(path).asList();
8477
}
8578
return defaultValue;
8679
}
8780

8881
@ZenMethod
8982
public static long getLong(IData data, String path, @Optional long defaultValue) {
9083
if (check(data, path)) {
91-
return get(data,path).getLong(path);
84+
return get(data).get(path).asLong();
9285
}
9386
return defaultValue;
9487
}
9588

9689
@ZenMethod
9790
public static Map<String, IData> getMap(IData data, String path, @Optional Map<String, IData> defaultValue) {
9891
if (check(data, path)) {
99-
return CraftTweakerMC.getIData(get(data,path).getTag(path)).asMap();
92+
return get(data).get(path).asMap();
10093
}
10194
return defaultValue;
10295
}
10396

10497
@ZenMethod
10598
public static short getShort(IData data, String path, @Optional short defaultValue) {
10699
if (check(data, path)) {
107-
return get(data,path).getShort(path);
100+
return get(data).get(path).asShort();
108101
}
109102
return defaultValue;
110103
}
111104

112105
@ZenMethod
113106
public static String getString(IData data, String path, @Optional String defaultValue) {
114107
if (check(data, path)) {
115-
return get(data,path).getString(path);
108+
return get(data).get(path).asString();
116109
}
117110
return defaultValue;
118111
}
@@ -121,7 +114,7 @@ public static String getString(IData data, String path, @Optional String default
121114
public static boolean check(IData data, String... path){
122115
final var nbt = get(data);
123116
for (String key : path) {
124-
if (!nbt.hasKey(key)){
117+
if (!nbt.containsKey(key)){
125118
return false;
126119
}
127120
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import crafttweaker.annotations.ZenRegister;
55
import github.kasuminova.novaeng.NovaEngineeringCore;
66
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
7+
import it.unimi.dsi.fastutil.objects.ObjectLists;
78
import net.minecraft.util.text.translation.I18n;
89
import stanhebben.zenscript.annotations.ZenClass;
910
import stanhebben.zenscript.annotations.ZenMethod;
1011

1112
import java.util.Collection;
12-
import java.util.Collections;
1313
import java.util.List;
1414
import java.util.PriorityQueue;
1515
import java.util.stream.Collectors;
@@ -86,15 +86,15 @@ public static List<String> getText(String key) {
8686
var s = I18n.translateToLocal(key);
8787
return new ObjectArrayList<>(s.split("&n"));
8888
}
89-
return Collections.emptyList();
89+
return ObjectLists.singleton(key);
9090
}
9191

9292
public static List<String> getText(String key, Object... objs) {
9393
if (NovaEngineeringCore.proxy.isClient()) {
9494
var s = I18n.translateToLocalFormatted(key, objs);
9595
return new ObjectArrayList<>(s.split("&n"));
9696
}
97-
return Collections.emptyList();
97+
return ObjectLists.singleton(key);
9898
}
9999

100100
@Desugar

0 commit comments

Comments
 (0)