Search in sources :

Example 1 with TransmissionType

use of mekanism.common.lib.transmitter.TransmissionType 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 TransmissionType

use of mekanism.common.lib.transmitter.TransmissionType in project Mekanism by mekanism.

the class TileComponentConfig method read.

@Override
public void read(CompoundNBT nbtTags) {
    if (nbtTags.contains(NBTConstants.COMPONENT_CONFIG, NBT.TAG_COMPOUND)) {
        CompoundNBT configNBT = nbtTags.getCompound(NBTConstants.COMPONENT_CONFIG);
        Set<Direction> directionsToUpdate = EnumSet.noneOf(Direction.class);
        for (Entry<TransmissionType, ConfigInfo> entry : configInfo.entrySet()) {
            TransmissionType type = entry.getKey();
            ConfigInfo info = entry.getValue();
            info.setEjecting(configNBT.getBoolean(NBTConstants.EJECT + type.ordinal()));
            CompoundNBT sideConfig = configNBT.getCompound(NBTConstants.CONFIG + type.ordinal());
            for (RelativeSide side : EnumUtils.SIDES) {
                NBTUtils.setEnumIfPresent(sideConfig, NBTConstants.SIDE + side.ordinal(), DataType::byIndexStatic, dataType -> {
                    if (info.getDataType(side) != dataType) {
                        info.setDataType(dataType, side);
                        if (tile.hasLevel()) {
                            // If we aren't already loaded yet don't do any updates
                            Direction direction = side.getDirection(tile.getDirection());
                            sideChangedBasic(type, direction);
                            directionsToUpdate.add(direction);
                        }
                    }
                });
            }
        }
        WorldUtils.notifyNeighborsOfChange(tile.getLevel(), tile.getBlockPos(), directionsToUpdate);
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) TransmissionType(mekanism.common.lib.transmitter.TransmissionType) RelativeSide(mekanism.api.RelativeSide) DataType(mekanism.common.tile.component.config.DataType) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) Direction(net.minecraft.util.Direction)

Example 3 with TransmissionType

use of mekanism.common.lib.transmitter.TransmissionType in project Mekanism by mekanism.

the class TileComponentConfig method readFromUpdateTag.

@Override
public void readFromUpdateTag(CompoundNBT updateTag) {
    if (updateTag.contains(NBTConstants.COMPONENT_CONFIG, NBT.TAG_COMPOUND)) {
        CompoundNBT configNBT = updateTag.getCompound(NBTConstants.COMPONENT_CONFIG);
        for (Entry<TransmissionType, ConfigInfo> entry : configInfo.entrySet()) {
            TransmissionType type = entry.getKey();
            ConfigInfo info = entry.getValue();
            CompoundNBT sideConfig = configNBT.getCompound(NBTConstants.CONFIG + type.ordinal());
            for (RelativeSide side : EnumUtils.SIDES) {
                NBTUtils.setEnumIfPresent(sideConfig, NBTConstants.SIDE + side.ordinal(), DataType::byIndexStatic, dataType -> info.setDataType(dataType, side));
            }
        }
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) TransmissionType(mekanism.common.lib.transmitter.TransmissionType) RelativeSide(mekanism.api.RelativeSide) DataType(mekanism.common.tile.component.config.DataType) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo)

Example 4 with TransmissionType

use of mekanism.common.lib.transmitter.TransmissionType in project Mekanism by mekanism.

the class TileComponentEjector method tickServer.

public void tickServer() {
    for (Map.Entry<TransmissionType, ConfigInfo> entry : configInfo.entrySet()) {
        TransmissionType type = entry.getKey();
        ConfigInfo info = entry.getValue();
        if (info.isEjecting() && (canEject == null || canEject.test(type))) {
            if (type == TransmissionType.ITEM) {
                if (tickDelay == 0) {
                    outputItems(info);
                } else {
                    tickDelay--;
                }
            } else if (type != TransmissionType.HEAT) {
                eject(type, info);
            }
        }
    }
}
Also used : TransmissionType(mekanism.common.lib.transmitter.TransmissionType) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap)

Example 5 with TransmissionType

use of mekanism.common.lib.transmitter.TransmissionType in project Mekanism by mekanism.

the class TileComponentEjector method eject.

/**
 * @apiNote Ensure that it can eject before calling this method.
 */
