mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 11:05:40 +00:00
[1.12.x] [Animation API] Add rotation origin variable (#4466)
This commit is contained in:
1 parent
f2adf0100c
commit
e283d51e28
6 files changed
+270
-5
No files matched your search
@@ -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;
|
||||
@@ -79,6 +77,10 @@ public class ModelAnimationDebug
|
||||
@ObjectHolder(blockName)
|
||||
public static final Item TEST_ITEM = null;
|
||||
|
||||
public static final String rotateBlockName = "rotatest";
|
||||
@ObjectHolder(rotateBlockName)
|
||||
public static final Block TEST_ROTATE_BLOCK = null;
|
||||
|
||||
@Instance(MODID)
|
||||
public static ModelAnimationDebug instance;
|
||||
|
||||
@@ -94,6 +96,7 @@ public class ModelAnimationDebug
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> event)
|
||||
{
|
||||
GameRegistry.registerTileEntity(Chest.class, MODID + ":" + "tile_" + blockName);
|
||||
GameRegistry.registerTileEntity(Spin.class, MODID + ":" + "tile_" + rotateBlockName);
|
||||
event.getRegistry().register(
|
||||
new Block(Material.WOOD)
|
||||
{
|
||||
@@ -181,6 +184,56 @@ public class ModelAnimationDebug
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
event.getRegistry().register(new Block(Material.WOOD){
|
||||
{
|
||||
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
|
||||
setUnlocalizedName(MODID + "." + rotateBlockName);
|
||||
setRegistryName(new ResourceLocation(MODID, rotateBlockName));
|
||||
}
|
||||
|
||||
@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 IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
return state.withProperty(Properties.StaticProperty, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumBlockRenderType getRenderType(IBlockState state) {
|
||||
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, IBlockState state) {
|
||||
return new Spin();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@@ -196,6 +249,11 @@ public class ModelAnimationDebug
|
||||
}
|
||||
}.setRegistryName(TEST_BLOCK.getRegistryName())
|
||||
);
|
||||
event.getRegistry().register(
|
||||
new ItemBlock(TEST_ROTATE_BLOCK) {
|
||||
|
||||
}.setRegistryName(TEST_ROTATE_BLOCK.getRegistryName())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,6 +287,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);
|
||||
@@ -298,6 +357,50 @@ public class ModelAnimationDebug
|
||||
logger = event.getModLog();
|
||||
}
|
||||
|
||||
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 Chest extends TileEntity
|
||||
{
|
||||
@Nullable
|
||||
|
||||
Reference in new issue
Block a user