Cleanup IForgeTagBuilder code style.
This commit is contained in:
parent
b6dc5381ca
commit
0d2a0deef3
|
@ -82,7 +82,7 @@
|
|||
}
|
||||
|
||||
public Tag.Builder<T> func_219783_a(Function<ResourceLocation, Optional<T>> p_219783_1_, JsonObject p_219783_2_) {
|
||||
@@ -143,8 +171,26 @@
|
||||
@@ -143,8 +171,10 @@
|
||||
}
|
||||
|
||||
this.field_200052_a.addAll(list);
|
||||
|
@ -90,26 +90,10 @@
|
|||
return this;
|
||||
}
|
||||
+ public Tag.Builder<T> remove(Tag.ITagEntry<T> e) { this.field_200052_a.remove(e); return this; }
|
||||
+
|
||||
+ public Tag.Builder<T> addOptional(TagCollection<T> collection, ResourceLocation entry) {
|
||||
+ return addOptional(collection.getEntryLookup(), Collections.singleton(entry));
|
||||
+ }
|
||||
+
|
||||
+ @SafeVarargs
|
||||
+ public final Tag.Builder<T> addOptional(TagCollection<T> collection, ResourceLocation... entries) {
|
||||
+ return addOptional(collection.getEntryLookup(), Lists.newArrayList(entries));
|
||||
+ }
|
||||
+
|
||||
+ @SafeVarargs
|
||||
+ public final Tag.Builder<T> addOptionalTag(ResourceLocation... tags) {
|
||||
+ for (ResourceLocation tag : tags)
|
||||
+ addOptionalTag(tag);
|
||||
+ return this;
|
||||
+ }
|
||||
}
|
||||
|
||||
public interface ITagEntry<T> {
|
||||
@@ -183,6 +229,8 @@
|
||||
@@ -183,6 +213,8 @@
|
||||
public Collection<T> func_200578_a() {
|
||||
return this.field_200165_a;
|
||||
}
|
||||
|
@ -118,7 +102,7 @@
|
|||
}
|
||||
|
||||
public static class TagEntry<T> implements Tag.ITagEntry<T> {
|
||||
@@ -229,5 +277,7 @@
|
||||
@@ -229,5 +261,7 @@
|
||||
public void func_200576_a(JsonArray p_200576_1_, Function<T, ResourceLocation> p_200576_2_) {
|
||||
p_200576_1_.add("#" + this.func_200577_a());
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
return this.field_199921_d;
|
||||
}
|
||||
+
|
||||
+ Function<ResourceLocation, Optional<T>> getEntryLookup() {
|
||||
+ public Function<ResourceLocation, Optional<T>> getEntryLookup() {
|
||||
+ return this.field_200040_e;
|
||||
+ }
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue