use of net.minecraftforge.common.model.animation.IAnimationStateMachine in project MinecraftForge by MinecraftForge.
the class AnimationTESR method renderTileEntityFast.
public void renderTileEntityFast(@Nonnull T te, double x, double y, double z, float partialTick, int breakStage, @Nonnull VertexBuffer renderer) {
if (!te.hasCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null)) {
return;
}
if (blockRenderer == null)
blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
BlockPos pos = te.getPos();
IBlockAccess world = MinecraftForgeClient.getRegionRenderCache(te.getWorld(), pos);
IBlockState state = world.getBlockState(pos);
if (state.getPropertyKeys().contains(Properties.StaticProperty)) {
state = state.withProperty(Properties.StaticProperty, false);
}
if (state instanceof IExtendedBlockState) {
IExtendedBlockState exState = (IExtendedBlockState) state;
if (exState.getUnlistedNames().contains(Properties.AnimationProperty)) {
float time = Animation.getWorldTime(getWorld(), partialTick);
IAnimationStateMachine capability = te.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
if (capability != null) {
Pair<IModelState, Iterable<Event>> pair = capability.apply(time);
handleEvents(te, time, pair.getRight());
// TODO: caching?
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(exState.getClean());
exState = exState.withProperty(Properties.AnimationProperty, pair.getLeft());
renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
blockRenderer.getBlockModelRenderer().renderModel(world, model, exState, pos, renderer, false);
}
}
}
}
use of net.minecraftforge.common.model.animation.IAnimationStateMachine in project MinecraftForge by MinecraftForge.
the class AnimationModelBase method render.
@SuppressWarnings("unchecked")
@Override
public void render(Entity entity, float limbSwing, float limbSwingSpeed, float timeAlive, float yawHead, float rotationPitch, float scale) {
IAnimationStateMachine capability = entity.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
if (capability == null) {
return;
}
Pair<IModelState, Iterable<Event>> pair = capability.apply(timeAlive / 20);
handleEvents((T) entity, timeAlive / 20, pair.getRight());
IModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation);
IBakedModel bakedModel = model.bake(pair.getLeft(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
BlockPos pos = new BlockPos(entity.posX, entity.posY + entity.height, entity.posZ);
RenderHelper.disableStandardItemLighting();
GlStateManager.pushMatrix();
GlStateManager.rotate(180, 0, 0, 1);
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer VertexBuffer = tessellator.getBuffer();
VertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
VertexBuffer.setTranslation(-0.5, -1.5, -0.5);
lighter.setParent(new VertexBufferConsumer(VertexBuffer));
lighter.setWorld(entity.world);
lighter.setState(Blocks.AIR.getDefaultState());
lighter.setBlockPos(pos);
boolean empty = true;
List<BakedQuad> quads = bakedModel.getQuads(null, null, 0);
if (!quads.isEmpty()) {
lighter.updateBlockInfo();
empty = false;
for (BakedQuad quad : quads) {
quad.pipe(lighter);
}
}
for (EnumFacing side : EnumFacing.values()) {
quads = bakedModel.getQuads(null, side, 0);
if (!quads.isEmpty()) {
if (empty)
lighter.updateBlockInfo();
empty = false;
for (BakedQuad quad : quads) {
quad.pipe(lighter);
}
}
}
// debug quad
/*VertexBuffer.pos(0, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 0).lightmap(240, 0).endVertex();
VertexBuffer.pos(0, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 1).lightmap(240, 0).endVertex();
VertexBuffer.pos(1, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 1).lightmap(240, 0).endVertex();
VertexBuffer.pos(1, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 0).lightmap(240, 0).endVertex();*/
VertexBuffer.setTranslation(0, 0, 0);
tessellator.draw();
GlStateManager.popMatrix();
RenderHelper.enableStandardItemLighting();
}
Aggregations