Search in sources :

Example 1 with ControllerTileEntity

use of com.lowdragmc.multiblocked.api.tile.ControllerTileEntity in project Multiblocked by Low-Drag-MC.

the class PatternWidget method onFormedSwitch.

private void onFormedSwitch(ClickData clickData, Boolean isPressed) {
    MBPattern pattern = patterns[index];
    ControllerTileEntity controllerBase = pattern.controllerBase;
    if (isPressed) {
        loadControllerFormed(pattern.blockMap.keySet(), controllerBase);
    } else {
        sceneWidget.setRenderedCore(pattern.blockMap.keySet(), null);
        controllerBase.state = null;
        controllerBase.onStructureInvalid();
    }
}
Also used : ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)

Example 2 with ControllerTileEntity

use of com.lowdragmc.multiblocked.api.tile.ControllerTileEntity in project Multiblocked by Low-Drag-MC.

the class BlockPattern method checkPatternAt.

public boolean checkPatternAt(MultiblockState worldState, boolean savePredicate) {
    ControllerTileEntity controller = worldState.getController();
    if (controller == null) {
        worldState.setError(new PatternStringError("no controller found"));
        return false;
    }
    BlockPos centerPos = controller.getBlockPos();
    Direction frontFacing = controller.getFrontFacing();
    Set<MultiblockCapability<?>> inputCapabilities = controller.getDefinition().recipeMap.inputCapabilities;
    Set<MultiblockCapability<?>> outputCapabilities = controller.getDefinition().recipeMap.outputCapabilities;
    Direction[] facings = controller.getDefinition().allowRotate ? new Direction[] { frontFacing } : new Direction[] { Direction.SOUTH, Direction.NORTH, Direction.EAST, Direction.WEST };
    for (Direction facing : facings) {
        if (checkPatternAt(worldState, centerPos, facing, savePredicate, inputCapabilities, outputCapabilities)) {
            return true;
        }
    }
    return false;
}
Also used : MultiblockCapability(com.lowdragmc.multiblocked.api.capability.MultiblockCapability) BlockPos(net.minecraft.util.math.BlockPos) PatternStringError(com.lowdragmc.multiblocked.api.pattern.error.PatternStringError) Direction(net.minecraft.util.Direction) RelativeDirection(com.lowdragmc.multiblocked.api.pattern.util.RelativeDirection) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)

Example 3 with ControllerTileEntity

use of com.lowdragmc.multiblocked.api.tile.ControllerTileEntity in project Multiblocked by Low-Drag-MC.

the class MultiblockState method onBlockStateChanged.

public void onBlockStateChanged(BlockPos pos) {
    if (pos.equals(controllerPos)) {
        if (this.getMatchContext().containsKey("renderMask")) {
            MultiblockedNetworking.sendToAll(new SPacketRemoveDisabledRendering(controllerPos));
        }
        if (lastController != null) {
            lastController.onStructureInvalid();
        }
        MultiblockWorldSavedData mbds = MultiblockWorldSavedData.getOrCreate(world);
        mbds.removeMapping(this);
        mbds.removeLoading(controllerPos);
    } else if (error != UNLOAD_ERROR) {
        ControllerTileEntity controller = getController();
        if (controller != null && !controller.checkPattern()) {
            controller.onStructureInvalid();
            MultiblockWorldSavedData.getOrCreate(world).removeMapping(this);
        }
    }
}
Also used : MultiblockWorldSavedData(com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData) SPacketRemoveDisabledRendering(com.lowdragmc.multiblocked.network.s2c.SPacketRemoveDisabledRendering) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)

Example 4 with ControllerTileEntity

use of com.lowdragmc.multiblocked.api.tile.ControllerTileEntity in project Multiblocked by Low-Drag-MC.

the class ItemMultiblockBuilder method onItemUseFirst.

