Search in sources :

Example 1 with MBDBlockStateRenderer

use of com.lowdragmc.multiblocked.client.renderer.impl.MBDBlockStateRenderer in project Multiblocked by Low-Drag-MC.

the class ControllerBuilderWidget method onBuildTemplate.

@Override
protected void onBuildTemplate(ClickData clickData) {
    if (clickData.isRemote) {
        if (pos != null && facing != null && selected != null && facing.getAxis() != Direction.Axis.Y) {
            BlockPos[] poses = ItemBlueprint.getPos(selected);
            if (poses != null) {
                World world = table.getLevel();
                ResourceLocation location = new ResourceLocation("mod_id:component_id");
                ControllerDefinition controllerDefinition = new ControllerDefinition(location);
                controllerDefinition.baseRenderer = new MBDBlockStateRenderer(world.getBlockState(pos));
                new ControllerWidget(this, controllerDefinition, new JsonBlockPattern(world, location, pos, facing, poses[0].getX(), poses[0].getY(), poses[0].getZ(), poses[1].getX(), poses[1].getY(), poses[1].getZ()), "empty", jsonObject -> {
                    if (jsonObject != null) {
                        FileUtility.saveJson(new File(Multiblocked.location, "definition/controller/" + jsonObject.get("location").getAsString().replace(":", "_") + ".json"), jsonObject);
                        updateList();
                    }
                });
            }
        } else {
        // TODO
        }
    }
}
Also used : MBDBlockStateRenderer(com.lowdragmc.multiblocked.client.renderer.impl.MBDBlockStateRenderer) JsonBlockPattern(com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern) ControllerDefinition(com.lowdragmc.multiblocked.api.definition.ControllerDefinition) ControllerWidget(com.lowdragmc.multiblocked.api.gui.blueprint_table.components.ControllerWidget) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) World(net.minecraft.world.World) File(java.io.File)

Example 2 with MBDBlockStateRenderer

use of com.lowdragmc.multiblocked.client.renderer.impl.MBDBlockStateRenderer in project Multiblocked by Low-Drag-MC.

the class TemplateBuilderWidget method getComponentDefinition.

public static ComponentDefinition getComponentDefinition(ComponentDefinition definition, Set<BlockInfo> candidates) {
    if (candidates.size() == 1) {
        definition = new PartDefinition(new ResourceLocation(Multiblocked.MODID, "i_renderer"));
        definition.baseRenderer = new MBDBlockStateRenderer(candidates.toArray(new BlockInfo[0])[0]);
    } else if (!candidates.isEmpty()) {
        definition = new PartDefinition(new ResourceLocation(Multiblocked.MODID, "i_renderer"));
        definition.baseRenderer = new CycleBlockStateRenderer(candidates.toArray(new BlockInfo[0]));
    }
    return definition;
}
Also used : CycleBlockStateRenderer(com.lowdragmc.multiblocked.client.renderer.impl.CycleBlockStateRenderer) MBDBlockStateRenderer(com.lowdragmc.multiblocked.client.renderer.impl.MBDBlockStateRenderer) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) ResourceLocation(net.minecraft.util.ResourceLocation) PartDefinition(com.lowdragmc.multiblocked.api.definition.PartDefinition)

Example 3 with MBDBlockStateRenderer

use of com.lowdragmc.multiblocked.client.renderer.impl.MBDBlockStateRenderer in project Multiblocked by Low-Drag-MC.

the class ControllerWidget method updateScene.

