Skip to content

Commit c8ba33f

Browse files
committed
stuff
1 parent 14ae70e commit c8ba33f

File tree

8 files changed

+16
-59
lines changed

8 files changed

+16
-59
lines changed

src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
import codechicken.lib.render.pipeline.IVertexOperation;
5757
import codechicken.lib.vec.Matrix4;
5858
import codechicken.lib.vec.Rotation;
59-
import com.google.common.collect.AbstractIterator;
59+
import com.google.common.collect.Iterators;
6060
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
6161
import it.unimi.dsi.fastutil.objects.Object2IntMap;
6262
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
@@ -834,19 +834,7 @@ public List<MultiblockShapeInfo> getMatchingShapes() {
834834
*/
835835
@NotNull
836836
public Iterator<Map<String, String>> getPreviewBuilds() {
837-
return new AbstractIterator<>() {
838-
839-
private boolean used;
840-
841-
@Override
842-
protected Map<String, String> computeNext() {
843-
if (!used) {
844-
used = true;
845-
return Collections.emptyMap();
846-
}
847-
return endOfData();
848-
}
849-
};
837+
return Iterators.singletonIterator(Collections.emptyMap());
850838
}
851839

852840
/**
@@ -882,10 +870,8 @@ public void autoBuild(EntityPlayer player, Map<String, String> map,
882870

883871
BiPredicate<Long, BlockInfo> place = (l, info) -> {
884872
BlockPos pos = BlockPos.fromLong(l);
885-
886873
// don't stop build if its air
887874
if (!getWorld().isAirBlock(pos)) return true;
888-
889875
if (info.getTileEntity() instanceof MetaTileEntityHolder holder) {
890876
ItemStack removed = hasAndRemoveItem(player, holder.getMetaTileEntity().getStackForm());
891877
if (removed.isEmpty()) return false;
@@ -896,7 +882,6 @@ public void autoBuild(EntityPlayer player, Map<String, String> map,
896882
newHolder.getMetaTileEntity().setFrontFacing(holder.getMetaTileEntity().getFrontFacing());
897883
if (removed.hasTagCompound())
898884
newHolder.getMetaTileEntity().initFromItemStackData(removed.getTagCompound());
899-
900885
if (predicates.containsKey(pos.offset(newHolder.getMetaTileEntity().getFrontFacing()).toLong())) {
901886
EnumFacing valid = null;
902887
for (EnumFacing facing : EnumFacing.HORIZONTALS) {
@@ -914,26 +899,22 @@ public void autoBuild(EntityPlayer player, Map<String, String> map,
914899
}
915900
}
916901
}
917-
918902
getWorld().setBlockState(pos, holder.getMetaTileEntity().getBlock().getDefaultState());
919903
getWorld().setTileEntity(pos, newHolder);
920904
} else {
921905
if (!hasAndRemoveItem(player, GTUtility.toItem(info.getBlockState())).isEmpty())
922906
getWorld().setBlockState(pos, info.getBlockState());
923907
else return false;
924908
}
925-
926909
return true;
927910
};
928911

929912
for (Long2ObjectMap.Entry<TraceabilityPredicate> entry : predicates.long2ObjectEntrySet()) {
930913
TraceabilityPredicate pred = entry.getValue();
931914
if (simpleIndex.getInt(pred) >= pred.simple.size()) continue;
932-
933915
int pointer = simpleIndex.getInt(pred);
934916
TraceabilityPredicate.SimplePredicate simple = pred.simple.get(pointer);
935917
int count = globalCache.getInt(simple);
936-
937918
try {
938919
while ((simple.previewCount == -1 || count == simple.previewCount) &&
939920
(simple.minGlobalCount == -1 || count == simple.minGlobalCount)) {
@@ -946,28 +927,19 @@ public void autoBuild(EntityPlayer player, Map<String, String> map,
946927
} catch (IndexOutOfBoundsException e) {
947928
continue;
948929
}
949-
950930
globalCache.put(simple, globalCache.getInt(simple) + 1);
951-
952931
if (simple.candidates == null) continue;
953-
954932
TraceabilityPredicate.SimplePredicate finalSimple = simple;
955933
cache.computeIfAbsent(simple, k -> finalSimple.candidates.apply(map)[0]);
956-
957934
if (!place.test(entry.getLongKey(), cache.get(simple))) return;
958-
959935
entry.setValue(null);
960936
}
961-
962937
simpleIndex.clear();
963-
964938
for (Long2ObjectMap.Entry<TraceabilityPredicate> entry : predicates.long2ObjectEntrySet()) {
965939
TraceabilityPredicate pred = entry.getValue();
966940
if (pred == null || simpleIndex.getInt(pred) >= pred.simple.size()) continue;
967-
968941
TraceabilityPredicate.SimplePredicate simple = pred.simple.get(simpleIndex.getInt(pred));
969942
int count = globalCache.getInt(simple);
970-
971943
while (count == simple.previewCount || count == simple.maxGlobalCount) {
972944
// if the current predicate is used, move until the next free one
973945
int newIndex = simpleIndex.put(pred, simpleIndex.getInt(pred) + 1) + 1;
@@ -980,19 +952,16 @@ public void autoBuild(EntityPlayer player, Map<String, String> map,
980952
count = globalCache.getInt(simple);
981953
}
982954
globalCache.put(simple, globalCache.getInt(simple) + 1);
983-
984955
if (simple.candidates == null) continue;
985-
986956
TraceabilityPredicate.SimplePredicate finalSimple = simple;
987957
cache.computeIfAbsent(simple, k -> finalSimple.candidates.apply(map)[0]);
988-
989958
if (!place.test(entry.getLongKey(), cache.get(simple))) return;
990959
}
991960
}
992961

993962
/**
994963
* Called right before the autobuild code starts, modify the map like if you want it to be "height"
995-
* instead of "multi.1.0"
964+
* instead of "multi.1.0". The passed in map may be immutable and may be the same one passed in for multiple builds.
996965
*/
997966
protected void modifyAutoBuild(Map<String, String> map) {}
998967

src/main/java/gregtech/api/pattern/GreggyBlockPos.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import net.minecraft.util.EnumFacing;
44
import net.minecraft.util.math.BlockPos;
5-
import net.minecraft.util.math.MathHelper;
65

76
import com.google.common.collect.AbstractIterator;
87
import org.jetbrains.annotations.NotNull;
@@ -17,7 +16,7 @@
1716
*/
1817
public class GreggyBlockPos {
1918

20-
public static final int NUM_X_BITS = 1 + MathHelper.log2(MathHelper.smallestEncompassingPowerOfTwo(30000000));
19+
public static final int NUM_X_BITS = 1 + 32 - Integer.numberOfLeadingZeros(30_000_000 - 1);
2120
public static final int NUM_Z_BITS = NUM_X_BITS, NUM_Y_BITS = 64 - 2 * NUM_X_BITS;
2221
public static final int Y_SHIFT = NUM_Z_BITS;
2322
public static final int X_SHIFT = Y_SHIFT + NUM_Y_BITS;
@@ -156,7 +155,6 @@ public GreggyBlockPos offset(EnumFacing facing) {
156155

157156
/**
158157
* Serializes this pos to long, this should be identical to {@link BlockPos}.
159-
* But the blockpos impl is so bad, who let them cook???
160158
*
161159
* @return Long rep
162160
*/
@@ -284,7 +282,8 @@ public GreggyBlockPos copy() {
284282

285283
@Override
286284
public int hashCode() {
287-
return Arrays.hashCode(pos);
285+
// should be identical to blockpos
286+
return (pos[1] + pos[2] * 31) * 31 + pos[0];
288287
}
289288

290289
@Override

src/main/java/gregtech/api/pattern/MultiblockShapeInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Map;
3333
import java.util.function.Supplier;
3434

35+
@Deprecated(forRemoval = true) // this shall be removed soontm, this class has no use atm
3536
public class MultiblockShapeInfo {
3637

3738
/**

src/main/java/gregtech/api/pattern/PatternError.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public PatternError(BlockPos pos, TraceabilityPredicate failingPredicate) {
3030
this(pos, failingPredicate.getCandidates());
3131
}
3232

33+
public PatternError(BlockPos pos, TraceabilityPredicate.SimplePredicate failingPredicate) {
34+
this(pos, Collections.singletonList(failingPredicate.getCandidates()));
35+
}
36+
3337
@Nullable
3438
public BlockPos getPos() {
3539
return pos;

src/main/java/gregtech/api/pattern/TraceabilityPredicate.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,9 @@ public TraceabilityPredicate addTooltips(String... tips) {
102102
* @return A list containing lists which group together candidates
103103
*/
104104
public List<List<ItemStack>> getCandidates() {
105-
List<List<ItemStack>> candidates = new ArrayList<>();
106-
for (TraceabilityPredicate.SimplePredicate pred : simple) {
107-
candidates.add(pred.getCandidates());
108-
}
109-
return candidates;
105+
return simple.stream()
106+
.map(SimplePredicate::getCandidates)
107+
.collect(Collectors.toList());
110108
}
111109

112110
/**
@@ -284,23 +282,17 @@ public PatternError testLimited(BlockWorldState worldState,
284282
public PatternError testGlobal(BlockWorldState worldState, Object2IntMap<SimplePredicate> global,
285283
Object2IntMap<SimplePredicate> layer) {
286284
PatternError result = predicate.apply(worldState);
287-
288285
if (!global.containsKey(this)) global.put(this, 0);
289286
if ((minGlobalCount == -1 && maxGlobalCount == -1) || result != null || layer == null) return result;
290-
291287
int count = layer.put(this, layer.getInt(this) + 1) + 1 + global.getInt(this);
292288
if (maxGlobalCount == -1 || count <= maxGlobalCount) return null;
293-
294289
return new SinglePredicateError(this, 0);
295290
}
296291

297292
public PatternError testLayer(BlockWorldState worldState, Object2IntMap<SimplePredicate> cache) {
298293
PatternError result = predicate.apply(worldState);
299-
300294
if ((minLayerCount == -1 && maxLayerCount == -1) || result != null) return result;
301-
302295
if (maxLayerCount == -1 || cache.getInt(this) <= maxLayerCount) return null;
303-
304296
return new SinglePredicateError(this, 2);
305297
}
306298

@@ -318,7 +310,7 @@ public static class SinglePredicateError extends PatternError {
318310
public final int type, number;
319311

320312
public SinglePredicateError(SimplePredicate failingPredicate, int type) {
321-
super(null, Collections.singletonList(failingPredicate.getCandidates()));
313+
super(null, failingPredicate);
322314
this.type = type;
323315

324316
int number = -1;

src/main/java/gregtech/api/pattern/pattern/BasicAisleStrategy.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ protected int checkRepeatAisle(int index, int offset, boolean flip) {
7171
return aisles.get(index).actualRepeats = aisle.maxRepeats;
7272
}
7373

74-
// todo more lang support(yay!)
7574
@Override
7675
public int @NotNull [] getDefaultAisles(Map<String, String> map) {
7776
IntList list = new IntArrayList();
@@ -135,7 +134,6 @@ protected void multiAisleError() {
135134
throw new IllegalStateException("Illegal multiAisles, check logs above.");
136135
}
137136

138-
// resisting the urge to make this a generic type return to allow for inheritors,,,,,,
139137
public BasicAisleStrategy multiAisle(int min, int max, int from, int to) {
140138
Preconditions.checkArgument(max >= min, "max: %s is less than min: %s", max, min);
141139
Preconditions.checkArgument(from >= 0, "from argument is negative: %s", from);

src/main/java/gregtech/api/pattern/pattern/BlockPattern.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,12 @@ public BlockPattern(@NotNull PatternAisle @NotNull [] aisles,
8585
* @param center The center char to look for
8686
*/
8787
private void legacyStartOffset(char center) {
88-
// don't do anything if center char isn't specified, this allows
89-
// MultiblockControllerBase#validateStructurePatterns to do its thing while not logging an error here
88+
// don't do anything if center char isn't specified
9089
if (center == 0) return;
91-
// could also use aisles.length but this is cooler
9290
for (int aisleI = 0; aisleI < dimensions[0]; aisleI++) {
9391
int[] result = aisles[aisleI].firstInstanceOf(center);
9492
if (result != null) {
9593
// structure starts at aisle 0, string 0, char 0, think about it
96-
// so relative to the controller we need to offset by this to get to the start
9794
moveOffset(directions[0], -aisleI);
9895
moveOffset(directions[1], -result[0]);
9996
moveOffset(directions[2], -result[1]);
@@ -211,7 +208,6 @@ public boolean checkPatternAt(World world, BlockPos centerPos, EnumFacing frontF
211208
*/
212209
public boolean checkAisle(GreggyBlockPos controllerPos, EnumFacing frontFacing, EnumFacing upFacing, int aisleIndex,
213210
int aisleOffset, boolean flip) {
214-
// todo use a temporary cache to not double count sometimes
215211
// absolute facings from the relative facings
216212
EnumFacing absoluteAisle = directions[0].getRelativeFacing(frontFacing, upFacing, flip);
217213
EnumFacing absoluteString = directions[1].getRelativeFacing(frontFacing, upFacing, flip);

src/main/java/gregtech/common/items/behaviors/MultiblockBuilderBehavior.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import gregtech.api.mui.factory.MetaItemGuiFactory;
1111
import gregtech.api.pattern.PatternError;
1212
import gregtech.api.util.GTUtility;
13-
import gregtech.client.renderer.handler.BlockPosHighlightRenderer;
1413

1514
import net.minecraft.client.resources.I18n;
1615
import net.minecraft.entity.player.EntityPlayer;
@@ -193,7 +192,6 @@ public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPo
193192
player.sendMessage(
194193
new TextComponentTranslation("gregtech.multiblock.pattern.error_message_header"));
195194
player.sendMessage(new TextComponentString(error.getErrorInfo()));
196-
if (error.getPos() != null) BlockPosHighlightRenderer.renderBlockBoxHighLight(error.getPos(), 5000);
197195
return EnumActionResult.SUCCESS;
198196
}
199197
}

0 commit comments

Comments
 (0)