Search in sources :

Example 1 with ISideConfiguration

use of mekanism.common.tile.interfaces.ISideConfiguration in project Mekanism by mekanism.

the class GuiGauge method renderToolTip.

@Override
public void renderToolTip(@Nonnull MatrixStack matrix, int mouseX, int mouseY) {
    super.renderToolTip(matrix, mouseX, mouseY);
    ItemStack stack = minecraft.player.inventory.getCarried();
    EnumColor color = getGaugeColor().getColor();
    if (!stack.isEmpty() && stack.getItem() instanceof ItemConfigurator && color != null) {
        if (gui() instanceof GuiMekanismTile) {
            TileEntityMekanism tile = ((GuiMekanismTile<?, ?>) gui()).getTileEntity();
            if (tile instanceof ISideConfiguration && getTransmission() != null) {
                DataType dataType = null;
                ConfigInfo config = ((ISideConfiguration) tile).getConfig().getConfig(getTransmission());
                if (config != null) {
                    Set<DataType> supportedDataTypes = config.getSupportedDataTypes();
                    for (DataType type : supportedDataTypes) {
                        if (type.getColor() == color) {
                            dataType = type;
                            break;
                        }
                    }
                }
                if (dataType == null) {
                    displayTooltip(matrix, MekanismLang.GENERIC_PARENTHESIS.translateColored(color, color.getName()), mouseX, mouseY);
                } else {
                    displayTooltip(matrix, MekanismLang.GENERIC_WITH_PARENTHESIS.translateColored(color, dataType, color.getName()), mouseX, mouseY);
                }
            }
        }
    } else {
        List<ITextComponent> list = new ArrayList<>();
        if (getLabel() != null) {
            list.add(getLabel());
        }
        list.addAll(getTooltipText());
        displayTooltips(matrix, list, mouseX, mouseY);
    }
}
Also used : TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) EnumColor(mekanism.api.text.EnumColor) ITextComponent(net.minecraft.util.text.ITextComponent) ArrayList(java.util.ArrayList) ItemConfigurator(mekanism.common.item.ItemConfigurator) DataType(mekanism.common.tile.component.config.DataType) ItemStack(net.minecraft.item.ItemStack) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) GuiMekanismTile(mekanism.client.gui.GuiMekanismTile) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration)

Example 2 with ISideConfiguration

use of mekanism.common.tile.interfaces.ISideConfiguration in project Mekanism by mekanism.

the class BlockMekanism method getPickBlock.

