Search in sources :

Example 6 with ITag

use of net.minecraft.tags.ITag in project Mekanism by mekanism.

the class ChemicalTags method lookupTag.

/**
 * Helper to look up the name of a tag, and get a decent estimate in LAN of the actual tag name.
 *
 * @param tag Tag to lookup.
 *
 * @return Name of the tag.
 */
public ResourceLocation lookupTag(ITag<CHEMICAL> tag) {
    // Manual and slightly modified implementation of TagCollection#getIdOrThrow to have better reverse lookup handling
    ITagCollection<CHEMICAL> collection = getCollection();
    ResourceLocation resourceLocation = collection.getId(tag);
    if (resourceLocation == null) {
        // If we failed to get the resource location, try manually looking it up by a "matching" entry
        // as the objects are different and neither Tag nor NamedTag override equals and hashCode
        List<CHEMICAL> chemicals = tag.getValues();
        for (Map.Entry<ResourceLocation, ITag<CHEMICAL>> entry : collection.getAllTags().entrySet()) {
            if (chemicals.equals(entry.getValue().getValues())) {
                resourceLocation = entry.getKey();
                break;
            }
        }
    }
    if (resourceLocation == null) {
        throw new IllegalStateException("Unrecognized tag");
    }
    return resourceLocation;
}
Also used : ITag(net.minecraft.tags.ITag) ResourceLocation(net.minecraft.util.ResourceLocation) Map(java.util.Map)

Example 7 with ITag

use of net.minecraft.tags.ITag in project minecolonies by ldtteam.

the class Tag method deserialize.

public static Tag deserialize(final IFactoryController controller, final PacketBuffer buffer) {
    final ITag<Item> theTag = ItemTags.getAllTags().getTag(ResourceLocation.tryParse(buffer.readUtf(32767)));
    final ItemStack result = buffer.readBoolean() ? buffer.readItem() : ItemStack.EMPTY;
    final int count = buffer.readInt();
    final int minCount = buffer.readInt();
    return new Tag(theTag, result, count, minCount);
}
Also used : Item(net.minecraft.item.Item) ITag(net.minecraft.tags.ITag) ItemStack(net.minecraft.item.ItemStack)

Example 8 with ITag

use of net.minecraft.tags.ITag in project minecolonies by ldtteam.

the class Tag method deserialize.

/**
 * Deserialize the deliverable.
 *
 * @param controller the controller.
 * @param compound   the compound.
 * @return the deliverable.
 */
public static Tag deserialize(final IFactoryController controller, final CompoundNBT compound) {
    final ITag<Item> theTag = ItemTags.bind(compound.getString(NBT_TAG));
    final ItemStack result = compound.getAllKeys().contains(NBT_RESULT) ? ItemStackUtils.deserializeFromNBT(compound.getCompound(NBT_RESULT)) : ItemStackUtils.EMPTY;
    int count = compound.getInt("size");
    int minCount = count;
    if (compound.getAllKeys().contains(NBT_COUNT)) {
        count = compound.getInt(NBT_COUNT);
        minCount = compound.getInt(NBT_MINCOUNT);
    }
    return new Tag(theTag, result, count, minCount);
}
Also used : Item(net.minecraft.item.Item) ITag(net.minecraft.tags.ITag) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ITag (net.minecraft.tags.ITag)8 Item (net.minecraft.item.Item)7 ItemStack (net.minecraft.item.ItemStack)7 ImmutableList (com.google.common.collect.ImmutableList)2 Lists (com.google.common.collect.Lists)2 TypeToken (com.google.common.reflect.TypeToken)2 ICitizenData (com.minecolonies.api.colony.ICitizenData)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)2 IJob (com.minecolonies.api.colony.jobs.IJob)2 JobEntry (com.minecolonies.api.colony.jobs.registry.JobEntry)2 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)2 RequestState (com.minecolonies.api.colony.requestsystem.request.RequestState)2 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)2 Stack (com.minecolonies.api.colony.requestsystem.requestable.Stack)2 Tool (com.minecolonies.api.colony.requestsystem.requestable.Tool)2 AbstractDeliverymanRequestable.getMaxBuildingPriority (com.minecolonies.api.colony.requestsystem.requestable.deliveryman.AbstractDeliverymanRequestable.getMaxBuildingPriority)2 AbstractDeliverymanRequestable.scaledPriority (com.minecolonies.api.colony.requestsystem.requestable.deliveryman.AbstractDeliverymanRequestable.scaledPriority)2 IRequestResolver (com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver)2