Skip to content

Commit c14b163

Browse files
committed
- Fix crashes...
- Fix MultiLineLabel align offset. - When the controller is stopped by redstone control, a structure check is performed immediately upon recovery.
1 parent 620684f commit c14b163

File tree

5 files changed

+47
-24
lines changed

5 files changed

+47
-24
lines changed

src/main/java/github/kasuminova/mmce/client/gui/widget/MultiLineLabel.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,19 @@ public void render(final WidgetGui gui, final RenderSize renderSize, final Rende
7575
// Utils
7676

7777
protected float getLineRenderOffset(final String s, final FontRenderer fr) {
78+
if (leftAligned && !rightAligned) {
79+
return 0;
80+
}
81+
7882
int width = getWidth();
83+
float stringWidth = fr.getStringWidth(s) * scale;
7984

8085
if (leftAligned && rightAligned) {
81-
int stringWidth = fr.getStringWidth(s);
82-
return (float) (width - stringWidth) / 2 / scale;
83-
} else if (leftAligned) {
84-
return 0;
86+
return (width - (stringWidth)) / 2F;
8587
} else if (rightAligned) {
86-
return width - fr.getStringWidth(s) / scale;
88+
return (width - (stringWidth));
8789
} else {
88-
int stringWidth = fr.getStringWidth(s);
89-
return (float) (width - stringWidth) / 2 / scale;
90+
return (width - (stringWidth)) / 2F;
9091
}
9192
}
9293

src/main/java/github/kasuminova/mmce/client/gui/widget/container/Column.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public RenderPos getWidgetRenderOffset(DynamicWidget widget, int width, int y) {
257257
xOffset = widget.getMarginLeft();
258258
yOffset = y + widget.getMarginUp();
259259
} else if (rightAligned) {
260-
xOffset = width - widget.getWidth() - widget.getMarginRight();
260+
xOffset = width - (widget.getWidth() + widget.getMarginRight());
261261
yOffset = y + widget.getMarginUp();
262262
} else {
263263
// Where does it align?

src/main/java/github/kasuminova/mmce/common/world/MMWorldEventListener.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package github.kasuminova.mmce.common.world;
22

33
import github.kasuminova.mmce.client.world.BlockModelHider;
4+
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
5+
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
46
import net.minecraft.block.state.IBlockState;
57
import net.minecraft.entity.Entity;
68
import net.minecraft.entity.player.EntityPlayer;
@@ -21,14 +23,12 @@
2123
import javax.annotation.Nullable;
2224
import java.util.HashMap;
2325
import java.util.Map;
24-
import java.util.concurrent.ConcurrentHashMap;
2526

2627
public class MMWorldEventListener implements IWorldEventListener {
2728

2829
public static final MMWorldEventListener INSTANCE = new MMWorldEventListener();
2930

30-
private final Map<World, Map<ChunkPos, StructureBoundingBox>> worldChangedChunksLastTick = new ConcurrentHashMap<>();
31-
private final Map<World, Map<ChunkPos, StructureBoundingBox>> worldChangedChunks = new ConcurrentHashMap<>();
31+
private final Map<World, Long2ObjectMap<StructureBoundingBox>> worldChangedChunks = new HashMap<>();
3232

3333
private MMWorldEventListener() {
3434
}
@@ -51,19 +51,16 @@ public void onWorldUnloaded(WorldEvent.Unload event) {
5151
return;
5252
}
5353
worldChangedChunks.remove(world);
54-
worldChangedChunksLastTick.remove(world);
5554
MachineComponentManager.INSTANCE.removeWorld(world);
5655
}
5756

5857
@SubscribeEvent
59-
public void onServerTickStart(TickEvent.ServerTickEvent event) {
58+
public void onWorldTickStart(TickEvent.WorldTickEvent event) {
6059
if (event.side != Side.SERVER || event.phase != TickEvent.Phase.START) {
6160
return;
6261
}
6362

64-
worldChangedChunksLastTick.clear();
65-
worldChangedChunksLastTick.putAll(worldChangedChunks);
66-
worldChangedChunks.clear();
63+
worldChangedChunks.put(event.world, new Long2ObjectOpenHashMap<>());
6764
}
6865

6966
@SubscribeEvent
@@ -79,7 +76,7 @@ public void onChunkUnload(final ChunkEvent.Unload event) {
7976
int zEnd = pos.getZEnd();
8077

8178
StructureBoundingBox structureArea = new StructureBoundingBox(xStart, zStart, xEnd, zEnd);
82-
worldChangedChunks.get(world).put(pos, structureArea);
79+
worldChangedChunks.get(world).put(ChunkPos.asLong(pos.x, pos.z), structureArea);
8380
}
8481

8582
public boolean isAreaChanged(@Nonnull final World worldIn,
@@ -94,9 +91,9 @@ public boolean isAreaChanged(@Nonnull final World worldIn,
9491

9592
for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
9693
for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
97-
Map<ChunkPos, StructureBoundingBox> chunkPosBoundingBoxMap = worldChangedChunksLastTick.get(worldIn);
98-
if (chunkPosBoundingBoxMap != null) {
99-
StructureBoundingBox changedArea = chunkPosBoundingBoxMap.get(new ChunkPos(chunkX, chunkZ));
94+
Long2ObjectMap<StructureBoundingBox> changedChunks = worldChangedChunks.get(worldIn);
95+
if (changedChunks != null) {
96+
StructureBoundingBox changedArea = changedChunks.get(ChunkPos.asLong(chunkX, chunkZ));
10097
if (changedArea != null && changedArea.intersectsWith(structureArea)) {
10198
return true;
10299
}
@@ -111,16 +108,17 @@ public void notifyBlockUpdate(@Nonnull final World worldIn,
111108
@Nonnull final BlockPos pos,
112109
@Nonnull final IBlockState oldState,
113110
@Nonnull final IBlockState newState, final int flags) {
114-
if ((flags != 1 && flags != 3) || oldState == newState) {
111+
if ((flags & 1) == 0 || oldState == newState) {
115112
return;
116113
}
117114

118-
Map<ChunkPos, StructureBoundingBox> chunkPosHeightSetMap = worldChangedChunks.computeIfAbsent(worldIn, v -> new HashMap<>());
115+
Long2ObjectMap<StructureBoundingBox> changedChunks = worldChangedChunks.computeIfAbsent(worldIn, v -> new Long2ObjectOpenHashMap<>());
119116
ChunkPos chunkPos = new ChunkPos(pos.getX() >> 4, pos.getZ() >> 4);
120-
StructureBoundingBox changedArea = chunkPosHeightSetMap.get(chunkPos);
117+
long longChunkPos = ChunkPos.asLong(chunkPos.x, chunkPos.z);
118+
StructureBoundingBox changedArea = changedChunks.get(longChunkPos);
121119

122120
if (changedArea == null) {
123-
chunkPosHeightSetMap.put(chunkPos, new StructureBoundingBox(pos, pos));
121+
changedChunks.put(longChunkPos, new StructureBoundingBox(pos, pos));
124122
} else {
125123
changedArea.expandTo(new StructureBoundingBox(pos, pos));
126124
}

src/main/java/hellfirepvp/modularmachinery/common/tiles/TileFactoryController.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class TileFactoryController extends TileMultiblockMachineController {
4848
private FactoryRecipeSearchTask searchTask = null;
4949
private SequentialTaskExecutor threadTask = null;
5050

51+
private boolean redstoneEffected = false;
52+
5153
public TileFactoryController() {
5254

5355
}
@@ -67,6 +69,7 @@ public TileFactoryController(IBlockState state) {
6769
@Override
6870
public void doControllerTick() {
6971
if (getStrongPower() > 0) {
72+
redstoneEffected = true;
7073
return;
7174
}
7275

@@ -539,6 +542,15 @@ protected void updateComponents() {
539542
}
540543
}
541544

545+
@Override
546+
protected boolean canCheckStructure() {
547+
if (redstoneEffected) {
548+
redstoneEffected = false;
549+
return true;
550+
}
551+
return super.canCheckStructure();
552+
}
553+
542554
@Override
543555
protected void checkRotation() {
544556
IBlockState state = getWorld().getBlockState(getPos());

src/main/java/hellfirepvp/modularmachinery/common/tiles/TileMachineController.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public class TileMachineController extends TileMultiblockMachineController {
4040
private MachineRecipeThread recipeThread = new MachineRecipeThread(this);
4141
private BlockController parentController = null;
4242

43+
private boolean redstoneEffected = false;
44+
4345
public TileMachineController() {
4446
}
4547

@@ -59,6 +61,7 @@ public TileMachineController(IBlockState state) {
5961
@Override
6062
public void doControllerTick() {
6163
if (getStrongPower() > 0) {
64+
redstoneEffected = true;
6265
return;
6366
}
6467

@@ -222,6 +225,15 @@ protected void updateComponents() {
222225
ctx.updateComponents(foundComponents.values());
223226
}
224227

228+
@Override
229+
protected boolean canCheckStructure() {
230+
if (redstoneEffected) {
231+
redstoneEffected = false;
232+
return true;
233+
}
234+
return super.canCheckStructure();
235+
}
236+
225237
@Override
226238
protected void checkRotation() {
227239
IBlockState state = getWorld().getBlockState(getPos());

0 commit comments

Comments
 (0)