Skip to content

Commit f630ba3

Browse files
committed
- Fix #103.
1 parent dd04788 commit f630ba3

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

src/main/java/hellfirepvp/modularmachinery/client/gui/GuiMachineController.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,19 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
157157
int usedTimeCache = TileMultiblockMachineController.usedTimeCache;
158158
float searchUsedTimeCache = TileMultiblockMachineController.searchUsedTimeCache;
159159
String workMode = TileMultiblockMachineController.workModeCache.getDisplayName();
160-
fr.drawStringWithShadow(String.format("Avg: %sμs/t (Search: %sms), WorkMode: %s",
161-
usedTimeCache,
162-
MiscUtils.formatFloat(searchUsedTimeCache / 1000F, 2),
163-
workMode),
164-
offsetX, offsetY, 0xFFFFFF
160+
out = fr.listFormattedStringToWidth(
161+
String.format(
162+
"Avg: %sμs/t (Search: %sms), WorkMode: %s",
163+
usedTimeCache,
164+
MiscUtils.formatFloat(searchUsedTimeCache / 1000F, 2),
165+
workMode
166+
),
167+
MathHelper.floor(135 * (1 / scale))
165168
);
169+
for (String draw : out) {
170+
offsetY += 10;
171+
fr.drawStringWithShadow(draw, offsetX, offsetY, 0xFFFFFF);
172+
}
166173

167174
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
168175
GlStateManager.popMatrix();

src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileColorableMachineComponent.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import hellfirepvp.modularmachinery.common.data.Config;
1212
import net.minecraft.nbt.NBTTagCompound;
13+
import net.minecraft.world.World;
1314

1415
/**
1516
* This class is part of the Modular Machinery Mod
@@ -43,8 +44,17 @@ public void readCustomNBT(NBTTagCompound compound) {
4344

4445
if (!compound.hasKey("casingColor")) {
4546
definedColor = Config.machineColor;
46-
} else {
47-
definedColor = compound.getInteger("casingColor");
47+
return;
48+
}
49+
50+
int newColor = compound.getInteger("casingColor");
51+
if (definedColor != newColor) {
52+
definedColor = newColor;
53+
World world = getWorld();
54+
//noinspection ConstantValue
55+
if (world != null) {
56+
world.addBlockEvent(pos, world.getBlockState(pos).getBlock(), 1, 1);
57+
}
4858
}
4959
}
5060

src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,14 @@ protected boolean matchesDynamicPatternRotation(final DynamicMachine machine, fi
431431
}
432432

433433
protected void distributeCasingColor() {
434-
if (this.foundMachine != null && this.foundPattern != null) {
435-
int color = this.foundMachine.getMachineColor();
436-
tryColorize(getPos(), color);
437-
for (BlockPos pos : this.foundPattern.getPattern().keySet()) {
438-
tryColorize(this.getPos().add(pos), color);
439-
}
434+
if (this.foundMachine == null || this.foundPattern == null) {
435+
return;
440436
}
437+
int color = this.foundMachine.getMachineColor();
438+
// Colorize Controller.
439+
tryColorize(getPos(), color);
440+
// Colorize Components.
441+
this.foundPattern.getTileBlocksArray().keySet().forEach(pos -> tryColorize(this.getPos().add(pos), color));
441442
}
442443

443444
/**
@@ -451,7 +452,6 @@ private void tryColorize(BlockPos pos, int color) {
451452
if (te instanceof final ColorableMachineTile colorable) {
452453
if (colorable.getMachineColor() != color) {
453454
colorable.setMachineColor(color);
454-
getWorld().addBlockEvent(pos, getWorld().getBlockState(pos).getBlock(), 1, 1);
455455
}
456456
}
457457
}
@@ -546,13 +546,9 @@ protected void onStructureFormed() {
546546
}
547547

548548
if (workMode == WorkMode.SYNC) {
549-
distributeCasingColor();
550549
notifyStructureFormedState(true);
551550
} else {
552-
ModularMachinery.EXECUTE_MANAGER.addSyncTask(() -> {
553-
distributeCasingColor();
554-
notifyStructureFormedState(true);
555-
});
551+
ModularMachinery.EXECUTE_MANAGER.addSyncTask(() -> notifyStructureFormedState(true));
556552
}
557553

558554
resetStructureCheckCounter();
@@ -706,6 +702,11 @@ protected void updateComponents() {
706702
this.foundModifiers.clear();
707703
updateModifiers();
708704
updateMultiBlockModifiers();
705+
if (workMode == WorkMode.SYNC) {
706+
distributeCasingColor();
707+
} else {
708+
ModularMachinery.EXECUTE_MANAGER.addSyncTask(this::distributeCasingColor);
709+
}
709710
}
710711

711712
private void checkAndAddComponents(final BlockPos pos, final BlockPos ctrlPos, final Map<TileEntity, ProcessingComponent<?>> found) {

0 commit comments

Comments
 (0)