Search in sources :

Example 11 with IBlueprintDataProvider

use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project Structurize by ldtteam.

the class ClientEventSubscriber method renderWorldLastEvent.

/**
 * Used to catch the renderWorldLastEvent in order to draw the debug nodes for pathfinding.
 *
 * @param event the catched event.
 */
@SubscribeEvent
public static void renderWorldLastEvent(@NotNull final RenderWorldLastEvent event) {
    Settings.instance.startStructurizePass();
    OptifineCompat.getInstance().preBlueprintDraw();
    final MatrixStack matrixStack = event.getMatrixStack();
    final float partialTicks = event.getPartialTicks();
    final IRenderTypeBuffer.Impl renderBuffer = renderBuffers.bufferSource();
    final Supplier<IVertexBuilder> linesWithCullAndDepth = () -> renderBuffer.getBuffer(RenderType.lines());
    final Supplier<IVertexBuilder> linesWithoutCullAndDepth = () -> renderBuffer.getBuffer(RenderUtils.LINES_GLINT);
    final PlayerEntity player = Minecraft.getInstance().player;
    final Blueprint blueprint = Settings.instance.getActiveStructure();
    if (blueprint != null) {
        Minecraft.getInstance().getProfiler().push("struct_render");
        final BlockPos pos = Settings.instance.getPosition();
        final BlockPos posMinusOffset = pos.subtract(blueprint.getPrimaryBlockOffset());
        StructureClientHandler.renderStructure(blueprint, partialTicks, pos, matrixStack);
        renderAnchorPos(pos, matrixStack, linesWithoutCullAndDepth.get());
        RenderUtils.renderWhiteOutlineBox(posMinusOffset, posMinusOffset.offset(blueprint.getSizeX() - 1, blueprint.getSizeY() - 1, blueprint.getSizeZ() - 1), matrixStack, linesWithCullAndDepth.get());
        renderBuffer.endBatch(RenderType.lines());
        renderBuffer.endBatch(RenderUtils.LINES_GLINT);
        Minecraft.getInstance().getProfiler().pop();
    }
    if (Settings.instance.getBox() != null) {
        Minecraft.getInstance().getProfiler().push("struct_box");
        // Used to render a red box around a scan's Primary offset (primary block)
        Settings.instance.getAnchorPos().ifPresent(pos -> renderAnchorPos(pos, matrixStack, linesWithoutCullAndDepth.get()));
        RenderUtils.renderWhiteOutlineBox(Settings.instance.getBox().getA(), Settings.instance.getBox().getB(), matrixStack, linesWithoutCullAndDepth.get());
        renderBuffer.endBatch(RenderUtils.LINES_GLINT);
        Minecraft.getInstance().getProfiler().pop();
    }
    final ItemStack itemStack = player.getItemInHand(Hand.MAIN_HAND);
    if (itemStack.getItem() == ModItems.tagTool.get() && itemStack.getOrCreateTag().contains(ItemTagTool.TAG_ANCHOR_POS)) {
        final BlockPos tagAnchor = BlockPosUtil.readFromNBT(itemStack.getTag(), ItemTagTool.TAG_ANCHOR_POS);
        final TileEntity te = Minecraft.getInstance().player.level.getBlockEntity(tagAnchor);
        renderAnchorPos(tagAnchor, matrixStack, linesWithoutCullAndDepth.get());
        if (te instanceof IBlueprintDataProvider) {
            final Map<BlockPos, List<String>> tagPosList = ((IBlueprintDataProvider) te).getWorldTagPosMap();
            for (final Map.Entry<BlockPos, List<String>> entry : tagPosList.entrySet()) {
                RenderUtils.renderWhiteOutlineBox(entry.getKey(), entry.getKey(), matrixStack, linesWithoutCullAndDepth.get());
                IRenderTypeBuffer.Impl buffer = IRenderTypeBuffer.immediate(Tessellator.getInstance().getBuilder());
                RenderUtils.renderDebugText(entry.getKey(), entry.getValue(), matrixStack, true, 3, buffer);
                RenderSystem.disableDepthTest();
                buffer.endBatch();
                RenderSystem.enableDepthTest();
            }
            renderBuffer.endBatch(RenderUtils.LINES_GLINT);
        }
    }
    renderBuffer.endBatch();
    OptifineCompat.getInstance().postBlueprintDraw();
    Settings.instance.endStructurizePass();
    final Vector3d viewPosition = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();
    matrixStack.pushPose();
    matrixStack.translate(-viewPosition.x(), -viewPosition.y(), -viewPosition.z());
    HookRegistries.render(matrixStack, partialTicks);
    matrixStack.popPose();
}
Also used : IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TileEntity(net.minecraft.tileentity.TileEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) IRenderTypeBuffer(net.minecraft.client.renderer.IRenderTypeBuffer) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 12 with IBlueprintDataProvider

