Skip to content

Commit 8923673

Browse files
Spread out stocking bus/hatch updates to improve worst-case mspt (#4704)
Co-authored-by: Jurre Groenendijk <jurre@jilles.com>
1 parent 758f26c commit 8923673

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
import com.mojang.datafixers.util.Pair;
9696
import lombok.AccessLevel;
9797
import lombok.Getter;
98+
import lombok.Setter;
9899
import org.jetbrains.annotations.*;
99100

100101
import java.util.*;
@@ -107,6 +108,8 @@
107108
public class MetaMachine extends ManagedSyncBlockEntity implements IGregtechBlockEntity, IToolGridHighlight,
108109
IFancyTooltip, IPaintable, IMachineFeature, ICopyable {
109110

111+
private static final int MIN_OFFSET_BOUND = 20;
112+
110113
@Getter
111114
protected final SyncDataHolder syncDataHolder = new SyncDataHolder(this);
112115

@@ -132,8 +135,10 @@ public class MetaMachine extends ManagedSyncBlockEntity implements IGregtechBloc
132135
@SyncToClient
133136
@RerenderOnChanged
134137
private MachineRenderState renderState;
138+
135139
@Getter(value = AccessLevel.PROTECTED)
136-
private final long offset = GTValues.RNG.nextInt(20);
140+
@Setter(value = AccessLevel.PROTECTED)
141+
private long offset = GTValues.RNG.nextInt(MIN_OFFSET_BOUND);
137142

138143
@Getter
139144
@SaveField
@@ -624,6 +629,11 @@ public void setPaintingColor(int color) {
624629

625630
public void onPaintingColorChanged(int color) {}
626631

632+
public void setOffsetBound(int offsetBound) {
633+
var bound = Math.max(offsetBound, MIN_OFFSET_BOUND);
634+
offset = GTValues.RNG.nextInt(bound);
635+
}
636+
627637
@Override
628638
public boolean shouldRenderGrid(Player player, BlockPos pos, BlockState state, ItemStack held,
629639
Set<GTToolType> toolTypes) {

src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEStockingBusPartMachine.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public class MEStockingBusPartMachine extends MEInputBusPartMachine implements I
5555
@SaveField
5656
private int minStackSize = 1;
5757
@Getter
58-
@Setter
5958
@SaveField
6059
private int ticksPerCycle = 40;
6160

@@ -65,6 +64,7 @@ public class MEStockingBusPartMachine extends MEInputBusPartMachine implements I
6564
public MEStockingBusPartMachine(BlockEntityCreationInfo info) {
6665
super(info);
6766
this.autoPullTest = $ -> false;
67+
setOffsetBound(ticksPerCycle);
6868
}
6969

7070
/////////////////////////////////
@@ -187,6 +187,11 @@ public void setAutoPull(boolean autoPull) {
187187
}
188188
}
189189

190+
public void setTicksPerCycle(int ticksPerCycle) {
191+
this.ticksPerCycle = ticksPerCycle;
192+
setOffsetBound(ticksPerCycle);
193+
}
194+
190195
/**
191196
* Refresh the configuration list in auto-pull mode.
192197
* Sets the config to the CONFIG_SIZE items with the highest amount in the ME system.

src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEStockingHatchPartMachine.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public class MEStockingHatchPartMachine extends MEInputHatchPartMachine implemen
6060
private int minStackSize = 1;
6161

6262
@Getter
63-
@Setter
6463
@SaveField
6564
private int ticksPerCycle = 40;
6665

@@ -70,6 +69,7 @@ public class MEStockingHatchPartMachine extends MEInputHatchPartMachine implemen
7069
public MEStockingHatchPartMachine(BlockEntityCreationInfo info) {
7170
super(info);
7271
this.autoPullTest = $ -> false;
72+
setOffsetBound(ticksPerCycle);
7373
}
7474

7575
/////////////////////////////////
@@ -176,6 +176,11 @@ public void setAutoPull(boolean autoPull) {
176176
}
177177
}
178178

179+
public void setTicksPerCycle(int ticksPerCycle) {
180+
this.ticksPerCycle = ticksPerCycle;
181+
setOffsetBound(ticksPerCycle);
182+
}
183+
179184
private void refreshList() {
180185
IGrid grid = this.getMainNode().getGrid();
181186
if (grid == null) {

0 commit comments

Comments
 (0)