Search in sources :

Example 1 with BlockBounding

use of mekanism.common.block.BlockBounding in project Mekanism by mekanism.

the class RenderTickHandler method onBlockHover.

@SubscribeEvent
public void onBlockHover(DrawHighlightEvent.HighlightBlock event) {
    PlayerEntity player = minecraft.player;
    if (player == null) {
        return;
    }
    BlockRayTraceResult rayTraceResult = event.getTarget();
    if (!rayTraceResult.getType().equals(Type.MISS)) {
        World world = player.getCommandSenderWorld();
        BlockPos pos = rayTraceResult.getBlockPos();
        IRenderTypeBuffer renderer = event.getBuffers();
        ActiveRenderInfo info = event.getInfo();
        MatrixStack matrix = event.getMatrix();
        IProfiler profiler = world.getProfiler();
        BlockState blockState = world.getBlockState(pos);
        boolean shouldCancel = false;
        profiler.push(ProfilerConstants.MEKANISM_OUTLINE);
        if (!blockState.isAir(world, pos) && world.getWorldBorder().isWithinBounds(pos)) {
            BlockPos actualPos = pos;
            BlockState actualState = blockState;
            if (blockState.getBlock() instanceof BlockBounding) {
                TileEntityBoundingBlock tile = WorldUtils.getTileEntity(TileEntityBoundingBlock.class, world, pos);
                if (tile != null) {
                    actualPos = tile.getMainPos();
                    actualState = world.getBlockState(actualPos);
                }
            }
            AttributeCustomSelectionBox customSelectionBox = Attribute.get(actualState, AttributeCustomSelectionBox.class);
            if (customSelectionBox != null) {
                WireFrameRenderer renderWireFrame = null;
                if (customSelectionBox.isJavaModel()) {
                    // If we use a TER to render the wire frame, grab the tile
                    TileEntity tile = WorldUtils.getTileEntity(world, actualPos);
                    if (tile != null) {
                        TileEntityRenderer<TileEntity> tileRenderer = TileEntityRendererDispatcher.instance.getRenderer(tile);
                        if (tileRenderer instanceof IWireFrameRenderer) {
                            IWireFrameRenderer wireFrameRenderer = (IWireFrameRenderer) tileRenderer;
                            if (wireFrameRenderer.hasSelectionBox(actualState)) {
                                renderWireFrame = (buffer, matrixStack, state, red, green, blue, alpha) -> {
                                    if (wireFrameRenderer.isCombined()) {
                                        renderQuadsWireFrame(state, buffer, matrixStack.last().pose(), world.random, red, green, blue, alpha);
                                    }
                                    wireFrameRenderer.renderWireFrame(tile, event.getPartialTicks(), matrixStack, buffer, red, green, blue, alpha);
                                };
                            }
                        }
                    }
                } else {
                    // Otherwise, skip getting the tile and just grab the model
                    renderWireFrame = (buffer, matrixStack, state, red, green, blue, alpha) -> renderQuadsWireFrame(state, buffer, matrixStack.last().pose(), world.random, red, green, blue, alpha);
                }
                if (renderWireFrame != null) {
                    matrix.pushPose();
                    Vector3d viewPosition = info.getPosition();
                    matrix.translate(actualPos.getX() - viewPosition.x, actualPos.getY() - viewPosition.y, actualPos.getZ() - viewPosition.z);
                    renderWireFrame.render(renderer.getBuffer(RenderType.lines()), matrix, actualState, 0, 0, 0, 0.4F);
                    matrix.popPose();
                    shouldCancel = true;
                }
            }
        }
        profiler.pop();
        ItemStack stack = player.getMainHandItem();
        if (stack.isEmpty() || !(stack.getItem() instanceof ItemConfigurator)) {
            // If we are not holding a configurator, look if we are in the offhand
            stack = player.getOffhandItem();
            if (stack.isEmpty() || !(stack.getItem() instanceof ItemConfigurator)) {
                if (shouldCancel) {
                    event.setCanceled(true);
                }
                return;
            }
        }
        profiler.push(ProfilerConstants.CONFIGURABLE_MACHINE);
        ConfiguratorMode state = ((ItemConfigurator) stack.getItem()).getMode(stack);
        if (state.isConfigurating()) {
            TransmissionType type = Objects.requireNonNull(state.getTransmission(), "Configurating state requires transmission type");
            TileEntity tile = WorldUtils.getTileEntity(world, pos);
            if (tile instanceof ISideConfiguration) {
                ISideConfiguration configurable = (ISideConfiguration) tile;
                TileComponentConfig config = configurable.getConfig();
                if (config.supports(type)) {
                    Direction face = rayTraceResult.getDirection();
                    DataType dataType = config.getDataType(type, RelativeSide.fromDirections(configurable.getDirection(), face));
                    if (dataType != null) {
                        Vector3d viewPosition = info.getPosition();
                        matrix.pushPose();
                        matrix.translate(pos.getX() - viewPosition.x, pos.getY() - viewPosition.y, pos.getZ() - viewPosition.z);
                        MekanismRenderer.renderObject(getOverlayModel(face, type), matrix, renderer.getBuffer(Atlases.translucentCullBlockSheet()), MekanismRenderer.getColorARGB(dataType.getColor(), 0.6F), MekanismRenderer.FULL_LIGHT, OverlayTexture.NO_OVERLAY, FaceDisplay.FRONT);
                        matrix.popPose();
                    }
                }
            }
        }
        profiler.pop();
        if (shouldCancel) {
            event.setCanceled(true);
        }
    }
}
Also used : AttributeCustomSelectionBox(mekanism.common.block.attribute.AttributeCustomSelectionBox) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) World(net.minecraft.world.World) TileComponentConfig(mekanism.common.tile.component.TileComponentConfig) Direction(net.minecraft.util.Direction) AbstractClientPlayerEntity(net.minecraft.client.entity.player.AbstractClientPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TileEntityBoundingBlock(mekanism.common.tile.TileEntityBoundingBlock) TileEntity(net.minecraft.tileentity.TileEntity) IRenderTypeBuffer(net.minecraft.client.renderer.IRenderTypeBuffer) IWireFrameRenderer(mekanism.client.render.tileentity.IWireFrameRenderer) IWireFrameRenderer(mekanism.client.render.tileentity.IWireFrameRenderer) BlockBounding(mekanism.common.block.BlockBounding) DataType(mekanism.common.tile.component.config.DataType) BlockPos(net.minecraft.util.math.BlockPos) ActiveRenderInfo(net.minecraft.client.renderer.ActiveRenderInfo) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration) ItemConfigurator(mekanism.common.item.ItemConfigurator) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) ConfiguratorMode(mekanism.common.item.ItemConfigurator.ConfiguratorMode) IProfiler(net.minecraft.profiler.IProfiler) BlockState(net.minecraft.block.BlockState) Vector3d(net.minecraft.util.math.vector.Vector3d) TransmissionType(mekanism.common.lib.transmitter.TransmissionType) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with BlockBounding

