Search in sources :

Example 21 with EnumColor

use of mekanism.api.text.EnumColor 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)

Example 22 with EnumColor

use of mekanism.api.text.EnumColor in project Mekanism by mekanism.

the class TileEntityQIOComponent method onUpdateServer.

@Override
protected void onUpdateServer() {
    super.onUpdateServer();
    EnumColor prev = lastColor;
    QIOFrequency frequency = getQIOFrequency();
    lastColor = frequency == null ? null : frequency.getColor();
    if (prev != lastColor) {
        sendUpdatePacket();
    }
    if (level.getGameTime() % 10 == 0) {
        setActive(frequency != null);
    }
}
Also used : EnumColor(mekanism.api.text.EnumColor) QIOFrequency(mekanism.common.content.qio.QIOFrequency)

Example 23 with EnumColor

use of mekanism.api.text.EnumColor in project Mekanism by mekanism.

the class PigmentExtractingRecipeProvider method addExtractionRecipes.

private static void addExtractionRecipes(Consumer<IFinishedRecipe> consumer, String basePath) {
    for (Map.Entry<EnumColor, PigmentRegistryObject<Pigment>> entry : MekanismPigments.PIGMENT_COLOR_LOOKUP.entrySet()) {
        EnumColor color = entry.getKey();
        IPigmentProvider pigment = entry.getValue();
        DyeColor dye = color.getDyeColor();
        if (dye != null) {
            ItemStackToChemicalRecipeBuilder.pigmentExtracting(ItemStackIngredient.from(dye.getTag()), pigment.getStack(DYE_RATE)).build(consumer, Mekanism.rl(basePath + "dye/" + color.getRegistryPrefix()));
            // TODO: Eventually we may want to consider taking patterns into account
            ItemStackToChemicalRecipeBuilder.pigmentExtracting(ItemStackIngredient.from(BannerBlock.byColor(dye)), pigment.getStack(BANNER_RATE)).build(consumer, Mekanism.rl(basePath + "banner/" + color.getRegistryPrefix()));
            addExtractionRecipe(consumer, color, CONCRETE, pigment, CONCRETE_RATE, basePath + "concrete/");
            addExtractionRecipe(consumer, color, CONCRETE_POWDER, pigment, CONCRETE_POWDER_RATE, basePath + "concrete_powder/");
            addExtractionRecipe(consumer, color, CARPETS, pigment, CARPET_RATE, basePath + "carpet/");
            addExtractionRecipe(consumer, color, TERRACOTTA, pigment, CONCRETE_RATE, basePath + "terracotta/");
            addTagExtractionRecipe(consumer, color, STAINED_GLASS, pigment, STAINED_GLASS_RATE, basePath + "stained_glass/");
            addTagExtractionRecipe(consumer, color, STAINED_GLASS_PANES, pigment, STAINED_GLASS_PANE_RATE, basePath + "stained_glass_pane/");
            addExtractionRecipe(consumer, color, WOOL, pigment, WOOL_RATE, basePath + "wool/");
        }
    }
}
Also used : EnumColor(mekanism.api.text.EnumColor) IPigmentProvider(mekanism.api.providers.IPigmentProvider) DyeColor(net.minecraft.item.DyeColor) EnumMap(java.util.EnumMap) Map(java.util.Map) PigmentRegistryObject(mekanism.common.registration.impl.PigmentRegistryObject)

Example 24 with EnumColor

use of mekanism.api.text.EnumColor in project Mekanism by mekanism.

the class LogisticalTransporter method onRightClick.

@Override
public ActionResultType onRightClick(PlayerEntity player, Direction side) {
    EnumColor color = getColor();
    player.sendMessage(MekanismUtils.logFormat(MekanismLang.CURRENT_COLOR.translate(color == null ? MekanismLang.NONE : color.getColoredName())), Util.NIL_UUID);
    return super.onRightClick(player, side);
}
Also used : EnumColor(mekanism.api.text.EnumColor)

Example 25 with EnumColor

use of mekanism.api.text.EnumColor in project Mekanism by mekanism.

the class TransporterUtils method canInsert.

public static boolean canInsert(TileEntity tile, EnumColor color, ItemStack itemStack, Direction side, boolean force) {
    if (force && tile instanceof TileEntityLogisticalSorter) {
        return ((TileEntityLogisticalSorter) tile).canSendHome(itemStack);
    }
    if (!force && tile instanceof ISideConfiguration) {
        ISideConfiguration config = (ISideConfiguration) tile;
        if (config.getEjector().hasStrictInput()) {
            Direction tileSide = config.getDirection();
            EnumColor configColor = config.getEjector().getInputColor(RelativeSide.fromDirections(tileSide, side.getOpposite()));
            if (configColor != null && configColor != color) {
                return false;
            }
        }
    }
    Optional<IItemHandler> capability = CapabilityUtils.getCapability(tile, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite()).resolve();
    if (capability.isPresent()) {
        IItemHandler inventory = capability.get();
        for (int i = 0; i < inventory.getSlots(); i++) {
            // Check validation
            if (inventory.isItemValid(i, itemStack)) {
                // Simulate insert
                ItemStack rejects = inventory.insertItem(i, itemStack, true);
                if (TransporterManager.didEmit(itemStack, rejects)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : EnumColor(mekanism.api.text.EnumColor) IItemHandler(net.minecraftforge.items.IItemHandler) TileEntityLogisticalSorter(mekanism.common.tile.TileEntityLogisticalSorter) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration)

Aggregations

EnumColor (mekanism.api.text.EnumColor)33 Map (java.util.Map)6 DyeColor (net.minecraft.item.DyeColor)6 ItemStack (net.minecraft.item.ItemStack)5 ISideConfiguration (mekanism.common.tile.interfaces.ISideConfiguration)4 DataType (mekanism.common.tile.component.config.DataType)3 ArrayList (java.util.ArrayList)2 IPigmentProvider (mekanism.api.providers.IPigmentProvider)2 ItemConfigurator (mekanism.common.item.ItemConfigurator)2 PigmentRegistryObject (mekanism.common.registration.impl.PigmentRegistryObject)2 ITextComponent (net.minecraft.util.text.ITextComponent)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 IVertexBuilder (com.mojang.blaze3d.vertex.IVertexBuilder)1 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)1 Object2ObjectOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Consumer (java.util.function.Consumer)1