@OnlyIn(Dist.CLIENT)
private void updateScene(JsonBlockPattern jsonPattern) {
    if (thread != null) {
        thread.interrupt();
        thread = null;
    }
    TrackedDummyWorld world = new TrackedDummyWorld();
    tiles.clear();
    sceneWidget.createScene(world);
    ImageWidget imageWidget;
    sceneWidget.addWidget(imageWidget = new ImageWidget(0, 0, sceneWidget.getSize().width, sceneWidget.getSize().height));
    imageWidget.setVisible(jsonPattern.pattern.length * jsonPattern.pattern[0].length * jsonPattern.pattern[0][0].length() > 1000);
    thread = new Thread(() -> {
        int[] centerOffset = jsonPattern.getCenterOffset();
        String[][] pattern = jsonPattern.pattern;
        Set<BlockPos> posSet = new HashSet<>();
        int offset = Math.max(pattern.length, Math.max(pattern[0].length, pattern[0][0].length()));
        int sum = jsonPattern.pattern.length * jsonPattern.pattern[0].length * jsonPattern.pattern[0][0].length();
        AtomicDouble progress = new AtomicDouble(0);
        imageWidget.setImage(new TextTexture("building scene!").setSupplier(() -> "building scene! " + String.format("%.1f", progress.get()) + "%%").setWidth(sceneWidget.getSize().width));
        int count = 0;
        for (int i = 0; i < pattern.length; i++) {
            for (int j = 0; j < pattern[0].length; j++) {
                for (int k = 0; k < pattern[0][0].length(); k++) {
                    if (Thread.interrupted()) {
                        sceneWidget.waitToRemoved(imageWidget);
                        return;
                    }
                    count++;
                    progress.set(count * 100.0 / sum);
                    char symbol = pattern[i][j].charAt(k);
                    BlockPos pos = jsonPattern.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;
                    boolean disableFormed = false;
                    if (jsonPattern.symbolMap.containsKey(symbol)) {
                        Set<BlockInfo> candidates = new HashSet<>();
                        for (String s : jsonPattern.symbolMap.get(symbol)) {
                            SimplePredicate predicate = jsonPattern.predicates.get(s);
                            if (predicate instanceof PredicateComponent && ((PredicateComponent) predicate).definition != null) {
                                definition = ((PredicateComponent) predicate).definition;
                                disableFormed |= predicate.disableRenderFormed;
                                break;
                            } else if (predicate != null && predicate.candidates != null) {
                                candidates.addAll(Arrays.asList(predicate.candidates.get()));
                                disableFormed |= predicate.disableRenderFormed;
                            }
                        }
                        definition = TemplateBuilderWidget.getComponentDefinition(definition, candidates);
                    }
                    if (definition != null) {
                        tileEntity.setDefinition(definition);
                        if (disableFormed) {
                            definition.formedRenderer = new MBDBlockStateRenderer(Blocks.AIR.defaultBlockState());
                        }
                    }
                    tileEntity.isFormed = isFormed;
                    tileEntity.setLevelAndPosition(world, pos);
                    posSet.add(pos);
                    tiles.add(tileEntity);
                }
            }
        }
        Minecraft.getInstance().execute(() -> {
            sceneWidget.setRenderedCore(posSet, null);
            sceneWidget.waitToRemoved(imageWidget);
        });
        thread = null;
    });
    thread.start();
}
Also used : MBDBlockStateRenderer(com.lowdragmc.multiblocked.client.renderer.impl.MBDBlockStateRenderer) HashSet(java.util.HashSet) Set(java.util.Set) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) PredicateComponent(com.lowdragmc.multiblocked.api.pattern.predicates.PredicateComponent) SimplePredicate(com.lowdragmc.multiblocked.api.pattern.predicates.SimplePredicate) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) BlockPos(net.minecraft.util.math.BlockPos) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) DummyComponentTileEntity(com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity) ComponentDefinition(com.lowdragmc.multiblocked.api.definition.ComponentDefinition) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Aggregations

MBDBlockStateRenderer (com.lowdragmc.multiblocked.client.renderer.impl.MBDBlockStateRenderer)3 TrackedDummyWorld (com.lowdragmc.lowdraglib.utils.TrackedDummyWorld)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 BlockPos (net.minecraft.util.math.BlockPos)2 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1 TextTexture (com.lowdragmc.lowdraglib.gui.texture.TextTexture)1 ImageWidget (com.lowdragmc.lowdraglib.gui.widget.ImageWidget)1 BlockInfo (com.lowdragmc.lowdraglib.utils.BlockInfo)1 ComponentDefinition (com.lowdragmc.multiblocked.api.definition.ComponentDefinition)1 ControllerDefinition (com.lowdragmc.multiblocked.api.definition.ControllerDefinition)1 PartDefinition (com.lowdragmc.multiblocked.api.definition.PartDefinition)1 ControllerWidget (com.lowdragmc.multiblocked.api.gui.blueprint_table.components.ControllerWidget)1 JsonBlockPattern (com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern)1 PredicateComponent (com.lowdragmc.multiblocked.api.pattern.predicates.PredicateComponent)1 SimplePredicate (com.lowdragmc.multiblocked.api.pattern.predicates.SimplePredicate)1 DummyComponentTileEntity (com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity)1 CycleBlockStateRenderer (com.lowdragmc.multiblocked.client.renderer.impl.CycleBlockStateRenderer)1 File (java.io.File)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1