Search in sources :

Example 1 with BlockInfo

use of com.cleanroommc.multiblocked.api.pattern.util.BlockInfo in project Multiblocked by CleanroomMC.

the class TemplateBuilderWidget method onSelected.

@SideOnly(Side.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.getWorld();
                sceneWidget.createScene(world);
                if (poses != null && world.isAreaLoaded(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.isAirBlock(new BlockPos(x, y, z))) {
                                    rendered.add(new BlockPos(x, y, z));
                                }
                            }
                        }
                    }
                    sceneWidget.setRenderedCore(rendered, null);
                }
            } else if (itemStack.getSubCompound("pattern") != null) {
                String json = itemStack.getSubCompound("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], EnumFacing.NORTH).add(offset, offset, offset);
                            world.addBlock(pos, new BlockInfo(MbdComponents.DummyComponentBlock));
                            DummyComponentTileEntity tileEntity = (DummyComponentTileEntity) world.getTileEntity(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.setWorld(world);
                            tileEntity.validate();
                            rendered.add(pos);
                        }
                    }
                }
                sceneWidget.setRenderedCore(rendered, null);
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TrackedDummyWorld(com.cleanroommc.multiblocked.client.util.TrackedDummyWorld) PredicateComponent(com.cleanroommc.multiblocked.api.pattern.predicates.PredicateComponent) TrackedDummyWorld(com.cleanroommc.multiblocked.client.util.TrackedDummyWorld) World(net.minecraft.world.World) ItemBlueprint(com.cleanroommc.multiblocked.api.item.ItemBlueprint) SimplePredicate(com.cleanroommc.multiblocked.api.pattern.predicates.SimplePredicate) JsonBlockPattern(com.cleanroommc.multiblocked.api.pattern.JsonBlockPattern) BlockInfo(com.cleanroommc.multiblocked.api.pattern.util.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos) DummyComponentTileEntity(com.cleanroommc.multiblocked.api.tile.DummyComponentTileEntity) HashSet(java.util.HashSet) ComponentDefinition(com.cleanroommc.multiblocked.api.definition.ComponentDefinition) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with BlockInfo

use of com.cleanroommc.multiblocked.api.pattern.util.BlockInfo in project Multiblocked by CleanroomMC.

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 BlockStateRenderer(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.cleanroommc.multiblocked.client.renderer.impl.CycleBlockStateRenderer) BlockStateRenderer(com.cleanroommc.multiblocked.client.renderer.impl.BlockStateRenderer) CycleBlockStateRenderer(com.cleanroommc.multiblocked.client.renderer.impl.CycleBlockStateRenderer) BlockInfo(com.cleanroommc.multiblocked.api.pattern.util.BlockInfo) ResourceLocation(net.minecraft.util.ResourceLocation) PartDefinition(com.cleanroommc.multiblocked.api.definition.PartDefinition)

Example 3 with BlockInfo

use of com.cleanroommc.multiblocked.api.pattern.util.BlockInfo in project Multiblocked by CleanroomMC.

the class ControllerWidget method updateScene.

@SideOnly(Side.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], EnumFacing.NORTH).add(offset, offset, offset);
                    world.addBlock(pos, new BlockInfo(MbdComponents.DummyComponentBlock));
                    DummyComponentTileEntity tileEntity = (DummyComponentTileEntity) world.getTileEntity(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 BlockStateRenderer(Blocks.AIR.getDefaultState());
                        }
                    }
                    tileEntity.isFormed = isFormed;
                    tileEntity.setWorld(world);
                    tileEntity.validate();
                    posSet.add(pos);
                    tiles.add(tileEntity);
                }
            }
        }
        Minecraft.getMinecraft().addScheduledTask(() -> {
            sceneWidget.setRenderedCore(posSet, null);
            sceneWidget.waitToRemoved(imageWidget);
        });
        thread = null;
    });
    thread.start();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) TrackedDummyWorld(com.cleanroommc.multiblocked.client.util.TrackedDummyWorld) PredicateComponent(com.cleanroommc.multiblocked.api.pattern.predicates.PredicateComponent) SimplePredicate(com.cleanroommc.multiblocked.api.pattern.predicates.SimplePredicate) BlockStateRenderer(com.cleanroommc.multiblocked.client.renderer.impl.BlockStateRenderer) BlockInfo(com.cleanroommc.multiblocked.api.pattern.util.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos) DummyComponentTileEntity(com.cleanroommc.multiblocked.api.tile.DummyComponentTileEntity) ComponentDefinition(com.cleanroommc.multiblocked.api.definition.ComponentDefinition) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with BlockInfo

