Search in sources :

Example 1 with TileComponentConfig

use of mekanism.common.tile.component.TileComponentConfig 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 TileComponentConfig

use of mekanism.common.tile.component.TileComponentConfig in project Mekanism by mekanism.

the class ISideConfiguration method getActiveDataType.

@Nullable
default DataType getActiveDataType(Object container) {
    ConfigInfo info = null;
    TileComponentConfig config = getConfig();
    if (container instanceof IGasTank && config.supports(TransmissionType.GAS)) {
        info = config.getConfig(TransmissionType.GAS);
    } else if (container instanceof IInfusionTank && config.supports(TransmissionType.INFUSION)) {
        info = config.getConfig(TransmissionType.INFUSION);
    } else if (container instanceof IPigmentTank && config.supports(TransmissionType.PIGMENT)) {
        info = config.getConfig(TransmissionType.PIGMENT);
    } else if (container instanceof ISlurryTank && config.supports(TransmissionType.SLURRY)) {
        info = config.getConfig(TransmissionType.SLURRY);
    } else if (container instanceof IExtendedFluidTank && config.supports(TransmissionType.FLUID)) {
        info = config.getConfig(TransmissionType.FLUID);
    } else if (container instanceof IInventorySlot && config.supports(TransmissionType.ITEM)) {
        info = config.getConfig(TransmissionType.ITEM);
    }
    if (info != null) {
        List<DataType> types = info.getDataTypeForContainer(container);
        int count = types.size();
        // of <= size - 1 to cut down slightly on the calculations
        if (count > 0 && count < info.getSupportedDataTypes().size()) {
            return types.get(0);
        }
    }
    return null;
}
Also used : IInventorySlot(mekanism.api.inventory.IInventorySlot) IPigmentTank(mekanism.api.chemical.pigment.IPigmentTank) IInfusionTank(mekanism.api.chemical.infuse.IInfusionTank) IGasTank(mekanism.api.chemical.gas.IGasTank) DataType(mekanism.common.tile.component.config.DataType) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) TileComponentConfig(mekanism.common.tile.component.TileComponentConfig) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) ISlurryTank(mekanism.api.chemical.slurry.ISlurryTank) Nullable(javax.annotation.Nullable)

Example 3 with TileComponentConfig

use of mekanism.common.tile.component.TileComponentConfig in project Mekanism by mekanism.

the class ConfigHolder method getSlotInfo.

@Nullable
private ISlotInfo getSlotInfo(Direction side) {
    Direction direction = facingSupplier.get();
    if (direction != lastDirection) {
        // Invalid entire cache and update what direction we had as last if our last direction doesn't match the one we currently are facing
        cachedSlotInfo.clear();
        lastDirection = direction;
    } else if (cachedSlotInfo.containsKey(side)) {
        return cachedSlotInfo.get(side);
    }
    ISlotInfo slotInfo;
    TileComponentConfig config = configSupplier.get();
    if (config == null) {
        slotInfo = NO_CONFIG;
    } else {
        TransmissionType transmissionType = getTransmissionType();
        ConfigInfo configInfo = config.getConfig(transmissionType);
        if (configInfo == null) {
            slotInfo = NO_CONFIG;
        } else {
            if (!listenerAdded) {
                // If we haven't added a listener to our config yet add one to remove the cached info we have for that side
                listenerAdded = true;
                config.addConfigChangeListener(transmissionType, cachedSlotInfo::remove);
            }
            slotInfo = configInfo.getSlotInfo(RelativeSide.fromDirections(direction, side));
            if (slotInfo != null && !slotInfo.isEnabled()) {
                // If we have a slot info, but it is not actually enabled, just store it as null to avoid having to recheck if it is enabled later
                slotInfo = null;
            }
        }
    }
    cachedSlotInfo.put(side, slotInfo);
    return slotInfo;
}
Also used : ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) TransmissionType(mekanism.common.lib.transmitter.TransmissionType) TileComponentConfig(mekanism.common.tile.component.TileComponentConfig) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) Direction(net.minecraft.util.Direction) Nullable(javax.annotation.Nullable)

Example 4 with TileComponentConfig

use of mekanism.common.tile.component.TileComponentConfig in project Mekanism by mekanism.

the class PacketConfigurationUpdate method handle.