private void eject(TransmissionType type, ConfigInfo info) {
    // Used to keep track of tanks to what sides they output to
    Map<Object, Set<Direction>> outputData = null;
    for (DataType dataType : info.getSupportedDataTypes()) {
        if (dataType.canOutput()) {
            ISlotInfo slotInfo = info.getSlotInfo(dataType);
            if (slotInfo != null) {
                Set<Direction> outputSides = info.getSidesForData(dataType);
                if (!outputSides.isEmpty()) {
                    if (outputData == null) {
                        // Lazy init outputData
                        outputData = new HashMap<>();
                    }
                    if (type.isChemical() && slotInfo instanceof ChemicalSlotInfo) {
                        for (IChemicalTank<?, ?> tank : ((ChemicalSlotInfo<?, ?, ?>) slotInfo).getTanks()) {
                            if (!tank.isEmpty() && (canTankEject == null || canTankEject.test(tank))) {
                                outputData.computeIfAbsent(tank, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
                            }
                        }
                    } else if (type == TransmissionType.FLUID && slotInfo instanceof FluidSlotInfo) {
                        for (IExtendedFluidTank tank : ((FluidSlotInfo) slotInfo).getTanks()) {
                            if (!tank.isEmpty()) {
                                outputData.computeIfAbsent(tank, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
                            }
                        }
                    } else if (type == TransmissionType.ENERGY && slotInfo instanceof EnergySlotInfo) {
                        for (IEnergyContainer container : ((EnergySlotInfo) slotInfo).getContainers()) {
                            if (!container.isEmpty()) {
                                outputData.computeIfAbsent(container, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
                            }
                        }
                    }
                }
            }
        }
    }
    if (outputData != null && !outputData.isEmpty()) {
        for (Map.Entry<Object, Set<Direction>> entry : outputData.entrySet()) {
            if (type.isChemical()) {
                ChemicalUtil.emit(entry.getValue(), (IChemicalTank<?, ?>) entry.getKey(), tile, chemicalEjectRate.getAsLong());
            } else if (type == TransmissionType.FLUID) {
                FluidUtils.emit(entry.getValue(), (IExtendedFluidTank) entry.getKey(), tile, fluidEjectRate.getAsInt());
            } else if (type == TransmissionType.ENERGY) {
                IEnergyContainer container = (IEnergyContainer) entry.getKey();
                CableUtils.emit(entry.getValue(), container, tile, energyEjectRate == null ? container.getMaxEnergy() : energyEjectRate.get());
            }
        }
    }
}
Also used : ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) LongSupplier(java.util.function.LongSupplier) SyncableInt(mekanism.common.inventory.container.sync.SyncableInt) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) CompoundNBT(net.minecraft.nbt.CompoundNBT) Direction(net.minecraft.util.Direction) FluidSlotInfo(mekanism.common.tile.component.config.slot.FluidSlotInfo) TileTransitRequest(mekanism.common.lib.inventory.TileTransitRequest) Map(java.util.Map) EnumSet(java.util.EnumSet) TileEntityLogisticalTransporterBase(mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase) EnumMap(java.util.EnumMap) NBTUtils(mekanism.common.util.NBTUtils) Predicate(java.util.function.Predicate) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) Set(java.util.Set) List(java.util.List) ComputerException(mekanism.common.integration.computer.ComputerException) InventoryUtils(mekanism.common.util.InventoryUtils) RelativeSide(mekanism.api.RelativeSide) ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) NBTConstants(mekanism.api.NBTConstants) ChemicalUtil(mekanism.common.util.ChemicalUtil) EnumColor(mekanism.api.text.EnumColor) CableUtils(mekanism.common.util.CableUtils) SyncableBoolean(mekanism.common.inventory.container.sync.SyncableBoolean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ISpecificContainerTracker(mekanism.common.inventory.container.MekanismContainer.ISpecificContainerTracker) ChemicalSlotInfo(mekanism.common.tile.component.config.slot.ChemicalSlotInfo) TransmissionType(mekanism.common.lib.transmitter.TransmissionType) TransitResponse(mekanism.common.lib.inventory.TransitRequest.TransitResponse) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod) IEnergyContainer(mekanism.api.energy.IEnergyContainer) Nonnull(javax.annotation.Nonnull) IntSupplier(java.util.function.IntSupplier) Nullable(javax.annotation.Nullable) TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) EnumUtils(mekanism.common.util.EnumUtils) DataType(mekanism.common.tile.component.config.DataType) InventorySlotInfo(mekanism.common.tile.component.config.slot.InventorySlotInfo) TransporterUtils(mekanism.common.util.TransporterUtils) FluidUtils(mekanism.common.util.FluidUtils) NBT(net.minecraftforge.common.util.Constants.NBT) EnergySlotInfo(mekanism.common.tile.component.config.slot.EnergySlotInfo) WorldUtils(mekanism.common.util.WorldUtils) TileEntity(net.minecraft.tileentity.TileEntity) IChemicalTank(mekanism.api.chemical.IChemicalTank) MekanismConfig(mekanism.common.config.MekanismConfig) FloatingLongSupplier(mekanism.api.math.FloatingLongSupplier) ISyncableData(mekanism.common.inventory.container.sync.ISyncableData) FluidSlotInfo(mekanism.common.tile.component.config.slot.FluidSlotInfo) EnumSet(java.util.EnumSet) Set(java.util.Set) EnergySlotInfo(mekanism.common.tile.component.config.slot.EnergySlotInfo) Direction(net.minecraft.util.Direction) ChemicalSlotInfo(mekanism.common.tile.component.config.slot.ChemicalSlotInfo) IEnergyContainer(mekanism.api.energy.IEnergyContainer) DataType(mekanism.common.tile.component.config.DataType) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap)

Aggregations

TransmissionType (mekanism.common.lib.transmitter.TransmissionType)16 ConfigInfo (mekanism.common.tile.component.config.ConfigInfo)11 RelativeSide (mekanism.api.RelativeSide)8 Direction (net.minecraft.util.Direction)8 DataType (mekanism.common.tile.component.config.DataType)6 TileEntity (net.minecraft.tileentity.TileEntity)6 ArrayList (java.util.ArrayList)5 EnumMap (java.util.EnumMap)5 Map (java.util.Map)5 CompoundNBT (net.minecraft.nbt.CompoundNBT)5 Nonnull (javax.annotation.Nonnull)4 IEnergyContainer (mekanism.api.energy.IEnergyContainer)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Nullable (javax.annotation.Nullable)3 BlockPos (net.minecraft.util.math.BlockPos)3 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)3 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)2 Object2ObjectOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap)2 Set (java.util.Set)2