use of com.cleanroommc.multiblocked.api.pattern.util.BlockInfo in project Multiblocked by CleanroomMC.

the class ComponentWidget method createScene.

@SideOnly(Side.CLIENT)
protected WidgetGroup createScene(int x, int y, String text, String tips, IRenderer init, Consumer<IRenderer> onUpdate) {
    TrackedDummyWorld world = new TrackedDummyWorld();
    world.addBlock(BlockPos.ORIGIN, new BlockInfo(MbdComponents.DummyComponentBlock));
    DummyComponentTileEntity tileEntity = (DummyComponentTileEntity) world.getTileEntity(BlockPos.ORIGIN);
    tileEntity.setDefinition(new PartDefinition(new ResourceLocation(Multiblocked.MODID, "component_widget")));
    tileEntity.getDefinition().baseRenderer = init;
    WidgetGroup widgetGroup = new WidgetGroup(x, y, 90, 90);
    widgetGroup.addWidget(new LabelWidget(0, 0, text));
    widgetGroup.addWidget(new ImageWidget(0, 12, 90, 80, new ColorBorderTexture(2, 0xff4A82F7)));
    widgetGroup.addWidget(new SceneWidget(0, 12, 90, 80, world).setRenderedCore(Collections.singleton(BlockPos.ORIGIN), null).setRenderSelect(false).setRenderFacing(false));
    widgetGroup.addWidget(new ButtonWidget(90 - 15, 12, 15, 15, new ResourceTexture("multiblocked:textures/gui/option.png"), (cd) -> new IRendererWidget(this, tileEntity.getRenderer(), r -> {
        tileEntity.getDefinition().baseRenderer = r;
        onUpdate.accept(r);
    })).setHoverBorderTexture(1, -1).setHoverTooltip(tips));
    return widgetGroup;
}
Also used : DialogWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.DialogWidget) JsonObject(com.google.gson.JsonObject) IRenderer(com.cleanroommc.multiblocked.client.renderer.IRenderer) SceneWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.SceneWidget) SwitchWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.SwitchWidget) Multiblocked(com.cleanroommc.multiblocked.Multiblocked) TextTexture(com.cleanroommc.multiblocked.api.gui.texture.TextTexture) ButtonWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.ButtonWidget) DummyComponentTileEntity(com.cleanroommc.multiblocked.api.tile.DummyComponentTileEntity) TrackedDummyWorld(com.cleanroommc.multiblocked.client.util.TrackedDummyWorld) CapabilityTrait(com.cleanroommc.multiblocked.api.capability.trait.CapabilityTrait) MultiblockCapability(com.cleanroommc.multiblocked.api.capability.MultiblockCapability) Side(net.minecraftforge.fml.relauncher.Side) MbdCapabilities(com.cleanroommc.multiblocked.api.registry.MbdCapabilities) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) TextFieldWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.TextFieldWidget) ImageWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.ImageWidget) IRendererWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.blueprint_table.dialogs.IRendererWidget) ResourceBorderTexture(com.cleanroommc.multiblocked.api.gui.texture.ResourceBorderTexture) BlockPos(net.minecraft.util.math.BlockPos) WidgetGroup(com.cleanroommc.multiblocked.api.gui.widget.WidgetGroup) LabelWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.LabelWidget) TabContainer(com.cleanroommc.multiblocked.api.gui.widget.imp.tab.TabContainer) ColorBorderTexture(com.cleanroommc.multiblocked.api.gui.texture.ColorBorderTexture) DraggableScrollableWidgetGroup(com.cleanroommc.multiblocked.api.gui.widget.imp.DraggableScrollableWidgetGroup) Consumer(java.util.function.Consumer) BlockInfo(com.cleanroommc.multiblocked.api.pattern.util.BlockInfo) ResourceTextureWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.blueprint_table.dialogs.ResourceTextureWidget) GuiScreen(net.minecraft.client.gui.GuiScreen) PartDefinition(com.cleanroommc.multiblocked.api.definition.PartDefinition) ComponentDefinition(com.cleanroommc.multiblocked.api.definition.ComponentDefinition) JsonUtils(net.minecraft.util.JsonUtils) ColorRectTexture(com.cleanroommc.multiblocked.api.gui.texture.ColorRectTexture) TextBoxWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.TextBoxWidget) MbdComponents(com.cleanroommc.multiblocked.api.registry.MbdComponents) ResourceLocation(net.minecraft.util.ResourceLocation) ResourceTexture(com.cleanroommc.multiblocked.api.gui.texture.ResourceTexture) TabButton(com.cleanroommc.multiblocked.api.gui.widget.imp.tab.TabButton) Collections(java.util.Collections) ResourceTexture(com.cleanroommc.multiblocked.api.gui.texture.ResourceTexture) IRendererWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.blueprint_table.dialogs.IRendererWidget) TrackedDummyWorld(com.cleanroommc.multiblocked.client.util.TrackedDummyWorld) WidgetGroup(com.cleanroommc.multiblocked.api.gui.widget.WidgetGroup) DraggableScrollableWidgetGroup(com.cleanroommc.multiblocked.api.gui.widget.imp.DraggableScrollableWidgetGroup) PartDefinition(com.cleanroommc.multiblocked.api.definition.PartDefinition) ButtonWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.ButtonWidget) ColorBorderTexture(com.cleanroommc.multiblocked.api.gui.texture.ColorBorderTexture) BlockInfo(com.cleanroommc.multiblocked.api.pattern.util.BlockInfo) ResourceLocation(net.minecraft.util.ResourceLocation) LabelWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.LabelWidget) ImageWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.ImageWidget) DummyComponentTileEntity(com.cleanroommc.multiblocked.api.tile.DummyComponentTileEntity) SceneWidget(com.cleanroommc.multiblocked.api.gui.widget.imp.SceneWidget) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with BlockInfo

