Cleanup of model system, taking advantage of java 8;

replaced guava Optional and Function with java 8 versions.
This commit is contained in:
RainWarrior committed 2017-06-25 04:08:20 +03:00
1 parent 1c24600bbb
commit dc043ac79f
93 files changed
+664 -1271

No files matched your search

@@ -26,6 +26,7 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
@@ -53,7 +54,7 @@ import net.minecraftforge.fml.common.eventhandler.Event;
import org.apache.logging.log4j.Level;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ArrayListMultimap;
@@ -129,14 +130,7 @@ public class ForgeChunkManager
final ImmutableSetMultimap<ChunkPos, Ticket> persistentChunksFor = getPersistentChunksFor(world);
final ImmutableSet.Builder<Chunk> builder = ImmutableSet.builder();
world.profiler.startSection("forcedChunkLoading");
builder.addAll(Iterators.transform(persistentChunksFor.keys().iterator(), new Function<ChunkPos, Chunk>() {
@Nullable
@Override
public Chunk apply(@Nullable ChunkPos input)
{
return input == null ? null : world.getChunkFromChunkCoords(input.x, input.z);
}
}));
builder.addAll(persistentChunksFor.keys().stream().filter(Objects::nonNull).map(input -> world.getChunkFromChunkCoords(input.x, input.z)).iterator());
world.profiler.endStartSection("regularChunkLoading");
builder.addAll(chunkIterator);
world.profiler.endSection();
@@ -24,7 +24,7 @@ import java.util.regex.Pattern;
import net.minecraft.util.IStringSerializable;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;
@@ -29,7 +29,7 @@ import java.util.concurrent.Callable;
import org.apache.logging.log4j.Level;
import org.objectweb.asm.Type;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
@@ -19,7 +19,7 @@
package net.minecraftforge.common.model;
import com.google.common.base.Optional;
import java.util.Optional;
/*
* Represents the dynamic information associated with the model.
@@ -42,7 +42,7 @@ import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.collect.Maps;
/*
@@ -563,7 +563,7 @@ public final class TRSRTransformation implements IModelState, ITransformation
{
if(part.isPresent())
{
return Optional.absent();
return Optional.empty();
}
return Optional.of(this);
}
@@ -19,18 +19,24 @@
package net.minecraftforge.common.model.animation;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Supplier;
import com.google.common.collect.*;
import com.google.gson.*;
import com.google.common.base.Predicate;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
@@ -45,19 +51,18 @@ import net.minecraftforge.common.util.JsonUtils;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.logging.log4j.Level;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.gson.annotations.SerializedName;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
public final class AnimationStateMachine implements IAnimationStateMachine
{
@@ -88,21 +93,7 @@ public final class AnimationStateMachine implements IAnimationStateMachine
@Deprecated
public AnimationStateMachine(ImmutableMap<String, ITimeValue> parameters, ImmutableMap<String, IClip> clips, ImmutableList<String> states, ImmutableMap<String, String> transitions, String startState)
{
this(parameters, clips, states, ImmutableMultimap.copyOf(Multimaps.newSetMultimap(Maps.transformValues(transitions, new Function<String, Collection<String>>()
{
@Override
public Collection<String> apply(String input)
{
return ImmutableSet.of(input);
}
}), new Supplier<Set<String>>()
{
@Override
public Set<String> get()
{
return Sets.newHashSet();
}
})), startState);
this(parameters, clips, states, ImmutableMultimap.copyOf(Multimaps.newSetMultimap(Maps.transformValues(transitions, ImmutableSet::of), Sets::newHashSet)), startState);
}
public AnimationStateMachine(ImmutableMap<String, ITimeValue> parameters, ImmutableMap<String, IClip> clips, ImmutableList<String> states, ImmutableMultimap<String, String> transitions, String startState)
@@ -27,7 +27,6 @@ import net.minecraft.util.math.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.animation.IAnimatedModel;
import net.minecraftforge.common.animation.Event;
import net.minecraftforge.common.animation.ITimeValue;
import net.minecraftforge.common.model.IModelPart;
@@ -40,9 +39,9 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Ordering;
@@ -93,15 +92,12 @@ public final class Clips
public static IClip getModelClipNode(ResourceLocation modelLocation, String clipName)
{
IModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation);
if(model instanceof IAnimatedModel)
Optional<? extends IClip> clip = model.getClip(clipName);
if (clip.isPresent())
{
Optional<? extends IClip> clip = ((IAnimatedModel)model).getClip(clipName);
if(clip.isPresent())
{
return new ModelClip(clip.get(), modelLocation, clipName);
}
FMLLog.log.error("Unable to find clip {} in the model {}", clipName, modelLocation);
return new ModelClip(clip.get(), modelLocation, clipName);
}
FMLLog.log.error("Unable to find clip {} in the model {}", clipName, modelLocation);
// FIXME: missing clip?
return new ModelClip(IdentityClip.INSTANCE, modelLocation, clipName);
}
@@ -312,7 +308,7 @@ public final class Clips
{
if(!part.isPresent() || !(part.get() instanceof IJoint))
{
return Optional.absent();
return Optional.empty();
}
IJoint joint = (IJoint)part.get();
// TODO: Cache clip application?
@@ -19,7 +19,7 @@
package net.minecraftforge.common.model.animation;
import com.google.common.base.Optional;
import java.util.Optional;
import net.minecraftforge.common.model.IModelPart;
import net.minecraftforge.common.model.TRSRTransformation;
@@ -29,7 +29,7 @@ import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -65,7 +65,7 @@ public class ExtendedBlockState extends BlockStateContainer
ImmutableMap.Builder<IUnlistedProperty<?>, Optional<?>> builder = ImmutableMap.builder();
for(IUnlistedProperty<?> p : unlistedProperties)
{
builder.put(p, Optional.absent());
builder.put(p, Optional.empty());
}
return builder.build();
}
@@ -111,7 +111,7 @@ public class ExtendedBlockState extends BlockStateContainer
}
Map<IProperty<?>, Comparable<?>> map = Maps.newHashMap(getProperties());
map.put(property, value);
if (Iterables.all(unlistedProperties.values(), Predicates.<Optional<?>>equalTo(Optional.absent())))
if (Iterables.all(unlistedProperties.values(), Predicates.<Optional<?>>equalTo(Optional.empty())))
{ // no dynamic properties present, looking up in the normal table
return normalMap.get(map);
}
@@ -134,8 +134,8 @@ public class ExtendedBlockState extends BlockStateContainer
throw new IllegalArgumentException("Cannot set unlisted property " + property + " to " + value + " on block " + Block.REGISTRY.getNameForObject(getBlock()) + ", it is not an allowed value");
}
Map<IUnlistedProperty<?>, Optional<?>> newMap = new HashMap<IUnlistedProperty<?>, Optional<?>>(unlistedProperties);
newMap.put(property, Optional.fromNullable(value));
if(Iterables.all(newMap.values(), Predicates.<Optional<?>>equalTo(Optional.absent())))
newMap.put(property, Optional.ofNullable(value));
if(Iterables.all(newMap.values(), Predicates.<Optional<?>>equalTo(Optional.empty())))
{ // no dynamic properties, lookup normal state
return (IExtendedBlockState) normalMap.get(getProperties());
}
@@ -155,7 +155,7 @@ public class ExtendedBlockState extends BlockStateContainer
{
throw new IllegalArgumentException("Cannot get unlisted property " + property + " as it does not exist in " + getBlock().getBlockState());
}
return property.getType().cast(this.unlistedProperties.get(property).orNull());
return property.getType().cast(this.unlistedProperties.get(property).orElse(null));
}
@Override
@@ -23,7 +23,7 @@ import java.util.Collection;
import net.minecraft.block.state.IBlockState;
import com.google.common.base.Optional;
import java.util.Optional;
import com.google.common.collect.ImmutableMap;
public interface IExtendedBlockState extends IBlockState