mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 12:42:26 +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,36 @@
|
||||
package net.minecraftforge.common.model.animation;
|
||||
|
||||
import net.minecraftforge.client.model.IModelState;
|
||||
import net.minecraftforge.client.model.animation.Event;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
/**
|
||||
* State machine representing the model animation.
|
||||
*/
|
||||
public interface IAnimationStateMachine
|
||||
{
|
||||
/**
|
||||
* Sample the state and events at the current time.
|
||||
* Event iterable will contain all events that happened from the last invocation of this method, from most to least recent.
|
||||
* Event offset is relative to the previous event, and for the first event it's relative to the current time.
|
||||
*/
|
||||
Pair<IModelState, Iterable<Event>> apply(float time);
|
||||
|
||||
/**
|
||||
* Transition to a new state.
|
||||
*/
|
||||
void transition(String newState);
|
||||
|
||||
/**
|
||||
* Get current state name.
|
||||
*/
|
||||
String currentState();
|
||||
|
||||
/**
|
||||
* Set to true if the machine should handle special events that come from the clips (they start with '!').
|
||||
* Right now only implemented event is "!transition:<state_name>".
|
||||
* Default value is true.
|
||||
*/
|
||||
void shouldHandleSpecialEvents(boolean value);
|
||||
}
|
||||
@@ -1,9 +1,27 @@
|
||||
package net.minecraftforge.common.property;
|
||||
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraftforge.client.model.IModelState;
|
||||
|
||||
public class Properties
|
||||
{
|
||||
/**
|
||||
* Property indicating if the model should be rendered in the static renderer or in the TESR. AnimationTESR sets it to false.
|
||||
*/
|
||||
public static final PropertyBool StaticProperty = PropertyBool.create("static");
|
||||
|
||||
/**
|
||||
* Property holding the IModelState used for animating the model in the TESR.
|
||||
*/
|
||||
public static final IUnlistedProperty<IModelState> AnimationProperty = new IUnlistedProperty<IModelState>()
|
||||
{
|
||||
public String getName() { return "forge_animation"; }
|
||||
public boolean isValid(IModelState state) { return true; }
|
||||
public Class<IModelState> getType() { return IModelState.class; }
|
||||
public String valueToString(IModelState state) { return state.toString(); }
|
||||
};
|
||||
|
||||
public static <V extends Comparable<V>> IUnlistedProperty<V> toUnlisted(IProperty<V> property)
|
||||
{
|
||||
return new PropertyAdapter<V>(property);
|
||||
|
||||
@@ -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