Skip to content

Commit ed7fdb6

Browse files
committed
- EC 内容完善。
- 其他内容更新。
1 parent e156b68 commit ed7fdb6

File tree

41 files changed

+625
-291
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+625
-291
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212

1313
// Project properties
1414
group = "github.kasuminova.novaeng"
15-
version = "1.20.0"
15+
version = "1.20.1"
1616

1717
// Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod
1818
java {

src/main/java/github/kasuminova/novaeng/client/gui/widget/ecalculator/CPUStatusPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public CPUStatus(final ECalculatorData.ThreadCoreData core) {
131131
final boolean hyper = core.maxHyperThreads() > 0;
132132
final boolean working = core.threads() > 0;
133133
this.hyper = hyper;
134-
this.cpus = core.threads();
134+
this.cpus = core.threads() + core.hyperThreads();
135135
this.maxThreads = core.maxThreads();
136136
this.maxHyperThreads = core.maxHyperThreads();
137137
switch (core.type()) {

src/main/java/github/kasuminova/novaeng/client/gui/widget/ecalculator/MonitorPanel.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,14 @@ public void render(final WidgetGui gui, final RenderSize renderSize, final Rende
154154

155155
// Total Parallelism
156156
GlStateManager.pushMatrix();
157-
GlStateManager.translate(53, 56, 0);
157+
if (this.totalParallelism >= 100_000) {
158+
GlStateManager.translate(53, 56 + 1, 0);
159+
GlStateManager.scale(.8F, .8F, .8F);
160+
} else {
161+
GlStateManager.translate(53, 56, 0);
162+
}
158163
{
159-
final String totalParallelism = String.format("%d", this.totalParallelism);
164+
final String totalParallelism = String.valueOf(this.totalParallelism);
160165
fr.drawStringWithShadow(totalParallelism, 0, 0, 0xFFFFFF);
161166
}
162167
GlStateManager.popMatrix();
@@ -291,6 +296,9 @@ protected void renderInternal(final WidgetGui gui, final RenderSize renderSize,
291296
GlStateManager.pushMatrix();
292297
GlStateManager.translate(renderPos.posX() + 24, renderPos.posY() + 2, 0);
293298
{
299+
MEMORY_ICON.render(new RenderPos(0, 0), gui);
300+
PARALLELISM_ICON.render(new RenderPos(0, 8), gui);
301+
294302
GlStateManager.pushMatrix();
295303
GlStateManager.scale(.8F, .8F, .8F);
296304
{
@@ -302,10 +310,6 @@ protected void renderInternal(final WidgetGui gui, final RenderSize renderSize,
302310
fr.drawStringWithShadow(cpuUsage, width - strWidth, 19, 0xFFFFFFFF);
303311
}
304312
GlStateManager.popMatrix();
305-
{
306-
MEMORY_ICON.render(new RenderPos(0, 1), gui);
307-
PARALLELISM_ICON.render(new RenderPos(0, 9), gui);
308-
}
309313
}
310314
GlStateManager.popMatrix();
311315
}

src/main/java/github/kasuminova/novaeng/common/block/ecotech/ecalculator/BlockECalculatorController.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import net.minecraft.tileentity.TileEntity;
1717
import net.minecraft.util.EnumFacing;
1818
import net.minecraft.util.EnumHand;
19-
import net.minecraft.util.NonNullList;
2019
import net.minecraft.util.ResourceLocation;
2120
import net.minecraft.util.math.BlockPos;
2221
import net.minecraft.world.IBlockAccess;
@@ -69,10 +68,6 @@ public IBlockState getActualState(@Nonnull IBlockState state, @Nonnull IBlockAcc
6968
return state;
7069
}
7170

72-
@Override
73-
public void getDrops(@Nonnull final NonNullList<ItemStack> drops, @Nonnull final IBlockAccess world, @Nonnull final BlockPos pos, @Nonnull final IBlockState state, final int fortune) {
74-
}
75-
7671
@Override
7772
public void breakBlock(World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
7873
Random rand = worldIn.rand;
@@ -98,8 +93,7 @@ public void breakBlock(World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockStat
9893
spawnAsEntity(worldIn, pos, stackCtrl);
9994
}
10095

101-
// TODO MM warn.
102-
super.breakBlock(worldIn, pos, state);
96+
worldIn.removeTileEntity(pos);
10397
}
10498

10599
@Override

src/main/java/github/kasuminova/novaeng/common/block/ecotech/ecalculator/BlockECalculatorParallelProc.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
@SuppressWarnings("deprecation")
2525
public class BlockECalculatorParallelProc extends BlockECalculatorPart {
2626

27-
public static final BlockECalculatorParallelProc L4 = new BlockECalculatorParallelProc("l4", 64);
28-
public static final BlockECalculatorParallelProc L6 = new BlockECalculatorParallelProc("l6", 512);
29-
public static final BlockECalculatorParallelProc L9 = new BlockECalculatorParallelProc("l9", 4096);
27+
public static final BlockECalculatorParallelProc L4 = new BlockECalculatorParallelProc("l4", 256);
28+
public static final BlockECalculatorParallelProc L6 = new BlockECalculatorParallelProc("l6", 2048);
29+
public static final BlockECalculatorParallelProc L9 = new BlockECalculatorParallelProc("l9", 16384);
3030

3131
protected final int parallelism;
3232

src/main/java/github/kasuminova/novaeng/common/block/ecotech/ecalculator/BlockECalculatorThreadCore.java

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
package github.kasuminova.novaeng.common.block.ecotech.ecalculator;
22

3+
import appeng.me.cluster.implementations.CraftingCPUCluster;
4+
import github.kasuminova.mmce.common.util.Sides;
35
import github.kasuminova.novaeng.NovaEngineeringCore;
46
import github.kasuminova.novaeng.common.block.ecotech.ecalculator.prop.Levels;
57
import github.kasuminova.novaeng.common.block.ecotech.ecalculator.prop.ThreadCoreStatus;
68
import github.kasuminova.novaeng.common.block.prop.FacingProp;
9+
import github.kasuminova.novaeng.common.item.ecalculator.ItemECalculatorThreadCore;
710
import github.kasuminova.novaeng.common.tile.ecotech.ecalculator.ECalculatorThreadCore;
811
import net.minecraft.block.material.Material;
912
import net.minecraft.block.state.BlockStateContainer;
1013
import net.minecraft.block.state.IBlockState;
1114
import net.minecraft.entity.EntityLivingBase;
15+
import net.minecraft.item.ItemStack;
16+
import net.minecraft.nbt.CompressedStreamTools;
17+
import net.minecraft.nbt.NBTTagCompound;
1218
import net.minecraft.tileentity.TileEntity;
1319
import net.minecraft.util.EnumFacing;
20+
import net.minecraft.util.NonNullList;
1421
import net.minecraft.util.ResourceLocation;
1522
import net.minecraft.util.Rotation;
1623
import net.minecraft.util.math.BlockPos;
@@ -19,6 +26,10 @@
1926
import org.jetbrains.annotations.Nullable;
2027

2128
import javax.annotation.Nonnull;
29+
import java.io.ByteArrayInputStream;
30+
import java.io.ByteArrayOutputStream;
31+
import java.io.IOException;
32+
import java.util.List;
2233

2334
@SuppressWarnings("deprecation")
2435
public class BlockECalculatorThreadCore extends BlockECalculatorPart {
@@ -29,6 +40,7 @@ public class BlockECalculatorThreadCore extends BlockECalculatorPart {
2940

3041
protected final int threads;
3142
protected final int hyperThreads;
43+
protected ItemECalculatorThreadCore item = null;
3244

3345
protected BlockECalculatorThreadCore(final ResourceLocation registryName, final String translationKey, final int threads, final int hyperThreads) {
3446
super(Material.IRON);
@@ -42,6 +54,15 @@ protected BlockECalculatorThreadCore(final ResourceLocation registryName, final
4254
);
4355
}
4456

57+
public ItemECalculatorThreadCore getItem() {
58+
return item;
59+
}
60+
61+
public BlockECalculatorThreadCore setItem(final ItemECalculatorThreadCore item) {
62+
this.item = item;
63+
return this;
64+
}
65+
4566
public int getThreads() {
4667
return threads;
4768
}
@@ -70,13 +91,89 @@ public TileEntity createTileEntity(@Nonnull final World world, @Nonnull final IB
7091
return new ECalculatorThreadCore(this.threads, this.hyperThreads);
7192
}
7293

94+
@Override
95+
public void dropBlockAsItemWithChance(@Nonnull final World worldIn, @Nonnull final BlockPos pos, @Nonnull final IBlockState state, final float chance, final int fortune) {
96+
}
97+
98+
@Override
99+
public void getDrops(@Nonnull final NonNullList<ItemStack> drops, @Nonnull final IBlockAccess world, @Nonnull final BlockPos pos, @Nonnull final IBlockState state, final int fortune) {
100+
}
101+
73102
@Override
74103
public void breakBlock(@Nonnull final World worldIn, @Nonnull final BlockPos pos, @Nonnull final IBlockState state) {
75104
TileEntity te = worldIn.getTileEntity(pos);
76-
if (te instanceof ECalculatorThreadCore threadCore) {
77-
threadCore.onBlockDestroyed();
105+
ItemStack dropped = new ItemStack(item);
106+
107+
if (te == null || Sides.isRunningOnClient()) {
108+
spawnAsEntity(worldIn, pos, dropped);
109+
worldIn.removeTileEntity(pos);
110+
return;
111+
}
112+
if (!(te instanceof final ECalculatorThreadCore threadCore)) {
113+
spawnAsEntity(worldIn, pos, dropped);
114+
worldIn.removeTileEntity(pos);
115+
return;
116+
}
117+
final List<CraftingCPUCluster> cpus = threadCore.getCpus();
118+
if (cpus.isEmpty()) {
119+
spawnAsEntity(worldIn, pos, dropped);
120+
worldIn.removeTileEntity(pos);
121+
return;
122+
}
123+
124+
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
125+
final NBTTagCompound tag = new NBTTagCompound();
126+
threadCore.writeCPUNBT(tag);
127+
128+
try {
129+
CompressedStreamTools.writeCompressed(tag, bos);
130+
} catch (IOException e) {
131+
NovaEngineeringCore.log.error("Failed to write CPU NBT to byte array!", e);
132+
spawnAsEntity(worldIn, pos, dropped);
133+
worldIn.removeTileEntity(pos);
134+
return;
135+
} finally {
136+
cpus.clear();
137+
}
138+
139+
NBTTagCompound itemTag = new NBTTagCompound();
140+
itemTag.setByteArray("compressedCpuNBT", bos.toByteArray());
141+
dropped.setTagCompound(itemTag);
142+
threadCore.onBlockDestroyed();
143+
144+
try {
145+
bos.close();
146+
} catch (IOException e) {
147+
NovaEngineeringCore.log.error("Failed to close byte array streams!", e);
148+
}
149+
150+
spawnAsEntity(worldIn, pos, dropped);
151+
worldIn.removeTileEntity(pos);
152+
}
153+
154+
@Override
155+
public void onBlockPlacedBy(@Nonnull final World worldIn,
156+
@Nonnull final BlockPos pos,
157+
@Nonnull final IBlockState state,
158+
@Nonnull final EntityLivingBase placer,
159+
@Nonnull final ItemStack stack)
160+
{
161+
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
162+
163+
TileEntity te = worldIn.getTileEntity(pos);
164+
NBTTagCompound tag = stack.getTagCompound();
165+
if (te instanceof final ECalculatorThreadCore threadCore && tag != null && tag.hasKey("compressedCpuNBT")) {
166+
byte[] cpuNBTBytes = tag.getByteArray("compressedCpuNBT");
167+
if (cpuNBTBytes.length == 0) {
168+
return;
169+
}
170+
try (ByteArrayInputStream bis = new ByteArrayInputStream(cpuNBTBytes)) {
171+
NBTTagCompound cpuNBT = CompressedStreamTools.readCompressed(bis);
172+
threadCore.readCPUNBT(cpuNBT);
173+
} catch (IOException e) {
174+
NovaEngineeringCore.log.error("Failed to read CPU NBT from byte array!", e);
175+
}
78176
}
79-
super.breakBlock(worldIn, pos, state);
80177
}
81178

82179
@Nonnull

src/main/java/github/kasuminova/novaeng/common/block/ecotech/efabricator/BlockEFabricatorController.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import net.minecraft.tileentity.TileEntity;
1717
import net.minecraft.util.EnumFacing;
1818
import net.minecraft.util.EnumHand;
19-
import net.minecraft.util.NonNullList;
2019
import net.minecraft.util.ResourceLocation;
2120
import net.minecraft.util.math.BlockPos;
2221
import net.minecraft.world.IBlockAccess;
@@ -69,26 +68,6 @@ public IBlockState getActualState(@Nonnull IBlockState state, @Nonnull IBlockAcc
6968
return state;
7069
}
7170

72-
@Override
73-
public void getDrops(@Nonnull final NonNullList<ItemStack> drops, @Nonnull final IBlockAccess world, @Nonnull final BlockPos pos, @Nonnull final IBlockState state, final int fortune) {
74-
// Random rand = world instanceof World ? ((World) world).rand : RANDOM;
75-
//
76-
// TileEntity te = world.getTileEntity(pos);
77-
// if (te instanceof EFabricatorController ctrl && ctrl.getOwner() != null) {
78-
// UUID ownerUUID = ctrl.getOwner();
79-
// Item dropped = getItemDropped(state, rand, fortune);
80-
// ItemStack stackCtrl = new ItemStack(dropped, 1);
81-
// if (ownerUUID != null) {
82-
// NBTTagCompound tag = new NBTTagCompound();
83-
// tag.setString("owner", ownerUUID.toString());
84-
// stackCtrl.setTagCompound(tag);
85-
// }
86-
// drops.add(stackCtrl);
87-
// } else {
88-
// super.getDrops(drops, world, pos, state, fortune);
89-
// }
90-
}
91-
9271
@Override
9372
public void breakBlock(World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
9473
Random rand = worldIn.rand;
@@ -114,8 +93,7 @@ public void breakBlock(World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockStat
11493
spawnAsEntity(worldIn, pos, stackCtrl);
11594
}
11695

117-
// TODO MM warn.
118-
super.breakBlock(worldIn, pos, state);
96+
worldIn.removeTileEntity(pos);
11997
}
12098

12199
@Override

src/main/java/github/kasuminova/novaeng/common/block/ecotech/estorage/BlockEStorageController.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
import net.minecraft.tileentity.TileEntity;
1717
import net.minecraft.util.EnumFacing;
1818
import net.minecraft.util.EnumHand;
19-
import net.minecraft.util.NonNullList;
2019
import net.minecraft.util.ResourceLocation;
2120
import net.minecraft.util.math.AxisAlignedBB;
2221
import net.minecraft.util.math.BlockPos;
23-
import net.minecraft.world.IBlockAccess;
2422
import net.minecraft.world.World;
2523

2624
import javax.annotation.Nonnull;
@@ -63,26 +61,6 @@ public BlockEStorageController(final String level) {
6361
setTranslationKey(NovaEngineeringCore.MOD_ID + '.' + registryName.getPath());
6462
}
6563

66-
@Override
67-
public void getDrops(@Nonnull final NonNullList<ItemStack> drops, @Nonnull final IBlockAccess world, @Nonnull final BlockPos pos, @Nonnull final IBlockState state, final int fortune) {
68-
// Random rand = world instanceof World ? ((World) world).rand : RANDOM;
69-
//
70-
// TileEntity te = world.getTileEntity(pos);
71-
// if (te instanceof EStorageController ctrl && ctrl.getOwner() != null) {
72-
// UUID ownerUUID = ctrl.getOwner();
73-
// Item dropped = getItemDropped(state, rand, fortune);
74-
// ItemStack stackCtrl = new ItemStack(dropped, 1);
75-
// if (ownerUUID != null) {
76-
// NBTTagCompound tag = new NBTTagCompound();
77-
// tag.setString("owner", ownerUUID.toString());
78-
// stackCtrl.setTagCompound(tag);
79-
// }
80-
// drops.add(stackCtrl);
81-
// } else {
82-
// super.getDrops(drops, world, pos, state, fortune);
83-
// }
84-
}
85-
8664
@Override
8765
public void breakBlock(World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
8866
Random rand = worldIn.rand;
@@ -108,8 +86,7 @@ public void breakBlock(World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockStat
10886
spawnAsEntity(worldIn, pos, stackCtrl);
10987
}
11088

111-
// TODO MM warn.
112-
super.breakBlock(worldIn, pos, state);
89+
worldIn.removeTileEntity(pos);
11390
}
11491

11592
@Override

src/main/java/github/kasuminova/novaeng/common/container/data/ECalculatorData.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,24 @@
1919
import java.util.List;
2020

2121
@Desugar
22-
public record ECalculatorData(long totalStorage, long usedExtraStorage, int accelerators, List<ThreadCoreData> threadCores, List<ECPUData> ecpuList, int cpuUsagePerSecond) {
22+
public record ECalculatorData(long totalStorage, long usedExtraStorage, int accelerators,
23+
List<ThreadCoreData> threadCores, List<ECPUData> ecpuList, int cpuUsagePerSecond) {
2324

24-
@SuppressWarnings("DataFlowIssue")
2525
public static ECalculatorData from(final ECalculatorController controller) {
2626
final long totalStorage = controller.getTotalBytes();
2727
final int accelerators = controller.getSharedParallelism();
2828
final List<ECalculatorThreadCore> threadCores = controller.getThreadCores();
2929
final List<ThreadCoreData> dataList = new ArrayList<>();
3030
for (final ECalculatorThreadCore threadCore : threadCores) {
3131
final int hyperThreads = (int) threadCore.getCpus().stream()
32-
.map(cpus -> (ECPUCluster) (Object) cpus)
32+
.map(ECPUCluster::from)
3333
.filter(ecpuCluster -> ecpuCluster.novaeng_ec$getUsedExtraStorage() > 0)
3434
.count();
3535
dataList.add(new ThreadCoreData(threadCore.getControllerLevel(), threadCore.getCpus().size() - hyperThreads, hyperThreads, threadCore.getMaxThreads(), threadCore.getMaxHyperThreads()));
3636
}
3737
final List<ECPUData> ecpuData = getEcpuData(controller);
38-
return new ECalculatorData(totalStorage, ecpuData.stream().mapToLong(ECPUData::usedExtraMemory).sum(), accelerators, dataList, ecpuData, 0);
38+
final int cpuUsagePerSecond = ecpuData.stream().mapToInt(ECPUData::cpuUsagePerSecond).sum();
39+
return new ECalculatorData(totalStorage, ecpuData.stream().mapToLong(ECPUData::usedExtraMemory).sum(), accelerators, dataList, ecpuData, cpuUsagePerSecond);
3940
}
4041

4142
@Nonnull
@@ -50,12 +51,20 @@ private static List<ECPUData> getEcpuData(final ECalculatorController controller
5051
final ICraftingGrid crafting = channel.getProxy().getCrafting();
5152
final List<ECalculatorThreadCore> threadCores = controller.getThreadCores();
5253
for (ICraftingCPU cpu : crafting.getCpus()) {
53-
if (cpu instanceof ECPUCluster ecpu) {
54-
ECalculatorThreadCore core = ecpu.novaeng_ec$getController();
55-
if (core != null && threadCores.contains(core)) {
56-
ecpuData.add(new ECPUData(cpu.getFinalOutput(), cpu.getAvailableStorage(), ecpu.novaeng_ec$getUsedExtraStorage(), 0, 0));
57-
}
54+
if (!(cpu instanceof ECPUCluster ecpu)) {
55+
continue;
5856
}
57+
58+
ECalculatorThreadCore core = ecpu.novaeng_ec$getController();
59+
if (core == null || !threadCores.contains(core)) {
60+
continue;
61+
}
62+
63+
ecpuData.add(new ECPUData(
64+
cpu.getFinalOutput(), cpu.getAvailableStorage(), ecpu.novaeng_ec$getUsedExtraStorage(),
65+
ecpu.novaeng_ec$getParallelismRecorder().usedTimeAvg(),
66+
ecpu.novaeng_ec$getTimeRecorder().usedTimeAvg()
67+
));
5968
}
6069
} catch (GridAccessException ignored) {
6170
}

0 commit comments

Comments
 (0)