use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project Structurize by ldtteam.

the class ItemScanTool method canAttackBlock.

@Override
public boolean canAttackBlock(final BlockState state, final World worldIn, final BlockPos pos, final PlayerEntity player) {
    if (!player.isShiftKeyDown()) {
        return super.canAttackBlock(state, worldIn, pos, player);
    }
    if (worldIn.isClientSide()) {
        LanguageHandler.sendMessageToPlayer(player, ANCHOR_POS_TKEY, pos.getX(), pos.getY(), pos.getZ());
    }
    ItemStack itemstack = player.getMainHandItem();
    if (!itemstack.getItem().equals(getRegisteredItemInstance())) {
        itemstack = player.getOffhandItem();
    }
    final TileEntity te = worldIn.getBlockEntity(pos);
    if (te instanceof IBlueprintDataProvider && !((IBlueprintDataProvider) te).getSchematicName().isEmpty()) {
        if (worldIn.isClientSide) {
            Settings.instance.setAnchorPos(Optional.of(pos));
        }
        final BlockPos start = ((IBlueprintDataProvider) te).getInWorldCorners().getA();
        final BlockPos end = ((IBlueprintDataProvider) te).getInWorldCorners().getB();
        if (!(start.equals(pos)) && !(end.equals(pos))) {
            if (worldIn.isClientSide) {
                Settings.instance.setBox(((IBlueprintDataProvider) te).getInWorldCorners());
            }
            itemstack.getOrCreateTag().put(NBT_START_POS, NBTUtil.writeBlockPos(start));
            itemstack.getOrCreateTag().put(NBT_END_POS, NBTUtil.writeBlockPos(end));
            if (player instanceof ServerPlayerEntity) {
                ((ServerPlayerEntity) player).refreshContainer(player.inventoryMenu, player.inventory.items);
            }
        }
    }
    itemstack.getOrCreateTag().put(NBT_ANCHOR_POS, NBTUtil.writeBlockPos(pos));
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ItemStack(net.minecraft.item.ItemStack)

Example 13 with IBlueprintDataProvider

use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project Structurize by ldtteam.

the class ItemTagTool method canAttackBlock.

@Override
public boolean canAttackBlock(final BlockState state, final World worldIn, final BlockPos pos, final PlayerEntity player) {
    final ItemStack stack = player.getMainHandItem();
    if (stack.getItem() != ModItems.tagTool.get() || player == null || worldIn == null) {
        return false;
    }
    BlockPos anchorPos = getAnchorPos(stack);
    String currentTag = getCurrentTag(stack);
    if (anchorPos == null) {
        LanguageHandler.sendPlayerMessage(player, "com.ldtteam.structurize.gui.tagtool.noanchor");
        return false;
    }
    if (currentTag.isEmpty()) {
        LanguageHandler.sendPlayerMessage(player, "com.ldtteam.structurize.gui.tagtool.notag");
        return false;
    }
    // Apply tag to item
    BlockPos relativePos = pos.subtract(anchorPos);
    final TileEntity te = worldIn.getBlockEntity(anchorPos);
    if (!(te instanceof IBlueprintDataProvider)) {
        LanguageHandler.sendPlayerMessage(player, "com.ldtteam.structurize.gui.tagtool.anchor.notvalid");
        stack.getOrCreateTag().remove(TAG_ANCHOR_POS);
        return false;
    }
    // add/remove tags
    Map<BlockPos, List<String>> tagPosMap = ((IBlueprintDataProvider) te).getPositionedTags();
    if (!tagPosMap.containsKey(relativePos) || !tagPosMap.get(relativePos).contains(currentTag)) {
        ((IBlueprintDataProvider) te).addTag(relativePos, currentTag);
        if (worldIn.isClientSide()) {
            LanguageHandler.sendPlayerMessage(player, "com.ldtteam.structurize.gui.tagtool.addtag", currentTag, new TranslationTextComponent(worldIn.getBlockState(pos).getBlock().getDescriptionId()));
        }
    } else {
        ((IBlueprintDataProvider) te).removeTag(relativePos, currentTag);
        if (worldIn.isClientSide()) {
            LanguageHandler.sendPlayerMessage(player, "com.ldtteam.structurize.gui.tagtool.removed", currentTag, new TranslationTextComponent(worldIn.getBlockState(pos).getBlock().getDescriptionId()));
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List)

Example 14 with IBlueprintDataProvider

use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project minecolonies by ldtteam.

the class AbstractSchematicProvider method upgradeBuildingLevelToSchematicData.

@Override
public void upgradeBuildingLevelToSchematicData() {
    final TileEntity tileEntity = colony.getWorld().getBlockEntity(getID());
    if (tileEntity instanceof IBlueprintDataProvider) {
        final IBlueprintDataProvider blueprintDataProvider = (IBlueprintDataProvider) tileEntity;
        if (blueprintDataProvider.getSchematicName().isEmpty()) {
            return;
        }
        setCorners(blueprintDataProvider.getInWorldCorners().getA(), blueprintDataProvider.getInWorldCorners().getB());
        int level = 0;
        try {
            level = Integer.parseInt(blueprintDataProvider.getSchematicName().substring(blueprintDataProvider.getSchematicName().length() - 1));
        } catch (NumberFormatException e) {
        }
        if (level > 0 && level >= getBuildingLevel() && level <= getMaxBuildingLevel()) {
            if (level > getBuildingLevel()) {
                FireworkUtils.spawnFireworksAtAABBCorners(getCorners(), colony.getWorld(), level);
            }
            setBuildingLevel(level);
            onUpgradeComplete(level);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) IAltersBuildingFootprint(com.minecolonies.api.colony.buildings.modules.IAltersBuildingFootprint) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 15 with IBlueprintDataProvider

use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project minecolonies by ldtteam.

the class CreativeBuildingStructureHandler method triggerSuccess.

@Override
public void triggerSuccess(final BlockPos pos, final List<ItemStack> list, final boolean placement) {
    super.triggerSuccess(pos, list, placement);
    final BlockPos worldPos = getProgressPosInWorld(pos);
    final CompoundNBT teData = getBluePrint().getTileEntityData(worldPos, pos);
    if (teData != null && teData.contains(TAG_BLUEPRINTDATA)) {
        final TileEntity te = getWorld().getBlockEntity(worldPos);
        if (te != null) {
            ((IBlueprintDataProvider) te).readSchematicDataFromNBT(teData);
            ((ServerWorld) getWorld()).getChunkSource().blockChanged(worldPos);
            te.setChanged();
        }
    }
    if (building != null) {
        building.registerBlockPosition(getBluePrint().getBlockState(pos), worldPos, this.getWorld());
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CompoundNBT(net.minecraft.nbt.CompoundNBT) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)21 TileEntity (net.minecraft.tileentity.TileEntity)19 BlockPos (net.minecraft.util.math.BlockPos)16 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)5 ItemStack (net.minecraft.item.ItemStack)5 ScrollingList (com.ldtteam.blockout.views.ScrollingList)4 StructureName (com.ldtteam.structurize.management.StructureName)4 SchematicRequestMessage (com.ldtteam.structurize.network.messages.SchematicRequestMessage)4 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)4 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)4 IColonyView (com.minecolonies.api.colony.IColonyView)4 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)4 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)4 List (java.util.List)4 CompoundNBT (net.minecraft.nbt.CompoundNBT)4 Mirror (net.minecraft.util.Mirror)4 Pane (com.ldtteam.blockout.Pane)3 BlockState (net.minecraft.block.BlockState)3 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)3 Color (com.ldtteam.blockout.Color)2