@Nonnull
@Override
public ItemStack getPickBlock(@Nonnull BlockState state, RayTraceResult target, @Nonnull IBlockReader world, @Nonnull BlockPos pos, PlayerEntity player) {
    ItemStack itemStack = new ItemStack(this);
    TileEntityMekanism tile = WorldUtils.getTileEntity(TileEntityMekanism.class, world, pos);
    if (tile == null) {
        return itemStack;
    }
    // TODO: Some of the data doesn't get properly "picked", because there are cases such as before opening the GUI where
    // the server doesn't bother syncing the data to the client. For example with what frequencies there are
    Item item = itemStack.getItem();
    if (tile.getFrequencyComponent().hasCustomFrequencies()) {
        tile.getFrequencyComponent().write(ItemDataUtils.getDataMap(itemStack));
    }
    if (item instanceof ISecurityItem && tile.hasSecurity()) {
        ISecurityItem securityItem = (ISecurityItem) item;
        securityItem.setOwnerUUID(itemStack, tile.getOwnerUUID());
        securityItem.setSecurity(itemStack, tile.getSecurityMode());
    }
    if (tile.supportsUpgrades()) {
        tile.getComponent().write(ItemDataUtils.getDataMap(itemStack));
    }
    if (tile instanceof ISideConfiguration) {
        ISideConfiguration config = (ISideConfiguration) tile;
        config.getConfig().write(ItemDataUtils.getDataMap(itemStack));
        config.getEjector().write(ItemDataUtils.getDataMap(itemStack));
    }
    if (tile instanceof ISustainedData) {
        ((ISustainedData) tile).writeSustainedData(itemStack);
    }
    if (tile.supportsRedstone()) {
        ItemDataUtils.setInt(itemStack, NBTConstants.CONTROL_TYPE, tile.getControlType().ordinal());
    }
    for (SubstanceType type : EnumUtils.SUBSTANCES) {
        if (tile.handles(type)) {
            ItemDataUtils.setList(itemStack, type.getContainerTag(), DataHandlerUtils.writeContainers(type.getContainers(tile)));
        }
    }
    if (item instanceof ISustainedInventory && tile.persistInventory() && tile.getSlots() > 0) {
        ((ISustainedInventory) item).setInventory(tile.getInventory(), itemStack);
    }
    return itemStack;
}
Also used : TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) Item(net.minecraft.item.Item) ISecurityItem(mekanism.common.lib.security.ISecurityItem) ISecurityItem(mekanism.common.lib.security.ISecurityItem) ISustainedInventory(mekanism.common.tile.interfaces.ISustainedInventory) SubstanceType(mekanism.common.tile.base.SubstanceType) ItemStack(net.minecraft.item.ItemStack) ISustainedData(mekanism.common.tile.interfaces.ISustainedData) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration) Nonnull(javax.annotation.Nonnull)

Example 3 with ISideConfiguration

use of mekanism.common.tile.interfaces.ISideConfiguration 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 4 with ISideConfiguration

use of mekanism.common.tile.interfaces.ISideConfiguration in project Mekanism by mekanism.

the class GuiMekanismTile method drawForegroundText.

@Override
protected void drawForegroundText(@Nonnull MatrixStack matrix, int mouseX, int mouseY) {
    super.drawForegroundText(matrix, mouseX, mouseY);
    if (tile instanceof ISideConfiguration) {
        ItemStack stack = getMinecraft().player.inventory.getCarried();
        if (!stack.isEmpty() && stack.getItem() instanceof ItemConfigurator) {
            for (int i = 0; i < menu.slots.size(); i++) {
                Slot slot = menu.slots.get(i);
                if (isMouseOverSlot(slot, mouseX, mouseY)) {
                    DataType data = getFromSlot(slot);
                    if (data != null) {
                        EnumColor color = data.getColor();
                        displayTooltip(matrix, MekanismLang.GENERIC_WITH_PARENTHESIS.translateColored(color, data, color.getName()), mouseX - leftPos, mouseY - topPos);
                    }
                    break;
                }
            }
        }
    }
}
Also used : EnumColor(mekanism.api.text.EnumColor) ItemConfigurator(mekanism.common.item.ItemConfigurator) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) IInventorySlot(mekanism.api.inventory.IInventorySlot) Slot(net.minecraft.inventory.container.Slot) DataType(mekanism.common.tile.component.config.DataType) ItemStack(net.minecraft.item.ItemStack) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration)

Example 5 with ISideConfiguration

use of mekanism.common.tile.interfaces.ISideConfiguration in project Mekanism by mekanism.

the class InventoryNetwork method calculateAcceptors.

