Search in sources :

Example 21 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project minecolonies by Minecolonies.

the class ClientEventHandler method renderWorldLastEvent.

/**
 * Used to catch the renderWorldLastEvent in order to draw the debug nodes for pathfinding.
 *
 * @param event the catched event.
 */
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void renderWorldLastEvent(@NotNull final RenderWorldLastEvent event) {
    Pathfinding.debugDraw(event.getPartialTicks(), event.getMatrixStack());
    final Blueprint structure = Settings.instance.getActiveStructure();
    final ClientWorld world = Minecraft.getInstance().level;
    final PlayerEntity player = Minecraft.getInstance().player;
    if (structure != null) {
        handleRenderStructure(event, world, player);
    }
    if (player.getMainHandItem().getItem() == ModItems.scepterGuard) {
        handleRenderScepterGuard(event, world, player);
    } else if (player.getMainHandItem().getItem() == ModItems.bannerRallyGuards) {
        handleRenderBannerRallyGuards(event, world, player);
    } else if (player.getMainHandItem().getItem() == com.ldtteam.structurize.items.ModItems.buildTool.get()) {
        handleRenderBuildTool(event, world, player);
    } else {
        alreadyRequestedStructures.clear();
    }
    DebugRendererChunkBorder.renderWorldLastEvent(event);
    renderBuffer.endBatch();
}
Also used : Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) ClientWorld(net.minecraft.client.world.ClientWorld) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 22 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project minecolonies by Minecolonies.

the class DecorationBuildRequestMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    final IColony colony = IColonyManager.getInstance().getColonyByPosFromDim(dimension, pos);
    if (colony == null) {
        return;
    }
    final PlayerEntity player = ctxIn.getSender();
    // Verify player has permission to change this huts settings
    if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
        return;
    }
    final TileEntity entity = player.getCommandSenderWorld().getBlockEntity(pos);
    if (entity instanceof TileEntityDecorationController) {
        final Optional<Map.Entry<Integer, IWorkOrder>> wo = colony.getWorkManager().getWorkOrders().entrySet().stream().filter(entry -> entry.getValue() instanceof WorkOrderBuildDecoration).filter(entry -> ((WorkOrderBuildDecoration) entry.getValue()).getSchematicLocation().equals(pos)).findFirst();
        if (wo.isPresent()) {
            colony.getWorkManager().removeWorkOrder(wo.get().getKey());
            return;
        }
        int difference = 0;
        final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), this.pos, name + level, new PlacementSettings(), true);
        final Blueprint blueprint = structure.getBluePrint();
        if (blueprint != null) {
            final BlockState structureState = structure.getBluePrint().getBlockInfoAsMap().get(structure.getBluePrint().getPrimaryBlockOffset()).getState();
            if (structureState != null) {
                if (!(structureState.getBlock() instanceof BlockDecorationController)) {
                    Log.getLogger().error(String.format("Schematic %s doesn't have a correct Primary Offset", name + level));
                    return;
                }
                final int structureRotation = structureState.getValue(BlockDecorationController.FACING).get2DDataValue();
                final int worldRotation = colony.getWorld().getBlockState(this.pos).getValue(BlockDecorationController.FACING).get2DDataValue();
                if (structureRotation <= worldRotation) {
                    difference = worldRotation - structureRotation;
                } else {
                    difference = 4 + worldRotation - structureRotation;
                }
            }
        }
        final BlockState state = player.getCommandSenderWorld().getBlockState(pos);
        final WorkOrderBuildDecoration order = new WorkOrderBuildDecoration(name + level, name + level, difference, pos, state.getValue(BlockDecorationController.MIRROR));
        if (level != ((TileEntityDecorationController) entity).getTier()) {
            order.setLevelUp();
        }
        colony.getWorkManager().addWorkOrder(order, false);
    }
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) Action(com.minecolonies.api.colony.permissions.Action) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) RegistryKey(net.minecraft.util.RegistryKey) Map(java.util.Map) Log(com.minecolonies.api.util.Log) BlockState(net.minecraft.block.BlockState) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) LogicalSide(net.minecraftforge.fml.LogicalSide) IMessage(com.minecolonies.api.network.IMessage) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) IColonyManager(com.minecolonies.api.colony.IColonyManager) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Registry(net.minecraft.util.registry.Registry) Nullable(org.jetbrains.annotations.Nullable) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration) ResourceLocation(net.minecraft.util.ResourceLocation) IColony(com.minecolonies.api.colony.IColony) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) IColony(com.minecolonies.api.colony.IColony) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)

Example 23 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project minecolonies by Minecolonies.