use of mekanism.common.block.BlockBounding in project Mekanism by mekanism.

the class TOPProvider method addProbeInfo.

@Override
public void addProbeInfo(ProbeMode mode, IProbeInfo info, PlayerEntity player, World world, BlockState blockState, IProbeHitData data) {
    BlockPos pos = data.getPos();
    if (blockState.getBlock() instanceof BlockBounding) {
        // If we are a bounding block that has a position set, redirect the probe to the main location
        BlockPos mainPos = BlockBounding.getMainBlockPos(world, pos);
        if (mainPos != null) {
            pos = mainPos;
        // If we end up needing the blockstate at some point lower down, then uncomment this line
        // until we do though there is no point in bothering to query the world to get it
        // blockState = world.getBlockState(mainPos);
        }
    }
    TileEntity tile = WorldUtils.getTileEntity(world, pos);
    if (tile != null) {
        LookingAtUtils.addInfo(new TOPLookingAtHelper(info), tile, displayTanks(mode), displayFluidTanks);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockBounding(mekanism.common.block.BlockBounding) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with BlockBounding

use of mekanism.common.block.BlockBounding in project Mekanism by mekanism.

the class WorldUtils method makeBoundingBlock.

/**
 * Places a fake bounding block at the defined location.
 *
 * @param world            world to place block in
 * @param boundingLocation coordinates of bounding block
 * @param orig             original block position
 */
public static void makeBoundingBlock(@Nullable IWorld world, BlockPos boundingLocation, BlockPos orig) {
    if (world == null) {
        return;
    }
    BlockBounding boundingBlock = MekanismBlocks.BOUNDING_BLOCK.getBlock();
    BlockState newState = BlockStateHelper.getStateForPlacement(boundingBlock, boundingBlock.defaultBlockState(), world, boundingLocation, null, Direction.NORTH);
    world.setBlock(boundingLocation, newState, BlockFlags.DEFAULT);
    if (!world.isClientSide()) {
        TileEntityBoundingBlock tile = getTileEntity(TileEntityBoundingBlock.class, world, boundingLocation);
        if (tile != null) {
            tile.setMainLocation(orig);
        } else {
            Mekanism.logger.warn("Unable to find Bounding Block Tile at: {}", boundingLocation);
        }
    }
}
Also used : TileEntityBoundingBlock(mekanism.common.tile.TileEntityBoundingBlock) BlockState(net.minecraft.block.BlockState) BlockBounding(mekanism.common.block.BlockBounding)

Example 4 with BlockBounding

use of mekanism.common.block.BlockBounding in project Mekanism by mekanism.

the class TagCache method getModIDStacks.

public static List<ItemStack> getModIDStacks(@Nonnull String modName, boolean forceBlock) {
    if (modIDStacks.containsKey(modName)) {
        return modIDStacks.get(modName);
    }
    List<ItemStack> stacks = new ArrayList<>();
    for (Item item : ForgeRegistries.ITEMS.getValues()) {
        if (!forceBlock || item instanceof BlockItem) {
            // Ugly check to make sure we don't include our bounding block in render list. Eventually this should use getRenderShape() with a dummy BlockState
            if (item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BlockBounding) {
                continue;
            }
            // Note: We get the modid based on the stack so that if there is a mod that has a different modid for an item
            // that isn't based on NBT it can properly change the modid (this is unlikely to happen, but you never know)
            ItemStack stack = new ItemStack(item);
            if (WildcardMatcher.matches(modName, MekanismUtils.getModId(stack))) {
                stacks.add(stack);
            }
        }
    }
    modIDStacks.put(modName, stacks);
    return stacks;
}
Also used : Item(net.minecraft.item.Item) BlockItem(net.minecraft.item.BlockItem) ArrayList(java.util.ArrayList) BlockBounding(mekanism.common.block.BlockBounding) ItemStack(net.minecraft.item.ItemStack) BlockItem(net.minecraft.item.BlockItem)

Example 5 with BlockBounding

use of mekanism.common.block.BlockBounding in project Mekanism by mekanism.

the class TagCache method getMaterialStacks.

public static List<ItemStack> getMaterialStacks(@Nonnull Material material) {
    if (materialStacks.containsKey(material)) {
        return materialStacks.get(material);
    }
    List<ItemStack> stacks = new ArrayList<>();
    for (Item item : ForgeRegistries.ITEMS.getValues()) {
        if (item instanceof BlockItem) {
            Block block = ((BlockItem) item).getBlock();
            // noinspection ConstantConditions getBlock is nonnull, but if something "goes wrong" it returns null, just skip it
            if (block == null || block instanceof BlockBounding) {
                continue;
            }
            if (block.defaultBlockState().getMaterial() == material) {
                stacks.add(new ItemStack(item));
            }
        }
    }
    materialStacks.put(material, stacks);
    return stacks;
}
Also used : Item(net.minecraft.item.Item) BlockItem(net.minecraft.item.BlockItem) ArrayList(java.util.ArrayList) BlockBounding(mekanism.common.block.BlockBounding) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) BlockItem(net.minecraft.item.BlockItem)

Aggregations

BlockBounding (mekanism.common.block.BlockBounding)8 BlockState (net.minecraft.block.BlockState)5 BlockPos (net.minecraft.util.math.BlockPos)4 ItemStack (net.minecraft.item.ItemStack)3 World (net.minecraft.world.World)3 ArrayList (java.util.ArrayList)2 IEnergyContainer (mekanism.api.energy.IEnergyContainer)2 FloatingLong (mekanism.api.math.FloatingLong)2 TileEntityBoundingBlock (mekanism.common.tile.TileEntityBoundingBlock)2 BlockItem (net.minecraft.item.BlockItem)2 Item (net.minecraft.item.Item)2 TileEntity (net.minecraft.tileentity.TileEntity)2 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 IWireFrameRenderer (mekanism.client.render.tileentity.IWireFrameRenderer)1 AttributeCustomSelectionBox (mekanism.common.block.attribute.AttributeCustomSelectionBox)1 ModuleVeinMiningUnit (mekanism.common.content.gear.mekatool.ModuleVeinMiningUnit)1 ItemConfigurator (mekanism.common.item.ItemConfigurator)1 ConfiguratorMode (mekanism.common.item.ItemConfigurator.ConfiguratorMode)1 TransmissionType (mekanism.common.lib.transmitter.TransmissionType)1 TileEntityAdvancedBoundingBlock (mekanism.common.tile.TileEntityAdvancedBoundingBlock)1