public List<AcceptorData> calculateAcceptors(TransitRequest request, TransporterStack stack, Long2ObjectMap<IChunk> chunkMap) {
    List<AcceptorData> toReturn = new ArrayList<>();
    for (Map.Entry<BlockPos, Map<Direction, LazyOptional<IItemHandler>>> entry : acceptorCache.getAcceptorEntrySet()) {
        BlockPos pos = entry.getKey();
        if (!pos.equals(stack.homeLocation)) {
            TileEntity acceptor = WorldUtils.getTileEntity(getWorld(), chunkMap, pos);
            if (acceptor == null) {
                continue;
            }
            Map<TransitResponse, AcceptorData> dataMap = new HashMap<>();
            Coord4D position = new Coord4D(pos, getWorld());
            for (Map.Entry<Direction, LazyOptional<IItemHandler>> acceptorEntry : entry.getValue().entrySet()) {
                Optional<IItemHandler> handler = acceptorEntry.getValue().resolve();
                if (handler.isPresent()) {
                    Direction side = acceptorEntry.getKey();
                    // actually need to even query the TE
                    if (acceptor instanceof ISideConfiguration) {
                        // If the acceptor in question implements the mekanism interface, check that the color matches and bail fast if it doesn't
                        ISideConfiguration config = (ISideConfiguration) acceptor;
                        if (config.getEjector().hasStrictInput()) {
                            EnumColor configColor = config.getEjector().getInputColor(RelativeSide.fromDirections(config.getDirection(), side));
                            if (configColor != null && configColor != stack.color) {
                                continue;
                            }
                        }
                    }
                    TransitResponse response = TransporterManager.getPredictedInsert(position, side, handler.get(), request);
                    if (!response.isEmpty()) {
                        Direction opposite = side.getOpposite();
                        // If the response isn't empty, check if we already have acceptor data for
                        // a matching response at the destination
                        AcceptorData data = dataMap.get(response);
                        if (data == null) {
                            // If we don't, add a new acceptor data for the response and position with side
                            data = new AcceptorData(pos, response, opposite);
                            dataMap.put(response, data);
                            toReturn.add(data);
                        // Note: In theory this shouldn't cause any issues if some exposed slots overlap but are for
                        // different acceptor data/sides as our predicted insert takes into account all en-route
                        // items to the destination, and only checks about the side if none are actually able to be
                        // inserted in the first place
                        } else {
                            // If we do, add our side as one of the sides it can accept things from for that response
                            // This equates to the destination being the same
                            data.sides.add(opposite);
                        }
                    }
                }
            }
        }
    }
    return toReturn;
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) HashMap(java.util.HashMap) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) ArrayList(java.util.ArrayList) Direction(net.minecraft.util.Direction) TileEntity(net.minecraft.tileentity.TileEntity) EnumColor(mekanism.api.text.EnumColor) LazyOptional(net.minecraftforge.common.util.LazyOptional) TransitResponse(mekanism.common.lib.inventory.TransitRequest.TransitResponse) Coord4D(mekanism.api.Coord4D) BlockPos(net.minecraft.util.math.BlockPos) HashMap(java.util.HashMap) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Map(java.util.Map) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration)

Aggregations

ISideConfiguration (mekanism.common.tile.interfaces.ISideConfiguration)11 DataType (mekanism.common.tile.component.config.DataType)6 ItemStack (net.minecraft.item.ItemStack)6 TileEntityMekanism (mekanism.common.tile.base.TileEntityMekanism)5 TileEntity (net.minecraft.tileentity.TileEntity)5 EnumColor (mekanism.api.text.EnumColor)4 ConfigInfo (mekanism.common.tile.component.config.ConfigInfo)4 Direction (net.minecraft.util.Direction)4 IInventorySlot (mekanism.api.inventory.IInventorySlot)3 ItemConfigurator (mekanism.common.item.ItemConfigurator)3 SubstanceType (mekanism.common.tile.base.SubstanceType)3 ISustainedData (mekanism.common.tile.interfaces.ISustainedData)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 ArrayList (java.util.ArrayList)2 Nonnull (javax.annotation.Nonnull)2 RelativeSide (mekanism.api.RelativeSide)2 InventoryContainerSlot (mekanism.common.inventory.container.slot.InventoryContainerSlot)2 ConfiguratorMode (mekanism.common.item.ItemConfigurator.ConfiguratorMode)2 ISecurityItem (mekanism.common.lib.security.ISecurityItem)2 TransmissionType (mekanism.common.lib.transmitter.TransmissionType)2