mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Add rotation origin variable for animated models (#3875)
This commit is contained in:
1 parent
b930704955
commit
35e1737cb3
6 files changed
+262
-5
No files matched your search
@@ -326,6 +326,7 @@ public class ModelBlockAnimation
|
||||
time -= Math.floor(time);
|
||||
Vector3f translation = new Vector3f(0, 0, 0);
|
||||
Vector3f scale = new Vector3f(1, 1, 1);
|
||||
Vector3f origin = new Vector3f(0, 0, 0);
|
||||
AxisAngle4f rotation = new AxisAngle4f(0, 0, 0, 0);
|
||||
for(MBVariableClip var : variables)
|
||||
{
|
||||
@@ -390,11 +391,24 @@ public class ModelBlockAnimation
|
||||
case ZS:
|
||||
scale.z = value;
|
||||
break;
|
||||
case XORIGIN:
|
||||
origin.x = value - 0.5F;
|
||||
break;
|
||||
case YORIGIN:
|
||||
origin.y = value - 0.5F;
|
||||
break;
|
||||
case ZORIGIN:
|
||||
origin.z = value - 0.5F;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Quat4f rot = new Quat4f();
|
||||
rot.set(rotation);
|
||||
return TRSRTransformation.blockCenterToCorner(new TRSRTransformation(translation, rot, scale, null));
|
||||
TRSRTransformation base = new TRSRTransformation(translation, rot, scale, null);
|
||||
Vector3f negOrigin = new Vector3f(origin);
|
||||
negOrigin.negate();
|
||||
base = new TRSRTransformation(origin, null, null, null).compose(base).compose(new TRSRTransformation(negOrigin, null, null, null));
|
||||
return TRSRTransformation.blockCenterToCorner(base);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -498,7 +512,13 @@ public class ModelBlockAnimation
|
||||
@SerializedName("scale_y")
|
||||
YS,
|
||||
@SerializedName("scale_z")
|
||||
ZS;
|
||||
ZS,
|
||||
@SerializedName("origin_x")
|
||||
XORIGIN,
|
||||
@SerializedName("origin_y")
|
||||
YORIGIN,
|
||||
@SerializedName("origin_z")
|
||||
ZORIGIN;
|
||||
}
|
||||
|
||||
public static enum Type
|
||||
|
||||
@@ -22,9 +22,7 @@ import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
@@ -66,7 +64,9 @@ public class ModelAnimationDebug
|
||||
public static final String VERSION = "0.0";
|
||||
|
||||
public static String blockName = "test_animation_block";
|
||||
public static String blockSpinName = "rotatest";
|
||||
public static ResourceLocation blockId = new ResourceLocation(MODID, blockName);
|
||||
public static ResourceLocation blockSpinId = new ResourceLocation(MODID, blockSpinName);
|
||||
public static final PropertyDirection FACING = PropertyDirection.create("facing");
|
||||
|
||||
@Instance(MODID)
|
||||
@@ -166,6 +166,55 @@ public class ModelAnimationDebug
|
||||
return true;
|
||||
}
|
||||
});
|
||||
GameRegistry.register(new Block(Material.WOOD) {
|
||||
{
|
||||
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
|
||||
setUnlocalizedName(MODID + "." + blockSpinName);
|
||||
setRegistryName(blockSpinId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtendedBlockState createBlockState()
|
||||
{
|
||||
return new ExtendedBlockState(this, new IProperty[]{ Properties.StaticProperty }, new IUnlistedProperty[]{ Properties.AnimationProperty });
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) { return false; }
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(IBlockState state) { return false; }
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(IBlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumBlockRenderType getRenderType(IBlockState state) {
|
||||
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
@Override
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
return state.withProperty(Properties.StaticProperty, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, IBlockState state) {
|
||||
return new Spin();
|
||||
}
|
||||
|
||||
});
|
||||
GameRegistry.register(new ItemBlock(Block.REGISTRY.getObject(blockId))
|
||||
{
|
||||
@Override
|
||||
@@ -175,6 +224,7 @@ public class ModelAnimationDebug
|
||||
}
|
||||
}.setRegistryName(blockId));
|
||||
GameRegistry.registerTileEntity(Chest.class, MODID + ":" + "tile_" + blockName);
|
||||
GameRegistry.registerTileEntity(Spin.class, MODID + ":" + "tile_" + blockSpinName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -190,6 +240,50 @@ public class ModelAnimationDebug
|
||||
}
|
||||
}
|
||||
|
||||
public static class Spin extends TileEntity implements ITickable, ICapabilityProvider {
|
||||
|
||||
@Nullable
|
||||
private final IAnimationStateMachine asm;
|
||||
private final VariableValue cycle = new VariableValue(0);
|
||||
|
||||
public Spin() {
|
||||
asm = proxy.load(new ResourceLocation(MODID, "asms/block/rotatest.json"), ImmutableMap.<String, ITimeValue>of("cycle", cycle));
|
||||
|
||||
}
|
||||
|
||||
int tickcounter;
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
tickcounter++;
|
||||
if (world.isRemote) {
|
||||
cycle.setValue(tickcounter/40.0F);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing side) {
|
||||
return capability == CapabilityAnimation.ANIMATION_CAPABILITY || super.hasCapability(capability, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing side)
|
||||
{
|
||||
if(capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
||||
{
|
||||
return CapabilityAnimation.ANIMATION_CAPABILITY.cast(asm);
|
||||
}
|
||||
return super.getCapability(capability, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFastRenderer()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ClientProxy extends CommonProxy
|
||||
{
|
||||
@Override
|
||||
@@ -206,6 +300,7 @@ public class ModelAnimationDebug
|
||||
chest.handleEvents(time, pastEvents);
|
||||
}
|
||||
});
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(Spin.class, new AnimationTESR<Spin>());
|
||||
String entityName = MODID + ":entity_chest";
|
||||
//EntityRegistry.registerGlobalEntityID(EntityChest.class, entityName, EntityRegistry.findGlobalUniqueEntityId());
|
||||
EntityRegistry.registerModEntity(new ResourceLocation(entityName), EntityChest.class, entityName, 0, ModelAnimationDebug.instance, 64, 20, true, 0xFFAAAA00, 0xFFDDDD00);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"joints": {
|
||||
"wall": { "0": [1.0]},
|
||||
"wall2" : { "1": [1.0]},
|
||||
"stick": {"2": [1.0]},
|
||||
"cube": {"3": [1.0]}
|
||||
},
|
||||
"clips": {
|
||||
"default": {
|
||||
"loop": true,
|
||||
"joint_clips": {
|
||||
"stick": [
|
||||
{
|
||||
"variable": "offset_x",
|
||||
"type": "uniform",
|
||||
"interpolation": "linear",
|
||||
"samples": [0, 0.6875, 0]
|
||||
}
|
||||
],
|
||||
"cube": [
|
||||
{
|
||||
"variable": "offset_x",
|
||||
"type": "uniform",
|
||||
"interpolation": "linear",
|
||||
"samples": [0, 0.6875, 0]
|
||||
},
|
||||
{
|
||||
"variable": "axis_z",
|
||||
"type": "uniform",
|
||||
"interpolation": "nearest",
|
||||
"samples": [ 1 ]
|
||||
},
|
||||
{
|
||||
"variable": "origin_x",
|
||||
"type": "uniform",
|
||||
"interpolation": "nearest",
|
||||
"samples": [ 0.15625 ]
|
||||
},
|
||||
{
|
||||
"variable": "origin_y",
|
||||
"type": "uniform",
|
||||
"interpolation": "nearest",
|
||||
"samples": [ 0.40625 ]
|
||||
},
|
||||
{
|
||||
"variable": "angle",
|
||||
"type": "uniform",
|
||||
"interpolation": "linear",
|
||||
"samples": [0, 120, 240, 0, 120, 240]
|
||||
}
|
||||
]
|
||||
},
|
||||
"events": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"parameters": {
|
||||
|
||||
},
|
||||
"clips": {
|
||||
"default": ["apply", "forgedebugmodelanimation:block/rotatest@default", "#cycle" ]
|
||||
},
|
||||
"states": [
|
||||
"default"
|
||||
],
|
||||
"transitions": {},
|
||||
"start_state": "default"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"forge_marker": 1,
|
||||
"defaults": {
|
||||
"model": "forgedebugmodelanimation:rotatest"
|
||||
},
|
||||
"variants": {
|
||||
"normal": [{}],
|
||||
"static": {
|
||||
"true": {},
|
||||
"false": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"textures": {
|
||||
"0": "blocks/log_oak",
|
||||
"1": "blocks/iron_block",
|
||||
"2": "blocks/stone_slab_top",
|
||||
"3": "blocks/sponge"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"name": "WallA",
|
||||
"from": [ 0.0, 0.0, 0.0 ],
|
||||
"to": [ 16.0, 8.0, 2.0 ],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 8.0 ] },
|
||||
"east": { "texture": "#0", "uv": [ 0.0, 0.0, 2.0, 8.0 ] },
|
||||
"south": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 8.0 ] },
|
||||
"west": { "texture": "#0", "uv": [ 0.0, 0.0, 2.0, 8.0 ] },
|
||||
"up": { "texture": "#1", "uv": [ 0.0, 1.0, 16.0, 3.0 ] },
|
||||
"down": { "texture": "#1", "uv": [ 0.0, 1.0, 16.0, 3.0 ] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "WallB",
|
||||
"from": [ 0.0, 0.0, 14.0 ],
|
||||
"to": [ 16.0, 8.0, 16.0 ],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 8.0 ] },
|
||||
"east": { "texture": "#0", "uv": [ 0.0, 0.0, 2.0, 8.0 ] },
|
||||
"south": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 8.0 ] },
|
||||
"west": { "texture": "#0", "uv": [ 0.0, 0.0, 2.0, 8.0 ] },
|
||||
"up": { "texture": "#1", "uv": [ 0.0, 1.0, 16.0, 3.0 ] },
|
||||
"down": { "texture": "#1", "uv": [ 0.0, 1.0, 16.0, 3.0 ] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Stick",
|
||||
"from": [ 2.0, 6.0, 2.0 ],
|
||||
"to": [ 3.0, 7.0, 14.0 ],
|
||||
"faces": {
|
||||
"east": { "texture": "#2", "uv": [ 1.0, 1.0, 13.0, 2.0 ] },
|
||||
"west": { "texture": "#2", "uv": [ 1.0, 2.0, 13.0, 3.0 ] },
|
||||
"up": { "texture": "#2", "uv": [ 0.0, 0.0, 1.0, 12.0 ] },
|
||||
"down": { "texture": "#2", "uv": [ 0.0, 0.0, 1.0, 12.0 ] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Rotate",
|
||||
"from": [ 1.0, 5.0, 6.5 ],
|
||||
"to": [ 4.0, 8.0, 9.5 ],
|
||||
"faces": {
|
||||
"north": { "texture": "#3", "uv": [ 0.0, 0.0, 3.0, 3.0 ] },
|
||||
"east": { "texture": "#3", "uv": [ 0.0, 0.0, 3.0, 3.0 ] },
|
||||
"south": { "texture": "#3", "uv": [ 0.0, 0.0, 3.0, 3.0 ] },
|
||||
"west": { "texture": "#3", "uv": [ 0.0, 0.0, 3.0, 3.0 ] },
|
||||
"up": { "texture": "#3", "uv": [ 0.0, 0.0, 3.0, 3.0 ] },
|
||||
"down": { "texture": "#3", "uv": [ 0.0, 0.0, 3.0, 3.0 ] }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user