More lexicon faffing

This commit is contained in:
Vincent Lee committed 2016-02-06 22:39:43 -06:00
1 parent 26bc6b0059
commit 8cf71200ee
7 files changed
+108 -129

No files matched your search

@@ -26,7 +26,7 @@ import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import vazkii.botania.client.core.helper.IconHelper;
import vazkii.botania.client.model.FloatingFlowerModel;
import vazkii.botania.client.model.LexiconModelDispatcher;
import vazkii.botania.client.model.LexiconModel;
import vazkii.botania.client.model.PlatformModel;
import vazkii.botania.client.model.PylonItemModel;
import vazkii.botania.common.block.ModBlocks;
@@ -109,7 +109,7 @@ public class MiscellaneousIcons {
evt.modelRegistry.putObject(new ModelResourceLocation("botania:platform", "normal"), new PlatformModel());
// Lexicon
evt.modelRegistry.putObject(new ModelResourceLocation("botania:lexicon", "inventory"), new LexiconModelDispatcher());
evt.modelRegistry.putObject(new ModelResourceLocation("botania:lexicon", "inventory"), new LexiconModel());
}
@SubscribeEvent
@@ -1,52 +0,0 @@
package vazkii.botania.client.model;
import com.google.common.collect.ImmutableMap;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModelState;
import net.minecraftforge.client.model.ISmartItemModel;
import net.minecraftforge.client.model.animation.Animation;
import net.minecraftforge.client.model.animation.Event;
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
import org.apache.commons.lang3.tuple.Pair;
import vazkii.botania.client.core.handler.ClientTickHandler;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class LexiconAnimatedModel implements ISmartItemModel {
private final IBakedModel baseModel;
private final Map<IModelState, IBakedModel> cache; // No need to free this, LexiconAnimatedModels are destroyed on resource reload
private final IAnimationStateMachine asm;
protected LexiconAnimatedModel(IBakedModel baseModel) {
this.baseModel = baseModel;
this.cache = new HashMap<>();
this.asm = Animation.INSTANCE.load(new ResourceLocation("botania", "asms/item/lexicon_firstperson.json"), ImmutableMap.of());
}
@Override
public IBakedModel handleItemState(ItemStack stack) {
float time = (ClientTickHandler.ticksInGame + ClientTickHandler.partialTicks) / 20F;
Pair<IModelState, Iterable<Event>> pair = asm.apply(time);
// baseModel
return baseModel; // todo
}
@Override public List<BakedQuad> getFaceQuads(EnumFacing e) { return baseModel.getFaceQuads(e); }
@Override public List<BakedQuad> getGeneralQuads() { return baseModel.getGeneralQuads(); }
@Override public boolean isAmbientOcclusion() { return baseModel.isAmbientOcclusion(); }
@Override public boolean isGui3d() { return baseModel.isGui3d(); }
@Override public boolean isBuiltInRenderer() { return baseModel.isBuiltInRenderer(); }
@Override public TextureAtlasSprite getParticleTexture() { return baseModel.getParticleTexture(); }
@SuppressWarnings("deprecation")
@Override public ItemCameraTransforms getItemCameraTransforms() { return baseModel.getItemCameraTransforms(); }
}
@@ -1,18 +1,25 @@
package vazkii.botania.client.model;
import com.google.common.collect.ImmutableMap;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.resources.IReloadableResourceManager;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.Attributes;
import net.minecraftforge.client.model.IFlexibleBakedModel;
import net.minecraftforge.client.model.IModelState;
import net.minecraftforge.client.model.IPerspectiveAwareModel;
import net.minecraftforge.client.model.TRSRTransformation;
import net.minecraftforge.client.model.animation.Animation;
import net.minecraftforge.client.model.animation.Event;
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
import org.apache.commons.lang3.tuple.Pair;
import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.common.core.handler.ConfigHandler;
import javax.vecmath.Matrix4f;
import java.util.List;
@@ -20,10 +27,11 @@ import java.util.List;
/**
* This class handles choosing between the lexicon's default model and the special first person one
*/
public class LexiconModelDispatcher implements IPerspectiveAwareModel {
public class LexiconModel implements IPerspectiveAwareModel {
private IFlexibleBakedModel normalModel;
private IFlexibleBakedModel specialModel;
private IAnimationStateMachine asm;
private IFlexibleBakedModel getNormalModel() {
if (normalModel == null) {
@@ -36,9 +44,13 @@ public class LexiconModelDispatcher implements IPerspectiveAwareModel {
private IFlexibleBakedModel getSpecialModel() {
if (specialModel == null) {
specialModel = new IFlexibleBakedModel.Wrapper(new LexiconAnimatedModel(Minecraft.getMinecraft()
specialModel = new IFlexibleBakedModel.Wrapper(Minecraft.getMinecraft()
.getRenderItem().getItemModelMesher().getModelManager()
.getModel(new ModelResourceLocation("botania:lexicon_firstperson", "inventory"))), Attributes.DEFAULT_BAKED_FORMAT);
.getModel(new ModelResourceLocation("botania:lexicon_firstperson", "inventory")), Attributes.DEFAULT_BAKED_FORMAT);
}
if (asm == null) {
asm = Animation.INSTANCE.load(new ResourceLocation("botania", "asms/item/lexicon_firstperson.json"), ImmutableMap.of());
}
return specialModel;
}
@@ -46,8 +58,13 @@ public class LexiconModelDispatcher implements IPerspectiveAwareModel {
@SuppressWarnings("deprecation")
@Override
public Pair<? extends IFlexibleBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) {
if (cameraTransformType == ItemCameraTransforms.TransformType.FIRST_PERSON) {
return Pair.of(getSpecialModel(), new TRSRTransformation(getSpecialModel().getItemCameraTransforms().getTransform(cameraTransformType)).getMatrix());
if (ConfigHandler.lexicon3dModel && cameraTransformType == ItemCameraTransforms.TransformType.FIRST_PERSON) {
IFlexibleBakedModel model = getSpecialModel();
float time = (ClientTickHandler.ticksInGame + ClientTickHandler.partialTicks) / 20F;
Pair<IModelState, Iterable<Event>> animate = asm.apply(time);
return Pair.of(model, new TRSRTransformation(model.getItemCameraTransforms().getTransform(cameraTransformType)).getMatrix());
} else {
return Pair.of(getNormalModel(), new TRSRTransformation(getNormalModel().getItemCameraTransforms().getTransform(cameraTransformType)).getMatrix());
}
@@ -1,41 +0,0 @@
{
"joints": {
"spine": { "1": [ 1.0 ] },
"left_side": {},
"right_side": {},
"left_flip": { "4": [ 1.0 ] },
"right_flip": { "5": [ 1.0 ] }
},
"clips": {
"closed": {
"loop": false,
"joint_clips": {},
"events": {}
},
"open": {
"loop": false,
"joint_clips": {},
"events": {}
},
"opening": {
"loop": false,
"joint_clips": {},
"events": {}
},
"closing": {
"loop": false,
"joint_clips": {},
"events": {}
},
"flip_left": {
"loop": false,
"joint_clips": {},
"events": {}
},
"flip_right": {
"loop": false,
"joint_clips": {},
"events": {}
}
}
}
@@ -0,0 +1,77 @@
{
"joints": {
"spine": { "1": [ 1.0 ] },
"left_side": { "0": [ 1.0 ], "3": [ 1.0 ] },
"right_side": { "2": [ 1.0 ], "6": [ 1.0 ] },
"left_flip": { "4": [ 1.0 ] },
"right_flip": { "5": [ 1.0 ] }
},
"clips": {
"closed": {
"loop": false,
"joint_clips": {
"spine": [],
"left_side": [],
"right_side": [],
"left_flip": [],
"right_flip": []
},
"events": {}
},
"open": {
"loop": false,
"joint_clips": {
"spine": [],
"left_side": [],
"right_side": [],
"left_flip": [],
"right_flip": []
},
"events": {}
},
"opening": {
"loop": false,
"joint_clips": {
"spine": [],
"left_side": [],
"right_side": [],
"left_flip": [],
"right_flip": []
},
"events": {}
},
"closing": {
"loop": false,
"joint_clips": {
"spine": [],
"left_side": [],
"right_side": [],
"left_flip": [],
"right_flip": []
},
"events": {}
},
"flip_left": {
"loop": false,
"joint_clips": {
"spine": [],
"left_side": [],
"right_side": [],
"left_flip": [],
"right_flip": []
},
"events": {}
},
"flip_right": {
"loop": false,
"joint_clips": {
"spine": [],
"left_side": [],
"right_side": [],
"left_flip": [],
"right_flip": []
},
"events": {}
}
}
}
@@ -1,8 +1,8 @@
{
"parameters": {},
"clips": {
"closed": "botania:block/lexicon_firstperson@closed",
"open": "botania:block/lexicon_firstperson@open"
"closed": "botania:item/lexicon_firstperson@closed",
"open": "botania:item/lexicon_firstperson@open"
},
"states": [ "closed", "open", "opening", "closing" ],
"transitions": {
@@ -1,16 +1,4 @@
{
"display": {
"thirdperson": {
"rotation": [ -90, 0, 0 ],
"translation": [ 0, 1, -3 ],
"scale": [ 0.55, 0.55, 0.55 ]
},
"firstperson": {
"rotation": [ 0, -135, 25 ],
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
},
"elements": [
{
"name": "FrontCover",
@@ -20,9 +8,7 @@
"north": { "texture": "#-1", "uv": [ 0.0, 0.0, 6.0, 10.0 ] },
"east": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.0, 10.0 ] },
"south": { "texture": "#-1", "uv": [ 0.0, 0.0, 6.0, 10.0 ] },
"west": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.0, 10.0 ] },
"up": { "texture": "#-1", "uv": [ 0.0, 0.0, 6.0, 0.0 ] },
"down": { "texture": "#-1", "uv": [ 0.0, 0.0, 6.0, 0.0 ] }
"west": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.0, 10.0 ] }
}
},
{
@@ -46,9 +32,7 @@
"north": { "texture": "#-1", "uv": [ 0.0, 0.0, 6.0, 10.0 ] },
"east": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.0, 10.0 ] },
"south": { "texture": "#-1", "uv": [ 0.0, 0.0, 6.0, 10.0 ] },
"west": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.0, 10.0 ] },
"up": { "texture": "#-1", "uv": [ 0.0, 0.0, 6.0, 0.0 ] },
"down": { "texture": "#-1", "uv": [ 0.0, 0.0, 6.0, 0.0 ] }
"west": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.0, 10.0 ] }
}
},
{
@@ -58,7 +42,6 @@
"faces": {
"north": { "texture": "#-1", "uv": [ 0.0, 0.0, 5.0, 8.0 ] },
"east": { "texture": "#-1", "uv": [ 0.0, 0.0, 1.0, 8.0 ] },
"south": { "texture": "#-1", "uv": [ 0.0, 0.0, 5.0, 8.0 ] },
"west": { "texture": "#-1", "uv": [ 0.0, 0.0, 1.0, 8.0 ] },
"up": { "texture": "#-1", "uv": [ 0.0, 0.0, 5.0, 1.0 ] },
"down": { "texture": "#-1", "uv": [ 0.0, 0.0, 5.0, 1.0 ] }
@@ -72,9 +55,7 @@
"north": { "texture": "#-1", "uv": [ 0.0, 0.0, 5.0, 8.0 ] },
"east": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.0, 8.0 ] },
"south": { "texture": "#-1", "uv": [ 0.0, 0.0, 5.0, 8.0 ] },
"west": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.0, 8.0 ] },
"up": { "texture": "#-1", "uv": [ 0.0, 0.0, 5.0, 0.0 ] },
"down": { "texture": "#-1", "uv": [ 0.0, 0.0, 5.0, 0.0 ] }
"west": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.0, 8.0 ] }
}
},
{
@@ -85,9 +66,7 @@
"north": { "texture": "#-1", "uv": [ 0.0, 0.0, 5.0, 8.0 ] },
"east": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.0, 8.0 ] },
"south": { "texture": "#-1", "uv": [ 0.0, 0.0, 5.0, 8.0 ] },
"west": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.0, 8.0 ] },
"up": { "texture": "#-1", "uv": [ 0.0, 0.0, 5.0, 0.0 ] },
"down": { "texture": "#-1", "uv": [ 0.0, 0.0, 5.0, 0.0 ] }
"west": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.0, 8.0 ] }
}
},
{
@@ -95,7 +74,6 @@
"from": [ 5.0, 1.0, 7.0 ],
"to": [ 10.0, 9.0, 8.0 ],
"faces": {
"north": { "texture": "#-1", "uv": [ 0.0, 0.0, 5.0, 8.0 ] },
"east": { "texture": "#-1", "uv": [ 0.0, 0.0, 1.0, 8.0 ] },
"south": { "texture": "#-1", "uv": [ 0.0, 0.0, 5.0, 8.0 ] },
"west": { "texture": "#-1", "uv": [ 0.0, 0.0, 1.0, 8.0 ] },