2015-11-16 06:50:54 +03:00
|
|
|
package net.minecraftforge.debug;
|
|
|
|
|
|
2017-05-29 02:10:40 -07:00
|
|
|
import com.google.common.collect.ImmutableMap;
|
2015-11-16 06:50:54 +03:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
|
import net.minecraft.block.properties.IProperty;
|
|
|
|
|
import net.minecraft.block.properties.PropertyDirection;
|
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
2016-03-05 04:43:41 +03:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
2016-01-01 18:15:48 +03:00
|
|
|
import net.minecraft.client.renderer.entity.Render;
|
|
|
|
|
import net.minecraft.client.renderer.entity.RenderLiving;
|
|
|
|
|
import net.minecraft.client.renderer.entity.RenderManager;
|
2015-11-16 06:50:54 +03:00
|
|
|
import net.minecraft.client.renderer.texture.TextureMap;
|
|
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2016-01-01 18:15:48 +03:00
|
|
|
import net.minecraft.entity.EntityLiving;
|
2015-11-16 06:50:54 +03:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2016-01-01 18:15:48 +03:00
|
|
|
import net.minecraft.entity.SharedMonsterAttributes;
|
2015-11-16 06:50:54 +03:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.item.Item;
|
2016-03-21 09:15:39 +03:00
|
|
|
import net.minecraft.item.ItemBlock;
|
2016-03-05 04:43:41 +03:00
|
|
|
import net.minecraft.item.ItemStack;
|
2016-03-21 09:15:39 +03:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-11-16 06:50:54 +03:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-05 04:43:41 +03:00
|
|
|
import net.minecraft.util.EnumHand;
|
2016-01-01 18:15:48 +03:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2016-03-05 04:43:41 +03:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2015-11-23 10:12:01 +03:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2015-11-16 06:50:54 +03:00
|
|
|
import net.minecraft.world.World;
|
2017-06-20 18:39:55 -07:00
|
|
|
import net.minecraftforge.client.event.ModelRegistryEvent;
|
2015-11-16 06:50:54 +03:00
|
|
|
import net.minecraftforge.client.model.ModelLoader;
|
2016-03-21 10:01:30 +03:00
|
|
|
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
2016-01-01 18:15:48 +03:00
|
|
|
import net.minecraftforge.client.model.animation.Animation;
|
|
|
|
|
import net.minecraftforge.client.model.animation.AnimationTESR;
|
2015-11-16 06:50:54 +03:00
|
|
|
import net.minecraftforge.client.model.b3d.B3DLoader;
|
2016-01-01 18:15:48 +03:00
|
|
|
import net.minecraftforge.client.model.pipeline.VertexLighterSmoothAo;
|
2016-03-21 10:01:30 +03:00
|
|
|
import net.minecraftforge.common.animation.Event;
|
|
|
|
|
import net.minecraftforge.common.animation.ITimeValue;
|
|
|
|
|
import net.minecraftforge.common.animation.TimeValues.VariableValue;
|
2016-03-21 09:15:39 +03:00
|
|
|
import net.minecraftforge.common.capabilities.Capability;
|
|
|
|
|
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
2016-03-21 10:01:30 +03:00
|
|
|
import net.minecraftforge.common.model.animation.CapabilityAnimation;
|
2016-01-01 18:15:48 +03:00
|
|
|
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
|
2015-11-16 06:50:54 +03:00
|
|
|
import net.minecraftforge.common.property.ExtendedBlockState;
|
|
|
|
|
import net.minecraftforge.common.property.IUnlistedProperty;
|
2016-01-01 18:15:48 +03:00
|
|
|
import net.minecraftforge.common.property.Properties;
|
2017-06-19 15:02:18 -07:00
|
|
|
import net.minecraftforge.debug.ItemTileDebug.TestBlock;
|
|
|
|
|
import net.minecraftforge.event.RegistryEvent;
|
2015-11-16 06:50:54 +03:00
|
|
|
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
2016-01-01 18:15:48 +03:00
|
|
|
import net.minecraftforge.fml.client.registry.IRenderFactory;
|
|
|
|
|
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
2015-11-16 06:50:54 +03:00
|
|
|
import net.minecraftforge.fml.common.Mod;
|
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventHandler;
|
2016-01-01 18:15:48 +03:00
|
|
|
import net.minecraftforge.fml.common.Mod.Instance;
|
2015-11-16 06:50:54 +03:00
|
|
|
import net.minecraftforge.fml.common.SidedProxy;
|
|
|
|
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
2017-06-19 15:02:18 -07:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
2016-01-01 18:15:48 +03:00
|
|
|
import net.minecraftforge.fml.common.registry.EntityRegistry;
|
2015-11-16 06:50:54 +03:00
|
|
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
2017-06-19 15:02:18 -07:00
|
|
|
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
|
|
|
|
|
|
2017-07-25 02:08:00 +02:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
2017-05-29 02:10:40 -07:00
|
|
|
import org.apache.logging.log4j.Logger;
|
2015-11-16 06:50:54 +03:00
|
|
|
|
2016-11-17 10:44:31 -08:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
|
2016-11-22 12:12:13 -08:00
|
|
|
@Mod(modid = ModelAnimationDebug.MODID, name = "ForgeDebugModelAnimation", version = ModelAnimationDebug.VERSION, acceptableRemoteVersions = "*")
|
2015-11-16 06:50:54 +03:00
|
|
|
public class ModelAnimationDebug
|
|
|
|
|
{
|
|
|
|
|
public static final String MODID = "forgedebugmodelanimation";
|
|
|
|
|
public static final String VERSION = "0.0";
|
|
|
|
|
|
2017-06-19 15:02:18 -07:00
|
|
|
public static final String blockName = "test_animation_block";
|
2015-11-16 06:50:54 +03:00
|
|
|
public static final PropertyDirection FACING = PropertyDirection.create("facing");
|
2017-06-19 15:02:18 -07:00
|
|
|
@ObjectHolder(blockName)
|
|
|
|
|
public static final Block TEST_BLOCK = null;
|
|
|
|
|
@ObjectHolder(blockName)
|
|
|
|
|
public static final Item TEST_ITEM = null;
|
2016-01-01 18:15:48 +03:00
|
|
|
|
|
|
|
|
@Instance(MODID)
|
|
|
|
|
public static ModelAnimationDebug instance;
|
2015-11-16 06:50:54 +03:00
|
|
|
|
2016-01-02 09:59:14 +03:00
|
|
|
@SidedProxy
|
2015-11-16 06:50:54 +03:00
|
|
|
public static CommonProxy proxy;
|
2017-05-29 02:10:40 -07:00
|
|
|
private static Logger logger;
|
2015-11-16 06:50:54 +03:00
|
|
|
|
2017-06-19 15:02:18 -07:00
|
|
|
|
|
|
|
|
@Mod.EventBusSubscriber(modid = MODID)
|
|
|
|
|
public static class Registration
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2017-06-19 15:02:18 -07:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public static void registerBlocks(RegistryEvent.Register<Block> event)
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2017-06-20 18:39:55 -07:00
|
|
|
GameRegistry.registerTileEntity(Chest.class, MODID + ":" + "tile_" + blockName);
|
2017-06-19 15:02:18 -07:00
|
|
|
event.getRegistry().register(
|
|
|
|
|
new Block(Material.WOOD)
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
|
|
|
|
{
|
2016-05-18 05:11:56 -07:00
|
|
|
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
|
2015-11-16 06:50:54 +03:00
|
|
|
setUnlocalizedName(MODID + "." + blockName);
|
2017-06-19 15:02:18 -07:00
|
|
|
setRegistryName(new ResourceLocation(MODID, blockName));
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ExtendedBlockState createBlockState()
|
|
|
|
|
{
|
2017-05-29 02:10:40 -07:00
|
|
|
return new ExtendedBlockState(this, new IProperty[]{FACING, Properties.StaticProperty}, new IUnlistedProperty[]{Properties.AnimationProperty});
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-05-29 02:10:40 -07:00
|
|
|
public boolean isOpaqueCube(IBlockState state)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-11-16 06:50:54 +03:00
|
|
|
|
|
|
|
|
@Override
|
2017-05-29 02:10:40 -07:00
|
|
|
public boolean isFullCube(IBlockState state)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-11-16 06:50:54 +03:00
|
|
|
|
|
|
|
|
@Override
|
2016-12-21 15:52:30 -08:00
|
|
|
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2016-12-21 15:52:30 -08:00
|
|
|
return this.getDefaultState().withProperty(FACING, EnumFacing.getDirectionFromEntityLiving(pos, placer));
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-05-29 02:10:40 -07:00
|
|
|
public IBlockState getStateFromMeta(int meta)
|
|
|
|
|
{
|
2015-11-16 06:50:54 +03:00
|
|
|
return getDefaultState().withProperty(FACING, EnumFacing.getFront(meta));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-05-29 02:10:40 -07:00
|
|
|
public int getMetaFromState(IBlockState state)
|
|
|
|
|
{
|
|
|
|
|
return state.getValue(FACING).getIndex();
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-05-29 02:10:40 -07:00
|
|
|
public boolean hasTileEntity(IBlockState state)
|
|
|
|
|
{
|
2015-11-16 06:50:54 +03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-05-29 02:10:40 -07:00
|
|
|
public TileEntity createTileEntity(World world, IBlockState state)
|
|
|
|
|
{
|
2016-01-01 18:15:48 +03:00
|
|
|
return new Chest();
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
|
|
|
|
|
2015-11-23 10:12:01 +03:00
|
|
|
@Override
|
2017-05-29 02:10:40 -07:00
|
|
|
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
|
|
|
{
|
2016-01-01 18:15:48 +03:00
|
|
|
return state.withProperty(Properties.StaticProperty, true);
|
2015-11-23 10:12:01 +03:00
|
|
|
}
|
|
|
|
|
|
2015-11-16 06:50:54 +03:00
|
|
|
/*@Override
|
|
|
|
|
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
|
|
|
|
TileEntity te = world.getTileEntity(pos);
|
|
|
|
|
if(te instanceof Chest && state instanceof IExtendedBlockState)
|
|
|
|
|
{
|
|
|
|
|
return ((Chest)te).getState((IExtendedBlockState)state);
|
|
|
|
|
}
|
|
|
|
|
return super.getExtendedState(state, world, pos);
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-11-13 17:09:54 -05:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2017-05-29 02:10:40 -07:00
|
|
|
if (world.isRemote)
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
|
|
|
|
TileEntity te = world.getTileEntity(pos);
|
2017-05-29 02:10:40 -07:00
|
|
|
if (te instanceof Chest)
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2017-05-29 02:10:40 -07:00
|
|
|
((Chest) te).click(player.isSneaking());
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
|
|
|
|
}
|
2016-01-01 18:15:48 +03:00
|
|
|
return true;
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
2016-04-03 10:13:50 +03:00
|
|
|
});
|
2017-06-19 15:02:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public static void registerItems(RegistryEvent.Register<Item> event)
|
|
|
|
|
{
|
|
|
|
|
event.getRegistry().register(
|
2017-06-25 04:08:20 +03:00
|
|
|
new ItemBlock(TEST_BLOCK)
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt)
|
2016-03-21 09:15:39 +03:00
|
|
|
{
|
2017-06-25 04:08:20 +03:00
|
|
|
return new ItemAnimationHolder();
|
|
|
|
|
}
|
|
|
|
|
}.setRegistryName(TEST_BLOCK.getRegistryName())
|
2017-06-19 15:02:18 -07:00
|
|
|
);
|
|
|
|
|
}
|
2017-07-25 02:08:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static abstract class CommonProxy
|
|
|
|
|
{
|
|
|
|
|
@Nullable
|
|
|
|
|
public IAnimationStateMachine load(ResourceLocation location, ImmutableMap<String, ITimeValue> parameters){ return null; };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class ServerProxy extends CommonProxy {}
|
|
|
|
|
|
|
|
|
|
@Mod.EventBusSubscriber(value = Side.CLIENT, modid = MODID)
|
|
|
|
|
public static class ClientProxy extends CommonProxy
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public IAnimationStateMachine load(ResourceLocation location, ImmutableMap<String, ITimeValue> parameters)
|
|
|
|
|
{
|
|
|
|
|
return ModelLoaderRegistry.loadASM(location, parameters);
|
|
|
|
|
}
|
2015-11-16 06:50:54 +03:00
|
|
|
|
2017-06-25 04:08:20 +03:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public static void registerModels(ModelRegistryEvent event)
|
2016-01-01 18:15:48 +03:00
|
|
|
{
|
2017-06-25 04:08:20 +03:00
|
|
|
B3DLoader.INSTANCE.addDomain(MODID);
|
|
|
|
|
ModelLoader.setCustomModelResourceLocation(TEST_ITEM, 0, new ModelResourceLocation(TEST_ITEM.getRegistryName(), "inventory"));
|
|
|
|
|
ClientRegistry.bindTileEntitySpecialRenderer(Chest.class, new AnimationTESR<Chest>()
|
2017-06-20 18:39:55 -07:00
|
|
|
{
|
2017-06-25 04:08:20 +03:00
|
|
|
@Override
|
|
|
|
|
public void handleEvents(Chest chest, float time, Iterable<Event> pastEvents)
|
|
|
|
|
{
|
|
|
|
|
chest.handleEvents(time, pastEvents);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
|
RenderingRegistry.registerEntityRenderingHandler(EntityChest.class, new IRenderFactory<EntityChest>()
|
2016-01-01 18:15:48 +03:00
|
|
|
{
|
2017-06-25 04:08:20 +03:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
|
public Render<EntityChest> createRenderFor(RenderManager manager)
|
|
|
|
|
{
|
2017-06-20 18:39:55 -07:00
|
|
|
/*model = ModelLoaderRegistry.getModel(new ResourceLocation(ModelLoaderRegistryDebug.MODID, "block/chest.b3d"));
|
|
|
|
|
if(model instanceof IRetexturableModel)
|
2016-01-01 18:15:48 +03:00
|
|
|
{
|
2017-06-20 18:39:55 -07:00
|
|
|
model = ((IRetexturableModel)model).retexture(ImmutableMap.of("#chest", "entity/chest/normal"));
|
2016-01-01 18:15:48 +03:00
|
|
|
}
|
2017-06-20 18:39:55 -07:00
|
|
|
if(model instanceof IModelCustomData)
|
|
|
|
|
{
|
|
|
|
|
model = ((IModelCustomData)model).process(ImmutableMap.of("mesh", "[\"Base\", \"Lid\"]"));
|
|
|
|
|
}*/
|
2017-06-25 04:08:20 +03:00
|
|
|
ResourceLocation location = new ModelResourceLocation(new ResourceLocation(MODID, blockName), "entity");
|
|
|
|
|
return new RenderLiving<EntityChest>(manager, new net.minecraftforge.client.model.animation.AnimationModelBase<EntityChest>(location, new VertexLighterSmoothAo(Minecraft.getMinecraft().getBlockColors()))
|
2016-01-01 18:15:48 +03:00
|
|
|
{
|
2017-06-25 04:08:20 +03:00
|
|
|
@Override
|
|
|
|
|
public void handleEvents(EntityChest chest, float time, Iterable<Event> pastEvents)
|
|
|
|
|
{
|
|
|
|
|
chest.handleEvents(time, pastEvents);
|
|
|
|
|
}
|
|
|
|
|
}, 0.5f)
|
2016-01-01 18:15:48 +03:00
|
|
|
{
|
2017-06-25 04:08:20 +03:00
|
|
|
protected ResourceLocation getEntityTexture(EntityChest entity)
|
|
|
|
|
{
|
|
|
|
|
return TextureMap.LOCATION_BLOCKS_TEXTURE;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-06-20 18:39:55 -07:00
|
|
|
}
|
|
|
|
|
|
2016-03-21 09:15:39 +03:00
|
|
|
private static class ItemAnimationHolder implements ICapabilityProvider
|
|
|
|
|
{
|
|
|
|
|
private final VariableValue cycleLength = new VariableValue(4);
|
|
|
|
|
|
|
|
|
|
private final IAnimationStateMachine asm = proxy.load(new ResourceLocation(MODID.toLowerCase(), "asms/block/engine.json"), ImmutableMap.<String, ITimeValue>of(
|
2017-05-29 02:10:40 -07:00
|
|
|
"cycle_length", cycleLength
|
2016-03-21 09:15:39 +03:00
|
|
|
));
|
|
|
|
|
|
2016-11-17 10:44:31 -08:00
|
|
|
@Override
|
|
|
|
|
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
|
2016-03-21 09:15:39 +03:00
|
|
|
{
|
|
|
|
|
return capability == CapabilityAnimation.ANIMATION_CAPABILITY;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 10:44:31 -08:00
|
|
|
@Override
|
|
|
|
|
@Nullable
|
|
|
|
|
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
|
2016-03-21 09:15:39 +03:00
|
|
|
{
|
2017-05-29 02:10:40 -07:00
|
|
|
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
2016-03-21 09:15:39 +03:00
|
|
|
{
|
2016-03-22 09:01:00 +03:00
|
|
|
return CapabilityAnimation.ANIMATION_CAPABILITY.cast(asm);
|
2016-03-21 09:15:39 +03:00
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-16 06:50:54 +03:00
|
|
|
@EventHandler
|
2017-05-29 02:10:40 -07:00
|
|
|
public void preInit(FMLPreInitializationEvent event)
|
|
|
|
|
{
|
|
|
|
|
logger = event.getModLog();
|
|
|
|
|
}
|
2015-11-16 06:50:54 +03:00
|
|
|
|
2016-03-21 09:15:39 +03:00
|
|
|
public static class Chest extends TileEntity
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2016-11-22 15:20:05 -08:00
|
|
|
@Nullable
|
2016-01-01 18:15:48 +03:00
|
|
|
private final IAnimationStateMachine asm;
|
|
|
|
|
private final VariableValue cycleLength = new VariableValue(4);
|
|
|
|
|
private final VariableValue clickTime = new VariableValue(Float.NEGATIVE_INFINITY);
|
|
|
|
|
//private final VariableValue offset = new VariableValue(0);
|
|
|
|
|
|
2017-05-29 02:10:40 -07:00
|
|
|
public Chest()
|
|
|
|
|
{
|
2016-01-01 18:15:48 +03:00
|
|
|
/*asm = proxy.load(new ResourceLocation(MODID.toLowerCase(), "asms/block/chest.json"), ImmutableMap.<String, ITimeValue>of(
|
|
|
|
|
"click_time", clickTime
|
|
|
|
|
));*/
|
|
|
|
|
asm = proxy.load(new ResourceLocation(MODID.toLowerCase(), "asms/block/engine.json"), ImmutableMap.<String, ITimeValue>of(
|
2017-05-29 02:10:40 -07:00
|
|
|
"cycle_length", cycleLength,
|
|
|
|
|
"click_time", clickTime
|
|
|
|
|
//"offset", offset
|
2016-01-01 18:15:48 +03:00
|
|
|
));
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
|
|
|
|
|
2016-01-01 18:15:48 +03:00
|
|
|
public void handleEvents(float time, Iterable<Event> pastEvents)
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2017-05-29 02:10:40 -07:00
|
|
|
for (Event event : pastEvents)
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2017-06-23 07:33:11 +02:00
|
|
|
logger.info("Event: {} {} {} {}", event.event(), event.offset(), getPos(), time);
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-01-01 18:15:48 +03:00
|
|
|
public boolean hasFastRenderer()
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2016-01-01 18:15:48 +03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*public IExtendedBlockState getState(IExtendedBlockState state) {
|
|
|
|
|
return state.withProperty(B3DFrameProperty.instance, curState);
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
public void click(boolean sneaking)
|
|
|
|
|
{
|
2017-05-29 02:10:40 -07:00
|
|
|
if (asm != null)
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2017-05-29 02:10:40 -07:00
|
|
|
if (sneaking)
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2016-01-01 18:15:48 +03:00
|
|
|
cycleLength.setValue(6 - cycleLength.apply(0));
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
2016-01-01 18:15:48 +03:00
|
|
|
/*else if(asm.currentState().equals("closed"))
|
|
|
|
|
{
|
|
|
|
|
clickTime.setValue(Animation.getWorldTime(getWorld()));
|
|
|
|
|
asm.transition("opening");
|
|
|
|
|
}
|
|
|
|
|
else if(asm.currentState().equals("open"))
|
|
|
|
|
{
|
|
|
|
|
clickTime.setValue(Animation.getWorldTime(getWorld()));
|
|
|
|
|
asm.transition("closing");
|
|
|
|
|
}*/
|
2017-05-29 02:10:40 -07:00
|
|
|
else if (asm.currentState().equals("default"))
|
2016-01-01 18:15:48 +03:00
|
|
|
{
|
2016-01-25 17:39:43 +03:00
|
|
|
float time = Animation.getWorldTime(getWorld(), Animation.getPartialTickTime());
|
2016-01-01 18:15:48 +03:00
|
|
|
clickTime.setValue(time);
|
|
|
|
|
//offset.setValue(time);
|
|
|
|
|
//asm.transition("moving");
|
|
|
|
|
asm.transition("starting");
|
|
|
|
|
}
|
2017-05-29 02:10:40 -07:00
|
|
|
else if (asm.currentState().equals("moving"))
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2016-01-25 17:39:43 +03:00
|
|
|
clickTime.setValue(Animation.getWorldTime(getWorld(), Animation.getPartialTickTime()));
|
2016-01-01 18:15:48 +03:00
|
|
|
asm.transition("stopping");
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-21 09:15:39 +03:00
|
|
|
@Override
|
2016-11-17 10:44:31 -08:00
|
|
|
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing side)
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2017-05-29 02:10:40 -07:00
|
|
|
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
2016-03-21 09:15:39 +03:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return super.hasCapability(capability, side);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-11-17 10:44:31 -08:00
|
|
|
@Nullable
|
|
|
|
|
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing side)
|
2016-03-21 09:15:39 +03:00
|
|
|
{
|
2017-05-29 02:10:40 -07:00
|
|
|
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
2016-03-21 09:15:39 +03:00
|
|
|
{
|
2016-03-22 09:01:00 +03:00
|
|
|
return CapabilityAnimation.ANIMATION_CAPABILITY.cast(asm);
|
2016-03-21 09:15:39 +03:00
|
|
|
}
|
|
|
|
|
return super.getCapability(capability, side);
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-21 09:15:39 +03:00
|
|
|
public static class EntityChest extends EntityLiving
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2016-01-01 18:15:48 +03:00
|
|
|
private final IAnimationStateMachine asm;
|
2016-03-21 09:15:39 +03:00
|
|
|
private final VariableValue cycleLength = new VariableValue(getHealth() / 5);
|
2015-11-16 06:50:54 +03:00
|
|
|
|
2016-01-01 18:15:48 +03:00
|
|
|
public EntityChest(World world)
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2016-01-01 18:15:48 +03:00
|
|
|
super(world);
|
|
|
|
|
setSize(1, 1);
|
|
|
|
|
asm = proxy.load(new ResourceLocation(MODID.toLowerCase(), "asms/block/engine.json"), ImmutableMap.<String, ITimeValue>of(
|
2017-05-29 02:10:40 -07:00
|
|
|
"cycle_length", cycleLength
|
2016-01-01 18:15:48 +03:00
|
|
|
));
|
|
|
|
|
}
|
2015-11-16 06:50:54 +03:00
|
|
|
|
2016-01-01 18:15:48 +03:00
|
|
|
public void handleEvents(float time, Iterable<Event> pastEvents)
|
|
|
|
|
{
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
}
|
2015-11-16 06:50:54 +03:00
|
|
|
|
2016-03-21 09:15:39 +03:00
|
|
|
@Override
|
|
|
|
|
public void onEntityUpdate()
|
2016-01-01 18:15:48 +03:00
|
|
|
{
|
2016-03-21 09:15:39 +03:00
|
|
|
super.onEntityUpdate();
|
2016-12-21 15:52:30 -08:00
|
|
|
if (world.isRemote && cycleLength != null)
|
2015-11-16 06:50:54 +03:00
|
|
|
{
|
2016-01-01 18:15:48 +03:00
|
|
|
cycleLength.setValue(getHealth() / 5);
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
2016-03-21 09:15:39 +03:00
|
|
|
}
|
2015-11-16 06:50:54 +03:00
|
|
|
|
2016-01-01 18:15:48 +03:00
|
|
|
@Override
|
|
|
|
|
protected void applyEntityAttributes()
|
|
|
|
|
{
|
|
|
|
|
super.applyEntityAttributes();
|
2016-03-13 04:40:03 +03:00
|
|
|
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(60);
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
2016-03-21 09:15:39 +03:00
|
|
|
|
|
|
|
|
@Override
|
2016-11-17 10:44:31 -08:00
|
|
|
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing side)
|
2016-03-21 09:15:39 +03:00
|
|
|
{
|
2017-05-29 02:10:40 -07:00
|
|
|
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
2016-03-21 09:15:39 +03:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return super.hasCapability(capability, side);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-11-17 10:44:31 -08:00
|
|
|
@Nullable
|
|
|
|
|
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing side)
|
2016-03-21 09:15:39 +03:00
|
|
|
{
|
2017-05-29 02:10:40 -07:00
|
|
|
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
2016-03-21 09:15:39 +03:00
|
|
|
{
|
2016-03-22 09:01:00 +03:00
|
|
|
return CapabilityAnimation.ANIMATION_CAPABILITY.cast(asm);
|
2016-03-21 09:15:39 +03:00
|
|
|
}
|
|
|
|
|
return super.getCapability(capability, side);
|
|
|
|
|
}
|
2015-11-16 06:50:54 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|