@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
    PlayerEntity player = context.getPlayer();
    if (player != null) {
        if (!player.level.isClientSide) {
            TileEntity tileEntity = player.level.getBlockEntity(context.getClickedPos());
            ItemStack hold = player.getItemInHand(context.getHand());
            if (isItemMultiblockBuilder(hold) && tileEntity instanceof ControllerTileEntity) {
                if (isRaw(hold)) {
                    BlockPattern pattern = ((ControllerTileEntity) tileEntity).getPattern();
                    if (pattern != null) {
                        pattern.autoBuild(player, new MultiblockState(player.level, context.getClickedPos()));
                    }
                    return ActionResultType.SUCCESS;
                } else {
                    String json = hold.getOrCreateTagElement("pattern").getString("json");
                    String controller = hold.getOrCreateTagElement("pattern").getString("controller");
                    if (!json.isEmpty() && !controller.isEmpty()) {
                        if (controller.equals(((ControllerTileEntity) tileEntity).getDefinition().location.toString())) {
                            JsonBlockPattern jsonBlockPattern = Multiblocked.GSON.fromJson(json, JsonBlockPattern.class);
                            jsonBlockPattern.build().autoBuild(player, new MultiblockState(player.level, context.getClickedPos()));
                            return ActionResultType.SUCCESS;
                        }
                    }
                }
            }
        }
    }
    return ActionResultType.PASS;
}
Also used : ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) JsonBlockPattern(com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern) JsonBlockPattern(com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern) BlockPattern(com.lowdragmc.multiblocked.api.pattern.BlockPattern) MultiblockState(com.lowdragmc.multiblocked.api.pattern.MultiblockState) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)

Example 5 with ControllerTileEntity

use of com.lowdragmc.multiblocked.api.tile.ControllerTileEntity in project Multiblocked by Low-Drag-MC.

the class MultiblockPreviewRenderer method renderWorldLastEvent.

@SubscribeEvent
public static void renderWorldLastEvent(RenderWorldLastEvent event) {
    if (mbpPos != null) {
        Minecraft mc = Minecraft.getInstance();
        long time = System.currentTimeMillis();
        if (time > mbpEndTime || !(mc.level != null && mc.level.getBlockEntity(mbpPos) instanceof ControllerTileEntity)) {
            resetMultiblockRender();
            layer = 0;
            return;
        }
        MatrixStack stack = event.getMatrixStack();
        Vector3d pos = mc.gameRenderer.getMainCamera().getPosition();
        stack.pushPose();
        stack.translate(-pos.x, -pos.y, -pos.z);
        RenderSystem.enableTexture();
        RenderSystem.enableBlend();
        RenderSystem.enableCull();
        RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        Minecraft.getInstance().getTextureManager().bind(AtlasTexture.LOCATION_BLOCKS);
        RenderSystem.color4f(1F, 1F, 1F, 1F);
        IRenderTypeBuffer.Impl buffer = IRenderTypeBuffer.immediate(Tessellator.getInstance().getBuilder());
        render(stack, buffer);
        buffer.endBatch();
        stack.popPose();
    }
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) IRenderTypeBuffer(net.minecraft.client.renderer.IRenderTypeBuffer) Minecraft(net.minecraft.client.Minecraft) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

ControllerTileEntity (com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)10 BlockPos (net.minecraft.util.math.BlockPos)5 TileEntity (net.minecraft.tileentity.TileEntity)4 BlockInfo (com.lowdragmc.lowdraglib.utils.BlockInfo)3 TrackedDummyWorld (com.lowdragmc.lowdraglib.utils.TrackedDummyWorld)2 MultiblockCapability (com.lowdragmc.multiblocked.api.capability.MultiblockCapability)2 JsonBlockPattern (com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern)2 PatternStringError (com.lowdragmc.multiblocked.api.pattern.error.PatternStringError)2 RelativeDirection (com.lowdragmc.multiblocked.api.pattern.util.RelativeDirection)2 HashMap (java.util.HashMap)2 BlockState (net.minecraft.block.BlockState)2 Direction (net.minecraft.util.Direction)2 World (net.minecraft.world.World)2 ItemStackKey (com.lowdragmc.lowdraglib.utils.ItemStackKey)1 BlockComponent (com.lowdragmc.multiblocked.api.block.BlockComponent)1 IO (com.lowdragmc.multiblocked.api.capability.IO)1 JsonBlockPatternWidget (com.lowdragmc.multiblocked.api.gui.dialogs.JsonBlockPatternWidget)1 ItemBlueprint (com.lowdragmc.multiblocked.api.item.ItemBlueprint)1 PartAddedEvent (com.lowdragmc.multiblocked.api.kubejs.events.PartAddedEvent)1 BlockPattern (com.lowdragmc.multiblocked.api.pattern.BlockPattern)1