use of com.cleanroommc.multiblocked.api.pattern.util.BlockInfo in project Multiblocked by CleanroomMC.

the class EnergyGTCECapability method getCandidates.

@Override
public BlockInfo[] getCandidates() {
    List<BlockInfo> list = new ArrayList<>();
    if (isCEu()) {
        IBlockState blockState = GregTechAPI.MACHINE.getDefaultState();
        for (MetaTileEntityEnergyHatch energyInputHatch : MetaTileEntities.ENERGY_INPUT_HATCH) {
            if (energyInputHatch == null)
                continue;
            MetaTileEntityHolder holder = new MetaTileEntityHolder();
            ItemStack itemStack = energyInputHatch.getStackForm();
            holder.setMetaTileEntity(GregTechAPI.MTE_REGISTRY.getObjectById(itemStack.getItemDamage()));
            list.add(new BlockInfo(blockState, holder, itemStack));
        }
        for (MetaTileEntityEnergyHatch energyOutputHatch : MetaTileEntities.ENERGY_OUTPUT_HATCH) {
            if (energyOutputHatch == null)
                continue;
            MetaTileEntityHolder holder = new MetaTileEntityHolder();
            ItemStack itemStack = energyOutputHatch.getStackForm();
            holder.setMetaTileEntity(GregTechAPI.MTE_REGISTRY.getObjectById(itemStack.getItemDamage()));
            list.add(new BlockInfo(blockState, holder, itemStack));
        }
    } else {
    // time to get rid of the gtce
    }
    return list.toArray(new BlockInfo[0]);
}
Also used : MetaTileEntityEnergyHatch(gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityEnergyHatch) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) IBlockState(net.minecraft.block.state.IBlockState) BlockInfo(com.cleanroommc.multiblocked.api.pattern.util.BlockInfo) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Aggregations

BlockInfo (com.cleanroommc.multiblocked.api.pattern.util.BlockInfo)17 BlockPos (net.minecraft.util.math.BlockPos)8 TrackedDummyWorld (com.cleanroommc.multiblocked.client.util.TrackedDummyWorld)7 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)7 SimplePredicate (com.cleanroommc.multiblocked.api.pattern.predicates.SimplePredicate)6 DummyComponentTileEntity (com.cleanroommc.multiblocked.api.tile.DummyComponentTileEntity)5 ArrayList (java.util.ArrayList)5 TileEntity (net.minecraft.tileentity.TileEntity)5 ComponentDefinition (com.cleanroommc.multiblocked.api.definition.ComponentDefinition)3 ColorRectTexture (com.cleanroommc.multiblocked.api.gui.texture.ColorRectTexture)3 TextTexture (com.cleanroommc.multiblocked.api.gui.texture.TextTexture)3 ImageWidget (com.cleanroommc.multiblocked.api.gui.widget.imp.ImageWidget)3 PredicateComponent (com.cleanroommc.multiblocked.api.pattern.predicates.PredicateComponent)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 IBlockState (net.minecraft.block.state.IBlockState)3 ItemStack (net.minecraft.item.ItemStack)3 World (net.minecraft.world.World)3 Multiblocked (com.cleanroommc.multiblocked.Multiblocked)2 ControllerDefinition (com.cleanroommc.multiblocked.api.definition.ControllerDefinition)2