the class ItemSupplyChestDeployer method canShipBePlaced.

/**
 * Checks if the ship can be placed.
 *
 * @param world              the world.
 * @param pos                the pos.
 * @param ship               the blueprint.
 * @param placementErrorList the list of placement errors.
 * @param placer             the placer.
 * @return true if so.
 */
public static boolean canShipBePlaced(@NotNull final World world, @NotNull final BlockPos pos, final Blueprint ship, @NotNull final List<PlacementError> placementErrorList, final PlayerEntity placer) {
    if (MineColonies.getConfig().getServer().noSupplyPlacementRestrictions.get()) {
        return true;
    }
    final int sizeX = ship.getSizeX();
    final int sizeZ = ship.getSizeZ();
    final int waterLevel = BlueprintTagUtils.getNumberOfGroundLevels(ship, DEFAULT_WATER_LEVELS);
    final BlockPos zeroPos = pos.subtract(ship.getPrimaryBlockOffset());
    for (int z = zeroPos.getZ(); z < zeroPos.getZ() + sizeZ; z++) {
        for (int x = zeroPos.getX(); x < zeroPos.getX() + sizeX; x++) {
            for (int y = zeroPos.getY(); y <= zeroPos.getY() + waterLevel + SCAN_HEIGHT; y++) {
                if (y < zeroPos.getY() + waterLevel) {
                    checkFluidAndNotInColony(world, new BlockPos(x, y, z), placementErrorList, placer);
                } else if (world.getBlockState(new BlockPos(x, y, z)).getMaterial().isSolid()) {
                    final PlacementError placementError = new PlacementError(PlacementError.PlacementErrorType.NEEDS_AIR_ABOVE, new BlockPos(x, y, z));
                    placementErrorList.add(placementError);
                }
            }
        }
    }
    return placementErrorList.isEmpty();
}
Also used : PlacementError(com.ldtteam.structurize.placement.handlers.placement.PlacementError) BlockPos(net.minecraft.util.math.BlockPos) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 24 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.

the class BlueprintHandler method draw.

/**
 * Draw a blueprint with a rotation, mirror and offset.
 *
 * @param blueprint the wayPointBlueprint to draw.
 * @param pos       its position.
 */
public void draw(final Blueprint blueprint, final BlockPos pos, final MatrixStack stack, final float partialTicks) {
    if (blueprint == null) {
        Log.getLogger().warn("Trying to draw null blueprint!");
        return;
    }
    Minecraft.getInstance().getProfiler().push("struct_render_cache");
    final int blueprintHash = blueprint.hashCode();
    final BlueprintRenderer rendererRef = rendererCache.get(blueprintHash);
    final BlueprintRenderer renderer = rendererRef == null ? BlueprintRenderer.buildRendererForBlueprint(blueprint) : rendererRef;
    if (rendererRef == null) {
        rendererCache.put(blueprintHash, renderer);
    }
    renderer.updateBlueprint(blueprint);
    renderer.draw(pos, stack, partialTicks);
    evictTimeCache.put(blueprintHash, System.currentTimeMillis());
    Minecraft.getInstance().getProfiler().pop();
}
Also used : Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 25 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.

the class WindowShapeTool method init.

