Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the patterning #2689

Draft
wants to merge 64 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
0b4392e
scuffed commit, more red than lines changed
vrejhead Jul 13, 2024
5de619b
IT COMPILES!!!! debugging time
vrejhead Jul 14, 2024
4ba4503
spotless n stuff
vrejhead Jul 14, 2024
4a45b62
it actually kinda works
vrejhead Jul 15, 2024
49bdb1d
caching and stuff
vrejhead Jul 15, 2024
2694a0a
spotless, deprecations, and not nulls
vrejhead Jul 15, 2024
96078bb
iterable, apparently this is like 20x faster than the blockpos iterable
vrejhead Jul 16, 2024
0419271
step 1 of 13918238091 to making previews work
vrejhead Jul 16, 2024
b0bdbd0
groundwork for hell
vrejhead Jul 16, 2024
f7e76e6
time for hell
vrejhead Jul 16, 2024
0f21cf7
free from terminal
vrejhead Jul 17, 2024
47a7737
shoutout to crtl-slash i love you
vrejhead Jul 17, 2024
f9e4ccb
startoffset stuff
vrejhead Jul 17, 2024
d9dc706
default impls
vrejhead Jul 17, 2024
45691e8
the third dimension
vrejhead Jul 18, 2024
9645487
use hashmap pt1 + spotless
vrejhead Jul 18, 2024
cc0e227
javadocs + default cause lazy + fix yo stuff
vrejhead Jul 19, 2024
3de4af5
the list thing works + hopefully lbb works
vrejhead Jul 20, 2024
96d472c
hopefully it works fr(still didn't test)
vrejhead Jul 20, 2024
f0bd6dd
:reading:
vrejhead Jul 20, 2024
6c82b0a
smallest arch commit
vrejhead Aug 3, 2024
8f7f1c1
misc stuff
vrejhead Aug 3, 2024
fc20c37
reversed patterns
vrejhead Aug 11, 2024
5e182d6
cleanroom part 0
vrejhead Aug 12, 2024
07519df
assembly line and cleanroom
vrejhead Aug 12, 2024
9b50b62
assembly line and cleanroom but they work
vrejhead Aug 14, 2024
22e979b
central monitor stuff
vrejhead Aug 15, 2024
25abc28
java 11 method :sob:
vrejhead Aug 15, 2024
f09a0b6
charcoal pile igniter and refactor
vrejhead Aug 16, 2024
d65a1a7
persistent nbt data
vrejhead Aug 17, 2024
f8f014c
default pattern got real
vrejhead Aug 17, 2024
9fd8202
arch code is like an onion......
vrejhead Aug 18, 2024
ec3f7f8
zpotlezz
vrejhead Aug 18, 2024
6842647
predicate tooltips and candidates
vrejhead Aug 18, 2024
0ba18a3
in world preview part 1
vrejhead Aug 18, 2024
b8ce93f
part 2 ft. extended rotation
vrejhead Aug 18, 2024
d0abbd8
cleanup
vrejhead Aug 19, 2024
33f2c96
relative direction refactor(central monitor doesnt work again, as exp…
vrejhead Aug 20, 2024
82d30ed
central monitor but it works(and half the things that didn't work bef…
vrejhead Aug 21, 2024
5f49bc7
autobuild but it doesn't work(and dot blocks)
vrejhead Aug 26, 2024
dd9455a
spotless yet again
vrejhead Aug 28, 2024
088d6eb
fix conflicts, and part 1 of autobuild
vrejhead Sep 8, 2024
1b3368d
multi aisling
vrejhead Sep 23, 2024
befb7cf
but it works
vrejhead Sep 23, 2024
cc5211b
generify default pattern generation, and multi aisles
vrejhead Sep 28, 2024
d60c59b
the worst code this has even seen
vrejhead Oct 13, 2024
8ab848f
spotlessApply spotlessApply spotlessApply spotlessApply spotlessApply…
vrejhead Oct 13, 2024
1df1c2d
the calm before the refactor
vrejhead Dec 22, 2024
fbc55ac
"it compiles at least"
vrejhead Dec 23, 2024
36863b7
"it works”
vrejhead Dec 24, 2024
8f9537d
the todo crusade
vrejhead Dec 25, 2024
40c8276
MultiblockShapeInfo is half dead
vrejhead Dec 26, 2024
99c6dcd
spotless and stuff
vrejhead Dec 26, 2024
d3c6865
bruh
vrejhead Dec 26, 2024
1c15477
addressing the deprecations
vrejhead Dec 26, 2024
7d57405
not beating the n squared allegations
vrejhead Dec 27, 2024
0be978c
vrej
vrejhead Dec 27, 2024
fc6acde
:moyai:
vrejhead Dec 27, 2024
b2eebd8
lowercase
vrejhead Dec 27, 2024
f0798f1
constant + oops
vrejhead Dec 27, 2024
a58923f
how it feels to spotless
vrejhead Dec 27, 2024
98979da
the great unboxing
vrejhead Dec 27, 2024
14ae70e
caught
vrejhead Dec 28, 2024
c8ba33f
stuff
vrejhead Jan 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
javadocs + default cause lazy + fix yo stuff
  • Loading branch information
vrejhead committed Dec 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit cc0e227832a1c0d5e00c2b4158a7cee27595888b
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ public interface IMultiblockPart {
/**
* Gets how many multiblocks are currently using the part.
*/
// todo do a concrete impl
default int getWallsharedCount() { return 1;}

default boolean canPartShare(MultiblockControllerBase target, String substructureName) {
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@
import gregtech.api.pattern.BlockWorldState;
import gregtech.api.pattern.MultiblockShapeInfo;
import gregtech.api.pattern.PatternMatchContext;
import gregtech.api.pattern.StructureInfo;
import gregtech.api.pattern.TraceabilityPredicate;
import gregtech.api.pattern.pattern.IBlockPattern;
import gregtech.api.pattern.pattern.PatternInfo;
@@ -147,6 +146,8 @@ private void validateStructurePatterns() {
List<String> failures = new ArrayList<>();

for (Object2ObjectMap.Entry<String, PatternInfo> pattern : structures.object2ObjectEntrySet()) {
if ("MAIN".equals(pattern.getKey())) continue;

if (pattern.getValue().getPattern().legacyBuilderError()) {
failures.add(pattern.getKey());
}
@@ -183,7 +184,6 @@ public void setUpwardsFacing(EnumFacing upwardsFacing) {
}

public boolean isFlipped() {
if (getSubstructure("MAIN") == null) return false;
return getSubstructure("MAIN").isFlipped();
}

@@ -368,19 +368,19 @@ protected Function<BlockPos, Integer> multiblockPartSorter() {
return BlockPos::hashCode;
}

public void checkStructurePattern() {
checkStructurePattern("MAIN");
}

public void checkStructurePatterns() {
for (String name : structures.keySet()) {
checkStructurePattern(name);
}
}

public void checkStructurePattern() {
checkStructurePattern("MAIN");
}

public void checkStructurePattern(String name) {
PatternInfo pattern = getSubstructure(name);
if (pattern == null || !pattern.shouldUpdate) return;
if (!pattern.shouldUpdate) return;

long time = System.nanoTime();
PatternMatchContext context = pattern.getPattern().checkPatternFastAt(getWorld(), getPos(),
@@ -433,7 +433,7 @@ protected void formStructure(PatternMatchContext context, String name) {
// form the main structure
if ("MAIN".equals(name)) formStructure(context);

if (getSubstructure(name) != null) getSubstructure(name).setFormed(true);
getSubstructure(name).setFormed(true);
}

public void invalidateStructure() {
@@ -529,7 +529,7 @@ public void receiveCustomData(int dataId, PacketBuffer buf) {
pattern.setFormed(false);
}
} else {
getSubstructure(name).setFormed(false);
getSubstructure(name).setFormed(buf.readBoolean());
}

if (!isStructureFormed()) {
@@ -554,6 +554,8 @@ public boolean isStructureFormed() {
}

public boolean isStructureFormed(String name) {
if (getWorld() == null) return false;

return getSubstructure(name).isFormed();
}

@@ -659,6 +661,8 @@ public List<PreviewBlockPattern> getBuildableShapes(@Nullable Object2IntMap<Stri

// only generate for the first pattern, if you have more than 1 pattern you better override this
defaultPattern = getSubstructure("MAIN").getPattern().getDefaultShape();

if (defaultPattern == null) return Collections.emptyList();
}

return Collections.singletonList(defaultPattern);
16 changes: 6 additions & 10 deletions src/main/java/gregtech/api/pattern/pattern/BlockPattern.java
Original file line number Diff line number Diff line change
@@ -101,15 +101,11 @@ private void legacyStartOffset(char center) {
for (int aisleI = 0; aisleI < dimensions[0]; aisleI++) {
int[] result = aisles[aisleI].firstInstanceOf(center);
if (result != null) {
// the ordinal() / 2 is so that each relative offset gets put into the correct startOffset

// when legacyStartOffset() is called, aisles have been reversed, so don't reverse it manually here
// the scuffed ternary is so that if the structure dir is the second thing, then don't reverse it
startOffset[structureDir[0].ordinal() / 2] = aisleI * (structureDir[0].ordinal() % 2 == 0 ? -1 : 1);
startOffset[structureDir[1].ordinal() / 2] = (dimensions[1] - 1 - result[0]) *
(structureDir[1].ordinal() % 2 == 0 ? -1 : 1);
startOffset[structureDir[2].ordinal() / 2] = (dimensions[2] - 1 - result[1]) *
(structureDir[2].ordinal() % 2 == 0 ? -1 : 1);
// structure starts at aisle 0, string 0, char 0, think about it
// so relative to the controller we need to offset by this to get to the start
moveStartOffset(structureDir[0], -aisleI);
moveStartOffset(structureDir[1], -result[0]);
moveStartOffset(structureDir[2], -result[1]);
return;
}
}
@@ -256,7 +252,7 @@ public boolean checkAisle(GreggyBlockPos controllerPos, EnumFacing frontFacing,
!(te instanceof IGregTechTileEntity gtTe) || gtTe.isValid() ? te : null, predicate));
}

GTLog.logger.info("Checked pos at " + charPos + " with flip " + flip);
// GTLog.logger.info("Checked pos at " + charPos + " with flip " + flip);

boolean result = predicate.test(worldState, info, globalCount, layerCount);
if (!result) return false;
Original file line number Diff line number Diff line change
@@ -39,6 +39,12 @@ public class ExpandablePattern implements IBlockPattern {
protected final Long2ObjectMap<BlockInfo> cache = new Long2ObjectOpenHashMap<>();
protected final Object2IntMap<TraceabilityPredicate.SimplePredicate> globalCount = new Object2IntOpenHashMap<>();

/**
* New expandable pattern normally you would use {@link FactoryExpandablePattern} instead.
* @param boundsFunction A function to supply bounds, order in the way .values() are ordered in RelativeDirection.
* @param predicateFunction Given a pos and bounds(the one you just passed in, not mutated), return a predicate. The pos is offset as explained in the builder method.
* @param directions The structure directions, explained in the builder method.
*/
public ExpandablePattern(@NotNull QuadFunction<World, GreggyBlockPos, EnumFacing, EnumFacing, int[]> boundsFunction,
@NotNull BiFunction<GreggyBlockPos, int[], TraceabilityPredicate> predicateFunction,
@NotNull RelativeDirection[] directions) {
@@ -157,6 +163,7 @@ public boolean checkPatternAt(World world, BlockPos centerPos, EnumFacing frontF

@Override
public PreviewBlockPattern getDefaultShape() {
// todo undo
return null;
}

Original file line number Diff line number Diff line change
@@ -41,20 +41,38 @@ private FactoryExpandablePattern(RelativeDirection aisleDir, RelativeDirection s
if (flags != 0x7) throw new IllegalArgumentException("Must have 3 different axes!");
}

/**
* Starts a new builder using the provided directions.
*/
public static FactoryExpandablePattern start(RelativeDirection aisleDir, RelativeDirection stringDir,
RelativeDirection charDir) {
return new FactoryExpandablePattern(aisleDir, stringDir, charDir);
}

/**
* Same as calling {@link FactoryExpandablePattern#start(RelativeDirection, RelativeDirection, RelativeDirection)} with BACK, UP, RIGHT
*/
public static FactoryExpandablePattern start() {
return new FactoryExpandablePattern(RelativeDirection.BACK, RelativeDirection.UP, RelativeDirection.RIGHT);
}

/**
* This supplies the bounds function. The inputs are: World, controller pos, front facing, up facing. The returned array
* is an int array of length 6, with how much to extend the multiblock in each direction. The order of the directions is the same
* as the ordinal of the enum.
*/
public FactoryExpandablePattern boundsFunction(QuadFunction<World, GreggyBlockPos, EnumFacing, EnumFacing, int[]> function) {
this.boundsFunction = function;
return this;
}

/**
* This supplies the predicate from offset pos and the bounds, which is not mutated. The pos is offset so that the controller
* is at the origin(0, 0, 0). The 3 axes are positive towards the way structure direction is handled. The pos starts as usual,
* which means it will always be in octant 7. It then ends in octant 1, in the opposite corner to the start corner in the cube specified by the bounding box.
* The pos travels as expected from the structure direction, traveling first in charDir, then upon going out of bounds once in stringDir and resetting
* its charDir pos. Same happens when stringDir goes out of bounds and reset, then aisleDir is incremented.
*/
public FactoryExpandablePattern predicateFunction(BiFunction<GreggyBlockPos, int[], TraceabilityPredicate> function) {
this.predicateFunction = function;
return this;