@Override
public void handle(NetworkEvent.Context context) {
    PlayerEntity player = context.getSender();
    if (player == null) {
        return;
    }
    TileEntity tile = WorldUtils.getTileEntity(player.level, pos);
    if (tile instanceof ISideConfiguration) {
        ISideConfiguration config = (ISideConfiguration) tile;
        if (packetType == ConfigurationPacket.EJECT) {
            ConfigInfo info = config.getConfig().getConfig(transmission);
            if (info != null) {
                info.setEjecting(!info.isEjecting());
                WorldUtils.saveChunk(tile);
            }
        } else if (packetType == ConfigurationPacket.CLEAR_ALL) {
            TileComponentConfig configComponent = config.getConfig();
            ConfigInfo info = configComponent.getConfig(transmission);
            if (info != null) {
                for (RelativeSide side : EnumUtils.SIDES) {
                    if (info.isSideEnabled(side) && info.getDataType(side) != DataType.NONE) {
                        info.setDataType(DataType.NONE, side);
                        configComponent.sideChanged(transmission, side);
                    }
                }
            }
        } else if (packetType == ConfigurationPacket.SIDE_DATA) {
            TileComponentConfig configComponent = config.getConfig();
            ConfigInfo info = configComponent.getConfig(transmission);
            if (info != null) {
                DataType type = info.getDataType(inputSide);
                boolean changed = false;
                if (clickType == 0) {
                    changed = type != info.incrementDataType(inputSide);
                } else if (clickType == 1) {
                    changed = type != info.decrementDataType(inputSide);
                } else if (clickType == 2 && type != DataType.NONE) {
                    // We only need to update it if we are changing it to none
                    changed = true;
                    info.setDataType(DataType.NONE, inputSide);
                }
                if (changed) {
                    configComponent.sideChanged(transmission, inputSide);
                }
            }
        } else if (packetType == ConfigurationPacket.EJECT_COLOR) {
            TileComponentEjector ejector = config.getEjector();
            if (clickType == 0) {
                ejector.setOutputColor(TransporterUtils.increment(ejector.getOutputColor()));
            } else if (clickType == 1) {
                ejector.setOutputColor(TransporterUtils.decrement(ejector.getOutputColor()));
            } else if (clickType == 2) {
                ejector.setOutputColor(null);
            }
        } else if (packetType == ConfigurationPacket.INPUT_COLOR) {
            TileComponentEjector ejector = config.getEjector();
            if (clickType == 0) {
                ejector.setInputColor(inputSide, TransporterUtils.increment(ejector.getInputColor(inputSide)));
            } else if (clickType == 1) {
                ejector.setInputColor(inputSide, TransporterUtils.decrement(ejector.getInputColor(inputSide)));
            } else if (clickType == 2) {
                ejector.setInputColor(inputSide, null);
            }
        } else if (packetType == ConfigurationPacket.STRICT_INPUT) {
            TileComponentEjector ejector = config.getEjector();
            ejector.setStrictInput(!ejector.hasStrictInput());
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileComponentEjector(mekanism.common.tile.component.TileComponentEjector) RelativeSide(mekanism.api.RelativeSide) DataType(mekanism.common.tile.component.config.DataType) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) TileComponentConfig(mekanism.common.tile.component.TileComponentConfig) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration)

Aggregations

TileComponentConfig (mekanism.common.tile.component.TileComponentConfig)4 ConfigInfo (mekanism.common.tile.component.config.ConfigInfo)3 DataType (mekanism.common.tile.component.config.DataType)3 Nullable (javax.annotation.Nullable)2 TransmissionType (mekanism.common.lib.transmitter.TransmissionType)2 ISideConfiguration (mekanism.common.tile.interfaces.ISideConfiguration)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 TileEntity (net.minecraft.tileentity.TileEntity)2 Direction (net.minecraft.util.Direction)2 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 RelativeSide (mekanism.api.RelativeSide)1 IGasTank (mekanism.api.chemical.gas.IGasTank)1 IInfusionTank (mekanism.api.chemical.infuse.IInfusionTank)1 IPigmentTank (mekanism.api.chemical.pigment.IPigmentTank)1 ISlurryTank (mekanism.api.chemical.slurry.ISlurryTank)1 IExtendedFluidTank (mekanism.api.fluid.IExtendedFluidTank)1 IInventorySlot (mekanism.api.inventory.IInventorySlot)1 IWireFrameRenderer (mekanism.client.render.tileentity.IWireFrameRenderer)1 BlockBounding (mekanism.common.block.BlockBounding)1 AttributeCustomSelectionBox (mekanism.common.block.attribute.AttributeCustomSelectionBox)1