Search in sources :

Example 6 with IMultiblockedRenderer

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

the class ComponentTileEntity method getRenderer.

public IMultiblockedRenderer getRenderer() {
    IMultiblockedRenderer lastRenderer = currentRenderer;
    currentRenderer = updateCurrentRenderer();
    if (lastRenderer != currentRenderer) {
        if (lastRenderer != null) {
            lastRenderer.onPostAccess(this);
        }
        if (currentRenderer != null) {
            currentRenderer.onPreAccess(this);
        }
    }
    return currentRenderer;
}
Also used : IMultiblockedRenderer(com.lowdragmc.multiblocked.client.renderer.IMultiblockedRenderer)

Example 7 with IMultiblockedRenderer

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

the class MBDIModelRenderer method createConfigurator.

@Override
public Supplier<IMultiblockedRenderer> createConfigurator(WidgetGroup parent, DraggableScrollableWidgetGroup group, IMultiblockedRenderer current) {
    TextFieldWidget tfw = new TextFieldWidget(1, 1, 150, 20, null, null);
    group.addWidget(tfw);
    File path = new File(Multiblocked.location, "assets/multiblocked/models");
    group.addWidget(new ButtonWidget(155, 1, 20, 20, cd -> DialogWidget.showFileDialog(parent, "select a java model", path, true, DialogWidget.suffixFilter(".json"), r -> {
        if (r != null && r.isFile()) {
            tfw.setCurrentString("multiblocked:" + r.getPath().replace(path.getPath(), "").substring(1).replace(".json", "").replace('\\', '/'));
        }
    })).setButtonTexture(new ResourceTexture("multiblocked:textures/gui/darkened_slot.png"), new TextTexture("F", -1)).setHoverTooltips("multiblocked.gui.tips.file_selector"));
    if (current instanceof IModelRenderer && ((IModelRenderer) current).modelLocation != null) {
        tfw.setCurrentString(((IModelRenderer) current).modelLocation.toString());
    }
    return () -> {
        if (tfw.getCurrentString().isEmpty()) {
            return null;
        } else {
            return new MBDIModelRenderer(new ResourceLocation(tfw.getCurrentString()));
        }
    };
}
Also used : JsonObject(com.google.gson.JsonObject) TextFieldWidget(com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) IModelRenderer(com.lowdragmc.lowdraglib.client.renderer.impl.IModelRenderer) Supplier(java.util.function.Supplier) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) File(java.io.File) DialogWidget(com.lowdragmc.lowdraglib.gui.widget.DialogWidget) Gson(com.google.gson.Gson) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ResourceLocation(net.minecraft.util.ResourceLocation) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) IMultiblockedRenderer(com.lowdragmc.multiblocked.client.renderer.IMultiblockedRenderer) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ResourceLocation(net.minecraft.util.ResourceLocation) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) TextFieldWidget(com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget) IModelRenderer(com.lowdragmc.lowdraglib.client.renderer.impl.IModelRenderer) File(java.io.File) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)

Example 8 with IMultiblockedRenderer

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

the class ComponentWidget method createScene.

