mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Cleanup IForgeTagBuilder code style.
This commit is contained in:
1 parent
b6dc5381ca
commit
0d2a0deef3
5 files changed
+77
-91
No files matched your search
@@ -39,7 +39,6 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Queues;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
@@ -47,8 +46,6 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.model.Material;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
import net.minecraft.fluid.*;
|
||||
import net.minecraft.util.CachedBlockInfo;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -119,7 +116,6 @@ import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.storage.loot.LootContext;
|
||||
import net.minecraft.world.storage.loot.LootTable;
|
||||
import net.minecraft.world.storage.loot.LootTableManager;
|
||||
import net.minecraftforge.common.data.IOptionalTagEntry;
|
||||
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
||||
import net.minecraftforge.common.loot.LootModifierManager;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
@@ -1089,6 +1085,7 @@ public class ForgeHooks
|
||||
return res == Result.DEFAULT ? 0 : res == Result.DENY ? -1 : 1;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static <T> void deserializeTagAdditions(Tag.Builder<T> builder, Function<ResourceLocation, Optional<T>> valueGetter, JsonObject json)
|
||||
{
|
||||
if (json.has("optional"))
|
||||
@@ -1177,6 +1174,7 @@ public class ForgeHooks
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static synchronized void updateBurns()
|
||||
{
|
||||
VANILLA_BURNS.clear();
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.minecraftforge.common.data;
|
||||
|
||||
import net.minecraft.tags.Tag.ITagEntry;
|
||||
|
||||
public interface IOptionalTagEntry<T> extends ITagEntry<T>
|
||||
{
|
||||
|
||||
}
|
||||
/**
|
||||
* Marker class used by Forge to make a tag entry optional at runtime
|
||||
*/
|
||||
public interface IOptionalTagEntry<T> extends ITagEntry<T> {}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
@@ -9,77 +10,80 @@ import javax.annotation.Nonnull;
|
||||
import com.google.gson.JsonArray;
|
||||
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagCollection;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.data.IOptionalTagEntry;
|
||||
|
||||
public interface IForgeTagBuilder<T>
|
||||
{
|
||||
default Tag.Builder<T> addOptional(Function<ResourceLocation, Optional<T>> valueGetter, Collection<ResourceLocation> locations)
|
||||
{
|
||||
|
||||
default Tag.Builder<T> addOptional(final TagCollection<T> collection, final ResourceLocation... locations)
|
||||
{
|
||||
return ((Tag.Builder<T>)this).add(new OptionalListEntry<>(locations, valueGetter));
|
||||
return addOptional(collection, Arrays.asList(locations));
|
||||
}
|
||||
|
||||
default Tag.Builder<T> addOptional(final TagCollection<T> collection, final Collection<ResourceLocation> locations)
|
||||
{
|
||||
return addOptional(collection.getEntryLookup(), locations);
|
||||
}
|
||||
|
||||
@Deprecated //Use the TagCollection version
|
||||
default Tag.Builder<T> addOptional(final Function<ResourceLocation, Optional<T>> entryLookup, final Collection<ResourceLocation> locations)
|
||||
{
|
||||
return ((Tag.Builder<T>)this).add(new IOptionalTagEntry<T>() {
|
||||
@Override
|
||||
public void populate(Collection<T> itemsIn)
|
||||
{
|
||||
locations.stream().map(entryLookup).forEach(e -> e.ifPresent(itemsIn::add));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(JsonArray array, Function<T, ResourceLocation> getNameForObject)
|
||||
{
|
||||
locations.stream().map(ResourceLocation::toString).forEach(array::add);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
default Tag.Builder<T> addOptionalTag(final TagCollection<T> collection, @SuppressWarnings("unchecked") final Tag<T>... tags)
|
||||
{
|
||||
for (Tag<T> tag : tags)
|
||||
addOptionalTag(tag.getId());
|
||||
return ((Tag.Builder<T>)this);
|
||||
}
|
||||
|
||||
default Tag.Builder<T> addOptionalTag(final ResourceLocation... tags)
|
||||
{
|
||||
for (ResourceLocation rl : tags)
|
||||
addOptionalTag(rl);
|
||||
return ((Tag.Builder<T>)this);
|
||||
}
|
||||
|
||||
default Tag.Builder<T> addOptionalTag(ResourceLocation tag)
|
||||
{
|
||||
return ((Tag.Builder<T>)this).add(new OptionalTagEntry<>(tag));
|
||||
}
|
||||
}
|
||||
|
||||
class OptionalListEntry<T> implements IOptionalTagEntry<T>
|
||||
{
|
||||
private final Collection<ResourceLocation> names;
|
||||
private final Function<ResourceLocation, Optional<T>> valueGetter;
|
||||
|
||||
OptionalListEntry(Collection<ResourceLocation> names, Function<ResourceLocation, Optional<T>> valueGetter)
|
||||
{
|
||||
this.names = names;
|
||||
this.valueGetter = valueGetter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(Collection<T> itemsIn)
|
||||
{
|
||||
for (ResourceLocation rl : names)
|
||||
{
|
||||
valueGetter.apply(rl).ifPresent(itemsIn::add);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(JsonArray array, Function<T, ResourceLocation> getNameForObject)
|
||||
{
|
||||
for (ResourceLocation rl : names)
|
||||
{
|
||||
array.add(rl.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class OptionalTagEntry<T> extends Tag.TagEntry<T> implements IOptionalTagEntry<T>
|
||||
{
|
||||
private Tag<T> resolvedTag = null;
|
||||
|
||||
OptionalTagEntry(ResourceLocation referent)
|
||||
{
|
||||
super(referent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resolve(@Nonnull Function<ResourceLocation, Tag<T>> resolver)
|
||||
{
|
||||
if (this.resolvedTag == null)
|
||||
{
|
||||
this.resolvedTag = resolver.apply(this.getSerializedId());
|
||||
}
|
||||
return true; // never fail if resolver returns null
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(@Nonnull Collection<T> items)
|
||||
{
|
||||
if (this.resolvedTag != null)
|
||||
{
|
||||
items.addAll(this.resolvedTag.getAllElements());
|
||||
}
|
||||
class TagTarget<U> extends Tag.TagEntry<U> implements IOptionalTagEntry<U>
|
||||
{
|
||||
private Tag<U> resolvedTag = null;
|
||||
protected TagTarget(ResourceLocation referent) {
|
||||
super(referent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resolve(@Nonnull Function<ResourceLocation, Tag<U>> resolver)
|
||||
{
|
||||
if (this.resolvedTag == null)
|
||||
this.resolvedTag = resolver.apply(this.getSerializedId());
|
||||
return true; // never fail if resolver returns null
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(@Nonnull Collection<U> items)
|
||||
{
|
||||
if (this.resolvedTag != null)
|
||||
items.addAll(this.resolvedTag.getAllElements());
|
||||
}
|
||||
};
|
||||
|
||||
return ((Tag.Builder<T>)this).add(new TagTarget<>(tag));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user