Search in sources :

Example 1 with JsonBlockPatternWidget

use of com.lowdragmc.multiblocked.api.gui.dialogs.JsonBlockPatternWidget in project Multiblocked by Low-Drag-MC.

the class TemplateBuilderWidget method onBuildTemplate.

protected void onBuildTemplate(ClickData clickData) {
    if (isRemote() && ItemBlueprint.isItemBlueprint(selected)) {
        JsonBlockPattern pattern = null;
        if (ItemBlueprint.isRaw(selected)) {
            BlockPos[] poses = ItemBlueprint.getPos(selected);
            World world = table.getLevel();
            if (poses != null && world.hasChunksAt(poses[0], poses[1])) {
                ControllerTileEntity controller = null;
                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++) {
                            TileEntity te = world.getBlockEntity(new BlockPos(x, y, z));
                            if (te instanceof ControllerTileEntity) {
                                controller = (ControllerTileEntity) te;
                            }
                        }
                    }
                }
                if (controller != null) {
                    pattern = new JsonBlockPattern(table.getLevel(), controller.getLocation(), controller.getBlockPos(), controller.getFrontFacing(), poses[0].getX(), poses[0].getY(), poses[0].getZ(), poses[1].getX(), poses[1].getY(), poses[1].getZ());
                } else {
                // TODO tips dialog
                }
            } else {
            // TODO tips dialog
            }
        } else if (selected.getTagElement("pattern") != null) {
            String json = selected.getTagElement("pattern").getString("json");
            pattern = Multiblocked.GSON.fromJson(json, JsonBlockPattern.class);
        }
        if (pattern != null) {
            new JsonBlockPatternWidget(this, pattern, patternResult -> {
                if (patternResult != null) {
                    if (ItemBlueprint.setPattern(selected) && patternResult.predicates.get("controller") instanceof PredicateComponent) {
                        patternResult.cleanUp();
                        String json = patternResult.toJson();
                        String controller = ((PredicateComponent) patternResult.predicates.get("controller")).location.toString();
                        selected.getOrCreateTagElement("pattern").putString("json", json);
                        selected.getOrCreateTagElement("pattern").putString("controller", controller);
                        writeClientAction(-1, buffer -> {
                            buffer.writeVarInt(selectedSlot);
                            buffer.writeUtf(json);
                            buffer.writeUtf(controller);
                        });
                    }
                }
            });
        }
    }
}
Also used : BlueprintTableTileEntity(com.lowdragmc.multiblocked.api.tile.BlueprintTableTileEntity) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity) DummyComponentTileEntity(com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) JsonBlockPattern(com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern) JsonBlockPatternWidget(com.lowdragmc.multiblocked.api.gui.dialogs.JsonBlockPatternWidget) BlockPos(net.minecraft.util.math.BlockPos) 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) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)

Aggregations

TrackedDummyWorld (com.lowdragmc.lowdraglib.utils.TrackedDummyWorld)1 JsonBlockPatternWidget (com.lowdragmc.multiblocked.api.gui.dialogs.JsonBlockPatternWidget)1 ItemBlueprint (com.lowdragmc.multiblocked.api.item.ItemBlueprint)1 JsonBlockPattern (com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern)1 PredicateComponent (com.lowdragmc.multiblocked.api.pattern.predicates.PredicateComponent)1 BlueprintTableTileEntity (com.lowdragmc.multiblocked.api.tile.BlueprintTableTileEntity)1 ControllerTileEntity (com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)1 DummyComponentTileEntity (com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1