use of gregtech.api.multiblock.PatternMatchContext in project GregTech by GregTechCE.
the class MultiblockControllerBase method checkStructurePattern.
protected void checkStructurePattern() {
EnumFacing facing = getFrontFacing().getOpposite();
PatternMatchContext context = structurePattern.checkPatternAt(getWorld(), getPos(), facing);
if (context != null && !structureFormed) {
Set<IMultiblockPart> rawPartsSet = context.getOrCreate("MultiblockParts", HashSet::new);
ArrayList<IMultiblockPart> parts = new ArrayList<>(rawPartsSet);
parts.sort(Comparator.comparing(it -> ((MetaTileEntity) it).getPos().hashCode()));
for (IMultiblockPart part : parts) {
if (part.isAttachedToMultiBlock()) {
// stop here without attempting to register abilities
return;
}
}
Map<MultiblockAbility<Object>, List<Object>> abilities = new HashMap<>();
for (IMultiblockPart multiblockPart : parts) {
if (multiblockPart instanceof IMultiblockAbilityPart) {
IMultiblockAbilityPart<Object> abilityPart = (IMultiblockAbilityPart<Object>) multiblockPart;
List<Object> abilityInstancesList = abilities.computeIfAbsent(abilityPart.getAbility(), k -> new ArrayList<>());
abilityPart.registerAbilities(abilityInstancesList);
}
}
if (checkStructureComponents(parts, abilities)) {
parts.forEach(part -> part.addToMultiBlock(this));
this.multiblockParts.addAll(parts);
this.multiblockAbilities.putAll(abilities);
this.structureFormed = true;
writeCustomData(400, buf -> buf.writeBoolean(true));
formStructure(context);
}
} else if (context == null && structureFormed) {
invalidateStructure();
}
}
Aggregations