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;
}
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);
}
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);
}
Aggregations