Search in sources :

Example 1 with PatternMatchContext

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();
    }
}
Also used : Matrix4(codechicken.lib.vec.Matrix4) Textures(gregtech.api.render.Textures) java.util(java.util) IPatternCenterPredicate(gregtech.api.multiblock.IPatternCenterPredicate) BiFunction(java.util.function.BiFunction) IVertexOperation(codechicken.lib.render.pipeline.IVertexOperation) BlockWorldState(gregtech.api.multiblock.BlockWorldState) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Block(net.minecraft.block.Block) Pair(org.apache.commons.lang3.tuple.Pair) PatternMatchContext(gregtech.api.multiblock.PatternMatchContext) ICubeRenderer(gregtech.api.render.ICubeRenderer) OrientedOverlayRenderer(gregtech.api.render.OrientedOverlayRenderer) Nonnull(javax.annotation.Nonnull) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) CCRenderState(codechicken.lib.render.CCRenderState) Predicate(java.util.function.Predicate) EnumFacing(net.minecraft.util.EnumFacing) IBlockState(net.minecraft.block.state.IBlockState) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPattern(gregtech.api.multiblock.BlockPattern) TileEntity(net.minecraft.tileentity.TileEntity) GTUtility(gregtech.api.util.GTUtility) ColourMultiplier(codechicken.lib.render.pipeline.ColourMultiplier) PacketBuffer(net.minecraft.network.PacketBuffer) EnumFacing(net.minecraft.util.EnumFacing) PatternMatchContext(gregtech.api.multiblock.PatternMatchContext)

Aggregations

CCRenderState (codechicken.lib.render.CCRenderState)1 ColourMultiplier (codechicken.lib.render.pipeline.ColourMultiplier)1 IVertexOperation (codechicken.lib.render.pipeline.IVertexOperation)1 Matrix4 (codechicken.lib.vec.Matrix4)1 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)1 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)1 BlockPattern (gregtech.api.multiblock.BlockPattern)1 BlockWorldState (gregtech.api.multiblock.BlockWorldState)1 IPatternCenterPredicate (gregtech.api.multiblock.IPatternCenterPredicate)1 PatternMatchContext (gregtech.api.multiblock.PatternMatchContext)1 ICubeRenderer (gregtech.api.render.ICubeRenderer)1 OrientedOverlayRenderer (gregtech.api.render.OrientedOverlayRenderer)1 Textures (gregtech.api.render.Textures)1 GTUtility (gregtech.api.util.GTUtility)1 java.util (java.util)1 BiFunction (java.util.function.BiFunction)1 Predicate (java.util.function.Predicate)1 Nonnull (javax.annotation.Nonnull)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1