Search in sources :

Example 1 with TrackedDummyWorld

use of com.lowdragmc.lowdraglib.utils.TrackedDummyWorld in project Multiblocked by Low-Drag-MC.

the class PartBuilderWidget method initScene.

@OnlyIn(Dist.CLIENT)
private void initScene() {
    TrackedDummyWorld world = new TrackedDummyWorld();
    world.addBlock(BlockPos.ZERO, BlockInfo.fromBlockState(MbdComponents.DummyComponentBlock.defaultBlockState()));
    tileEntity = (DummyComponentTileEntity) world.getBlockEntity(BlockPos.ZERO);
    this.addWidget(new ImageWidget(30, 59, 138, 138, new GuiTextureGroup(new ColorBorderTexture(3, -1), new ColorRectTexture(0xaf444444))));
    this.addWidget(new SceneWidget(30, 59, 138, 138, world).setRenderedCore(Collections.singleton(BlockPos.ZERO), null).setRenderSelect(false).setRenderFacing(false));
    this.addWidget(new ImageWidget(30, 65, 138, 15, textTexture = new TextTexture("", 0xff00ff00).setDropShadow(true).setWidth(138).setType(TextTexture.TextType.ROLL)));
}
Also used : ColorBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) GuiTextureGroup(com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup) SceneWidget(com.lowdragmc.lowdraglib.gui.widget.SceneWidget) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 2 with TrackedDummyWorld

use of com.lowdragmc.lowdraglib.utils.TrackedDummyWorld in project Multiblocked by Low-Drag-MC.

the class TemplateBuilderWidget method onSelected.

