mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-23 21:49:46 +00:00
Model animation system.
Main things of interest:
* IAnimationStateMachine - state machine for animations; can load
from json.
* AnimationTESR - automatic TESR for animated models.
* AnimationModelBase - same for entities.
* ITimeValue - time-varying value, used to control animation
parameters from code.
* TESRs can now be batched - look at TESR.renderTileEntityFast +
TE.hasFastRenderer.
* RegionRenderCache is not accessible to TESRs and other client-side
logic - MinecraftForgeClient.getRegionRenderCache.
This commit is contained in:
1 parent
e9a86f27fb
commit
0710bdf3f5
44 files changed
+3185
-252
No files matched your search
@@ -0,0 +1,73 @@
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.reflect.TypeParameter;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
public class JsonUtils
|
||||
{
|
||||
// http://stackoverflow.com/questions/7706772/deserializing-immutablelist-using-gson/21677349#21677349
|
||||
public enum ImmutableListTypeAdapter implements JsonDeserializer<ImmutableList<?>>, JsonSerializer<ImmutableList<?>>
|
||||
{
|
||||
INSTANCE;
|
||||
|
||||
public ImmutableList<?> deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
final Type[] typeArguments = ((ParameterizedType) type).getActualTypeArguments();
|
||||
final Type parameterizedType = listOf(typeArguments[0]).getType();
|
||||
final List<?> list = context.deserialize(json, parameterizedType);
|
||||
return ImmutableList.copyOf(list);
|
||||
}
|
||||
|
||||
public JsonElement serialize(ImmutableList<?> src, Type type, JsonSerializationContext context)
|
||||
{
|
||||
final Type[] typeArguments = ((ParameterizedType) type).getActualTypeArguments();
|
||||
final Type parameterizedType = listOf(typeArguments[0]).getType();
|
||||
return context.serialize(src, parameterizedType);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "serial", "unchecked" })
|
||||
private static <E> TypeToken<List<E>> listOf(final Type arg)
|
||||
{
|
||||
return new TypeToken<List<E>>() {}.where(new TypeParameter<E>() {}, (TypeToken<E>) TypeToken.of(arg));
|
||||
}
|
||||
|
||||
public enum ImmutableMapTypeAdapter implements JsonDeserializer<ImmutableMap<String, ?>>, JsonSerializer<ImmutableMap<String, ?>>
|
||||
{
|
||||
INSTANCE;
|
||||
|
||||
public ImmutableMap<String, ?> deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
final Type[] typeArguments = ((ParameterizedType) type).getActualTypeArguments();
|
||||
final Type parameterizedType = mapOf(typeArguments[1]).getType();
|
||||
final Map<String, ?> map = context.deserialize(json, parameterizedType);
|
||||
return ImmutableMap.copyOf(map);
|
||||
}
|
||||
|
||||
public JsonElement serialize(ImmutableMap<String, ?> src, Type type, JsonSerializationContext context)
|
||||
{
|
||||
final Type[] typeArguments = ((ParameterizedType) type).getActualTypeArguments();
|
||||
final Type parameterizedType = mapOf(typeArguments[1]).getType();
|
||||
return context.serialize(src, parameterizedType);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "serial", "unchecked" })
|
||||
private static <E> TypeToken<Map<String, E>> mapOf(final Type arg)
|
||||
{
|
||||
return new TypeToken<Map<String, E>>() {}.where(new TypeParameter<E>() {}, (TypeToken<E>) TypeToken.of(arg));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user