@OnlyIn(Dist.CLIENT)
protected WidgetGroup createScene(int x, int y, String text, String tips, IMultiblockedRenderer init, Consumer<IMultiblockedRenderer> onUpdate) {
    TrackedDummyWorld world = new TrackedDummyWorld();
    world.addBlock(BlockPos.ZERO, BlockInfo.fromBlockState(MbdComponents.DummyComponentBlock.defaultBlockState()));
    DummyComponentTileEntity tileEntity = (DummyComponentTileEntity) world.getBlockEntity(BlockPos.ZERO);
    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.ZERO), 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).setHoverTooltips(tips));
    return widgetGroup;
}
Also used : JSONUtils(net.minecraft.util.JSONUtils) JsonObject(com.google.gson.JsonObject) TabButton(com.lowdragmc.lowdraglib.gui.widget.TabButton) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) CapabilityTrait(com.lowdragmc.multiblocked.api.capability.trait.CapabilityTrait) IRendererWidget(com.lowdragmc.multiblocked.api.gui.dialogs.IRendererWidget) MultiblockCapability(com.lowdragmc.multiblocked.api.capability.MultiblockCapability) ResourceBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture) TabContainer(com.lowdragmc.lowdraglib.gui.widget.TabContainer) Dist(net.minecraftforge.api.distmarker.Dist) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) TextBoxWidget(com.lowdragmc.lowdraglib.gui.widget.TextBoxWidget) Minecraft(net.minecraft.client.Minecraft) LabelWidget(com.lowdragmc.lowdraglib.gui.widget.LabelWidget) ComponentDefinition(com.lowdragmc.multiblocked.api.definition.ComponentDefinition) DummyComponentTileEntity(com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) IMultiblockedRenderer(com.lowdragmc.multiblocked.client.renderer.IMultiblockedRenderer) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ResourceTextureWidget(com.lowdragmc.multiblocked.api.gui.dialogs.ResourceTextureWidget) MbdComponents(com.lowdragmc.multiblocked.api.registry.MbdComponents) TextFieldWidget(com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget) PartDefinition(com.lowdragmc.multiblocked.api.definition.PartDefinition) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) ColorBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) SwitchWidget(com.lowdragmc.lowdraglib.gui.widget.SwitchWidget) BlockPos(net.minecraft.util.math.BlockPos) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) SceneWidget(com.lowdragmc.lowdraglib.gui.widget.SceneWidget) DialogWidget(com.lowdragmc.lowdraglib.gui.widget.DialogWidget) MbdCapabilities(com.lowdragmc.multiblocked.api.registry.MbdCapabilities) Consumer(java.util.function.Consumer) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ResourceLocation(net.minecraft.util.ResourceLocation) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) Collections(java.util.Collections) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) IRendererWidget(com.lowdragmc.multiblocked.api.gui.dialogs.IRendererWidget) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) PartDefinition(com.lowdragmc.multiblocked.api.definition.PartDefinition) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) ColorBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture) ResourceLocation(net.minecraft.util.ResourceLocation) LabelWidget(com.lowdragmc.lowdraglib.gui.widget.LabelWidget) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) DummyComponentTileEntity(com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity) SceneWidget(com.lowdragmc.lowdraglib.gui.widget.SceneWidget) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 9 with IMultiblockedRenderer

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

the class IRendererWidget method onChangeRenderer.

private void onChangeRenderer(String s) {
    group.clearAllWidgets();
    onUpdate = null;
    IMultiblockedRenderer current = tileEntity.getRenderer();
    String[] split = s.split("\\.");
    s = split[split.length - 1];
    if (s.equals("null")) {
        onUpdate = () -> setNewRenderer(null);
    } else {
        IMultiblockedRenderer renderer = MbdRenderers.getRenderer(s);
        if (renderer != null) {
            Supplier<IMultiblockedRenderer> supplier = renderer.createConfigurator(this, group, current);
            if (supplier != null) {
                onUpdate = () -> setNewRenderer(supplier.get());
            }
        }
    }
}
Also used : IMultiblockedRenderer(com.lowdragmc.multiblocked.client.renderer.IMultiblockedRenderer)

Aggregations

IMultiblockedRenderer (com.lowdragmc.multiblocked.client.renderer.IMultiblockedRenderer)9 JsonObject (com.google.gson.JsonObject)3 ResourceTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceTexture)3 TextTexture (com.lowdragmc.lowdraglib.gui.texture.TextTexture)3 ButtonWidget (com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)3 DialogWidget (com.lowdragmc.lowdraglib.gui.widget.DialogWidget)3 DraggableScrollableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup)3 TextFieldWidget (com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget)3 WidgetGroup (com.lowdragmc.lowdraglib.gui.widget.WidgetGroup)3 Multiblocked (com.lowdragmc.multiblocked.Multiblocked)3 Gson (com.google.gson.Gson)2 File (java.io.File)2 Collections (java.util.Collections)2 Supplier (java.util.function.Supplier)2 Minecraft (net.minecraft.client.Minecraft)2 JSONUtils (net.minecraft.util.JSONUtils)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 IModelRenderer (com.lowdragmc.lowdraglib.client.renderer.impl.IModelRenderer)1 ColorBorderTexture (com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture)1 ColorRectTexture (com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture)1