@OnlyIn(Dist.CLIENT)
public void onSelected(ItemStack itemStack, int slot) {
    if (this.selected != itemStack) {
        this.selected = itemStack;
        this.selectedSlot = slot;
        if (selected != null && isRemote()) {
            this.pos = null;
            this.facing = null;
            templateButton.setVisible(true);
            if (ItemBlueprint.isRaw(itemStack)) {
                BlockPos[] poses = ItemBlueprint.getPos(itemStack);
                World world = table.getLevel();
                sceneWidget.createScene(world);
                if (poses != null && world.hasChunksAt(poses[0], poses[1])) {
                    Set<BlockPos> rendered = new HashSet<>();
                    for (int x = poses[0].getX(); x <= poses[1].getX(); x++) {
                        for (int y = poses[0].getY(); y <= poses[1].getY(); y++) {
                            for (int z = poses[0].getZ(); z <= poses[1].getZ(); z++) {
                                if (!world.isEmptyBlock(new BlockPos(x, y, z))) {
                                    rendered.add(new BlockPos(x, y, z));
                                }
                            }
                        }
                    }
                    sceneWidget.setRenderedCore(rendered, null);
                }
            } else if (itemStack.getTagElement("pattern") != null) {
                String json = itemStack.getTagElement("pattern").getString("json");
                JsonBlockPattern pattern = Multiblocked.GSON.fromJson(json, JsonBlockPattern.class);
                int[] centerOffset = pattern.getCenterOffset();
                String[][] patternString = pattern.pattern;
                Set<BlockPos> rendered = new HashSet<>();
                TrackedDummyWorld world = new TrackedDummyWorld();
                sceneWidget.createScene(world);
                int offset = Math.max(patternString.length, Math.max(patternString[0].length, patternString[0][0].length()));
                for (int i = 0; i < patternString.length; i++) {
                    for (int j = 0; j < patternString[0].length; j++) {
                        for (int k = 0; k < patternString[0][0].length(); k++) {
                            char symbol = patternString[i][j].charAt(k);
                            BlockPos pos = pattern.getActualPosOffset(k - centerOffset[2], j - centerOffset[1], i - centerOffset[0], Direction.NORTH).offset(offset, offset, offset);
                            world.addBlock(pos, BlockInfo.fromBlockState(MbdComponents.DummyComponentBlock.defaultBlockState()));
                            DummyComponentTileEntity tileEntity = (DummyComponentTileEntity) world.getBlockEntity(pos);
                            ComponentDefinition definition = null;
                            assert tileEntity != null;
                            if (pattern.symbolMap.containsKey(symbol)) {
                                Set<BlockInfo> candidates = new HashSet<>();
                                for (String s : pattern.symbolMap.get(symbol)) {
                                    SimplePredicate predicate = pattern.predicates.get(s);
                                    if (predicate instanceof PredicateComponent && ((PredicateComponent) predicate).definition != null) {
                                        definition = ((PredicateComponent) predicate).definition;
                                        break;
                                    } else if (predicate != null && predicate.candidates != null) {
                                        candidates.addAll(Arrays.asList(predicate.candidates.get()));
                                    }
                                }
                                definition = getComponentDefinition(definition, candidates);
                            }
                            if (definition != null) {
                                tileEntity.setDefinition(definition);
                            }
                            tileEntity.isFormed = false;
                            tileEntity.setLevelAndPosition(world, pos);
                            rendered.add(pos);
                        }
                    }
                }
                sceneWidget.setRenderedCore(rendered, null);
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) PredicateComponent(com.lowdragmc.multiblocked.api.pattern.predicates.PredicateComponent) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) World(net.minecraft.world.World) ItemBlueprint(com.lowdragmc.multiblocked.api.item.ItemBlueprint) SimplePredicate(com.lowdragmc.multiblocked.api.pattern.predicates.SimplePredicate) JsonBlockPattern(com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern) BlockPos(net.minecraft.util.math.BlockPos) DummyComponentTileEntity(com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity) HashSet(java.util.HashSet) ComponentDefinition(com.lowdragmc.multiblocked.api.definition.ComponentDefinition) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 3 with TrackedDummyWorld

use of com.lowdragmc.lowdraglib.utils.TrackedDummyWorld in project Multiblocked by Low-Drag-MC.

the class FEMultiblockCapability method getCandidates.

@Override
public BlockInfo[] getCandidates() {
    List<BlockInfo> list = new ArrayList<>();
    TrackedDummyWorld dummyWorld = new TrackedDummyWorld();
    for (Block block : ForgeRegistries.BLOCKS.getValues()) {
        if (block.getRegistryName() != null) {
            String path = block.getRegistryName().getPath();
            if (path.contains("energy") || path.contains("rf")) {
                try {
                    if (block.hasTileEntity(block.defaultBlockState())) {
                        TileEntity tileEntity = block.createTileEntity(block.defaultBlockState(), dummyWorld);
                        if (tileEntity != null && isBlockHasCapability(IO.BOTH, tileEntity)) {
                            list.add(new BlockInfo(block.defaultBlockState(), tileEntity));
                        }
                    }
                } catch (Throwable ignored) {
                }
            }
        }
    }
    list.add(BlockInfo.fromBlock(MbdComponents.COMPONENT_BLOCKS_REGISTRY.get(new ResourceLocation(Multiblocked.MODID, "energy_input"))));
    list.add(BlockInfo.fromBlock(MbdComponents.COMPONENT_BLOCKS_REGISTRY.get(new ResourceLocation(Multiblocked.MODID, "energy_output"))));
    return list.toArray(new BlockInfo[0]);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) ResourceLocation(net.minecraft.util.ResourceLocation) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block)

Example 4 with TrackedDummyWorld

use of com.lowdragmc.lowdraglib.utils.TrackedDummyWorld in project Multiblocked by Low-Drag-MC.

the class FluidMultiblockCapability method getCandidates.

@Override
public BlockInfo[] getCandidates() {
    List<BlockInfo> list = new ArrayList<>();
    TrackedDummyWorld dummyWorld = new TrackedDummyWorld();
    for (Block block : ForgeRegistries.BLOCKS.getValues()) {
        if (block.getRegistryName() != null) {
            String path = block.getRegistryName().getPath();
            if (path.contains("tank") || path.contains("fluid") || path.contains("liquid")) {
                try {
                    if (block.hasTileEntity(block.defaultBlockState())) {
                        TileEntity tileEntity = block.createTileEntity(block.defaultBlockState(), dummyWorld);
                        if (tileEntity != null && isBlockHasCapability(IO.BOTH, tileEntity)) {
                            list.add(new BlockInfo(block.defaultBlockState(), tileEntity));
                        }
                    }
                } catch (Throwable ignored) {
                }
            }
        }
    }
    list.add(BlockInfo.fromBlock(MbdComponents.COMPONENT_BLOCKS_REGISTRY.get(new ResourceLocation(Multiblocked.MODID, "fluid_input"))));
    list.add(BlockInfo.fromBlock(MbdComponents.COMPONENT_BLOCKS_REGISTRY.get(new ResourceLocation(Multiblocked.MODID, "fluid_output"))));
    return list.toArray(new BlockInfo[0]);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) ResourceLocation(net.minecraft.util.ResourceLocation) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block)