private void init(final BlockPos pos, final boolean shouldUpdate) {
    if (!hasPermission())
        return;
    @Nullable final Blueprint structure = Settings.instance.getActiveStructure();
    if (structure != null) {
        rotation = Settings.instance.getRotation();
        this.shapeWidth = Settings.instance.getWidth();
        this.shapeLength = Settings.instance.getLength();
        this.shapeHeight = Settings.instance.getHeight();
        this.shapeFrequency = Settings.instance.getFrequency();
        this.shapeEquation = Settings.instance.getEquation();
    } else if (pos != null) {
        this.pos = pos;
        Settings.instance.setPosition(pos);
        Settings.instance.setRotation(0);
    }
    // Register all necessary buttons with the window.
    registerButton(BUTTON_CONFIRM, this::confirmClicked);
    registerButton(BUTTON_CANCEL, this::cancelClicked);
    registerButton(BUTTON_LEFT, this::moveLeftClicked);
    registerButton(BUTTON_MIRROR, this::mirror);
    registerButton(BUTTON_RIGHT, this::moveRightClicked);
    registerButton(BUTTON_BACKWARD, this::moveBackClicked);
    registerButton(BUTTON_FORWARD, this::moveForwardClicked);
    registerButton(BUTTON_UP, WindowShapeTool::moveUpClicked);
    registerButton(BUTTON_DOWN, WindowShapeTool::moveDownClicked);
    registerButton(BUTTON_ROTATE_RIGHT, this::rotateRightClicked);
    registerButton(BUTTON_ROTATE_LEFT, this::rotateLeftClicked);
    registerButton(BUTTON_PICK_MAIN_BLOCK, this::pickMainBlock);
    registerButton(BUTTON_PICK_FILL_BLOCK, this::pickFillBlock);
    registerButton(BUTTON_UNDOREDO, b -> {
        close();
        new WindowUndoRedo().open();
    });
    registerButton(BUTTON_HOLLOW, this::hollowShapeToggle);
    registerButton(BUTTON_PASTE, this::pasteClicked);
    inputWidth = findPaneOfTypeByID(INPUT_WIDTH, TextField.class);
    inputLength = findPaneOfTypeByID(INPUT_LENGTH, TextField.class);
    inputHeight = findPaneOfTypeByID(INPUT_HEIGHT, TextField.class);
    inputFrequency = findPaneOfTypeByID(INPUT_FREQUENCY, TextField.class);
    inputShape = findPaneOfTypeByID(INPUT_SHAPE, TextField.class);
    inputWidth.setText(Integer.toString(Settings.instance.getWidth()));
    inputLength.setText(Integer.toString(Settings.instance.getLength()));
    inputHeight.setText(Integer.toString(Settings.instance.getHeight()));
    inputFrequency.setText(Integer.toString(Settings.instance.getFrequency()));
    inputShape.setText(Settings.instance.getEquation());
    registerButton(INPUT_WIDTH + BUTTON_MINUS, () -> adjust(inputWidth, Settings.instance.getWidth() - 1));
    registerButton(INPUT_WIDTH + BUTTON_PLUS, () -> adjust(inputWidth, Settings.instance.getWidth() + 1));
    registerButton(INPUT_LENGTH + BUTTON_MINUS, () -> adjust(inputLength, Settings.instance.getLength() - 1));
    registerButton(INPUT_LENGTH + BUTTON_PLUS, () -> adjust(inputLength, Settings.instance.getLength() + 1));
    registerButton(INPUT_HEIGHT + BUTTON_MINUS, () -> adjust(inputHeight, Settings.instance.getHeight() - 1));
    registerButton(INPUT_HEIGHT + BUTTON_PLUS, () -> adjust(inputHeight, Settings.instance.getHeight() + 1));
    registerButton(INPUT_FREQUENCY + BUTTON_MINUS, () -> adjust(inputFrequency, Settings.instance.getFrequency() - 1));
    registerButton(INPUT_FREQUENCY + BUTTON_PLUS, () -> adjust(inputFrequency, Settings.instance.getFrequency() + 1));
    sections.clear();
    sections.addAll(Arrays.stream(Shape.values()).map(Enum::name).collect(Collectors.toList()));
    sectionsDropDownList = findPaneOfTypeByID(DROPDOWN_STYLE_ID, DropDownList.class);
    sectionsDropDownList.setHandler(this::onDropDownListChanged);
    sectionsDropDownList.setDataProvider(new SectionDropDownList());
    sectionsDropDownList.setSelectedIndex(Settings.instance.getShape().ordinal());
    registerButton("nextShape", sectionsDropDownList::selectNext);
    registerButton("previousShape", sectionsDropDownList::selectPrevious);
    disableInputIfNecessary();
    if (structure == null || shouldUpdate) {
        genShape();
    }
    updateRotationState();
    findPaneOfTypeByID(BUTTON_HOLLOW, ToggleButton.class).setActiveState(Settings.instance.isHollow() ? "hollow" : "solid");
}
Also used : Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) DropDownList(com.ldtteam.blockout.views.DropDownList) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)37 BlockPos (net.minecraft.util.math.BlockPos)23 BlockState (net.minecraft.block.BlockState)13 StructureName (com.ldtteam.structurize.management.StructureName)8 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)8 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)8 PlayerEntity (net.minecraft.entity.player.PlayerEntity)6 TileEntity (net.minecraft.tileentity.TileEntity)6 Nullable (org.jetbrains.annotations.Nullable)6 BlockInfo (com.ldtteam.structurize.util.BlockInfo)5 NotNull (org.jetbrains.annotations.NotNull)5 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)4 World (net.minecraft.world.World)4 Optional (java.util.Optional)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 SchematicRequestMessage (com.ldtteam.structurize.network.messages.SchematicRequestMessage)2 PlacementError (com.ldtteam.structurize.placement.handlers.placement.PlacementError)2 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)2 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)2 IColony (com.minecolonies.api.colony.IColony)2