Example 5 with TrackedDummyWorld

use of com.lowdragmc.lowdraglib.utils.TrackedDummyWorld in project Multiblocked by Low-Drag-MC.

the class MultiblockPreviewRenderer method renderControllerInList.

public static void renderControllerInList(ControllerTileEntity controllerBase, MultiblockShapeInfo shapeInfo, int layer) {
    Direction frontFacing;
    previewFacing = Direction.NORTH;
    controllerPos = BlockPos.ZERO;
    mte = null;
    BlockInfo[][][] blocks = shapeInfo.getBlocks();
    blockMap = new HashMap<>();
    int maxY = 0;
    for (int x = 0; x < blocks.length; x++) {
        BlockInfo[][] aisle = blocks[x];
        maxY = Math.max(maxY, aisle.length);
        for (int y = 0; y < aisle.length; y++) {
            BlockInfo[] column = aisle[y];
            for (int z = 0; z < column.length; z++) {
                blockMap.put(new BlockPos(x, y, z), column[z]);
                ControllerTileEntity metaTE = column[z].getTileEntity() instanceof ControllerTileEntity ? (ControllerTileEntity) column[z].getTileEntity() : null;
                if (metaTE != null) {
                    if (metaTE.getDefinition().location.equals(controllerBase.getDefinition().location)) {
                        controllerPos = new BlockPos(x, y, z);
                        mte = metaTE;
                    }
                }
            }
        }
    }
    world = new TrackedDummyWorld();
    world.addBlocks(blockMap);
    int finalMaxY = layer % (maxY + 1);
    world.setRenderFilter(pos -> pos.getY() + 1 == finalMaxY || finalMaxY == 0);
    facing = controllerBase.getFrontFacing();
    spin = Direction.NORTH;
    frontFacing = facing.getStepY() == 0 ? facing : facing.getStepY() < 0 ? spin : spin.getOpposite();
    rotatePreviewBy = Rotation.values()[(4 + frontFacing.get2DDataValue() - previewFacing.get2DDataValue()) % 4];
    if (mte != null) {
        mbpPos = controllerBase.getBlockPos();
    }
}
Also used : BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)

Aggregations

TrackedDummyWorld (com.lowdragmc.lowdraglib.utils.TrackedDummyWorld)8 BlockPos (net.minecraft.util.math.BlockPos)5 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)5 TextTexture (com.lowdragmc.lowdraglib.gui.texture.TextTexture)4 ImageWidget (com.lowdragmc.lowdraglib.gui.widget.ImageWidget)4 BlockInfo (com.lowdragmc.lowdraglib.utils.BlockInfo)4 DummyComponentTileEntity (com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity)4 ComponentDefinition (com.lowdragmc.multiblocked.api.definition.ComponentDefinition)3 PredicateComponent (com.lowdragmc.multiblocked.api.pattern.predicates.PredicateComponent)3 SimplePredicate (com.lowdragmc.multiblocked.api.pattern.predicates.SimplePredicate)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)2 ColorBorderTexture (com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture)2 ColorRectTexture (com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture)2 SceneWidget (com.lowdragmc.lowdraglib.gui.widget.SceneWidget)2 Block (net.minecraft.block.Block)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ResourceLocation (net.minecraft.util.ResourceLocation)2