Kinda migrated crystal cuvbe to json

This commit is contained in:
Vincent Lee committed 2016-02-13 12:28:52 -06:00
1 parent b6204f9a41
commit 9fe4e0f8cc
4 files changed
+109 -8

No files matched your search

@@ -242,7 +242,7 @@ public class ClientProxy extends CommonProxy {
ClientRegistry.bindTileEntitySpecialRenderer(TilePrism.class, new RenderTilePrism());
ClientRegistry.bindTileEntitySpecialRenderer(TileCorporeaIndex.class, new RenderTileCorporeaIndex());
ClientRegistry.bindTileEntitySpecialRenderer(TilePump.class, new AnimationTESR<>());
ClientRegistry.bindTileEntitySpecialRenderer(TileCorporeaCrystalCube.class, new AnimationTESR<>());
ClientRegistry.bindTileEntitySpecialRenderer(TileCorporeaCrystalCube.class, new RenderTileCorporeaCrystalCube());
ClientRegistry.bindTileEntitySpecialRenderer(TileIncensePlate.class, new RenderTileIncensePlate());
ClientRegistry.bindTileEntitySpecialRenderer(TileHourglass.class, new RenderTileHourglass());
ClientRegistry.bindTileEntitySpecialRenderer(TileSparkChanger.class, new RenderTileSparkChanger());
@@ -10,17 +10,38 @@
*/
package vazkii.botania.client.render.tile;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.client.model.IModelState;
import net.minecraftforge.client.model.ISmartBlockModel;
import net.minecraftforge.client.model.animation.Animation;
import net.minecraftforge.client.model.animation.Event;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.Properties;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import org.apache.commons.lang3.tuple.Pair;
import org.lwjgl.opengl.GL11;
import vazkii.botania.client.core.handler.ClientTickHandler;
@@ -29,6 +50,8 @@ import vazkii.botania.client.model.ModelCrystalCube;
import vazkii.botania.common.block.tile.corporea.TileCorporeaCrystalCube;
import vazkii.botania.common.lib.LibObfuscation;
import java.util.concurrent.TimeUnit;
public class RenderTileCorporeaCrystalCube extends TileEntitySpecialRenderer<TileCorporeaCrystalCube> {
private static final ResourceLocation texture = new ResourceLocation(LibResources.MODEL_CRYSTAL_CUBE);
@@ -57,10 +80,10 @@ public class RenderTileCorporeaCrystalCube extends TileEntitySpecialRenderer<Til
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.color(1F, 1F, 1F, 1F);
GlStateManager.translate(d0, d1, d2);
mc.renderEngine.bindTexture(texture);
//mc.renderEngine.bindTexture(texture);
GlStateManager.translate(0.5F, 1.5F, 0.5F);
GlStateManager.scale(1F, -1F, -1F);
model.renderBase();
//model.renderBase();
GlStateManager.translate(0F, (float) Math.sin(worldTicks / 20.0) * 0.05F, 0F);
if(stack != null) {
GlStateManager.pushMatrix();
@@ -70,11 +93,11 @@ public class RenderTileCorporeaCrystalCube extends TileEntitySpecialRenderer<Til
GlStateManager.rotate(180F, 0F, 0F, 1F);
((Render) mc.getRenderManager().entityRenderMap.get(EntityItem.class)).doRender(entity, 0, 0, 0, 1F, f);
GlStateManager.popMatrix();
mc.renderEngine.bindTexture(texture);
//mc.renderEngine.bindTexture(texture);
}
GlStateManager.color(1F, 1F, 1F, 0.4F);
model.renderCube();
//GlStateManager.color(1F, 1F, 1F, 0.4F);
//model.renderCube();
GlStateManager.color(1F, 1F, 1F);
if(stack != null) {
@@ -113,6 +136,84 @@ public class RenderTileCorporeaCrystalCube extends TileEntitySpecialRenderer<Til
GlStateManager.scale(1F, -1F, -1F);
GlStateManager.enableRescaleNormal();
GlStateManager.popMatrix();
renderAnimatedModel(cube, d0, d1, d2, f);
}
// Copied from AnimationTESR
protected static BlockRendererDispatcher blockRenderer;
protected static final LoadingCache<Pair<IExtendedBlockState, IModelState>, IBakedModel> modelCache = CacheBuilder.newBuilder().maximumSize(10).expireAfterWrite(100, TimeUnit.MILLISECONDS).build(new CacheLoader<Pair<IExtendedBlockState, IModelState>, IBakedModel>()
{
public IBakedModel load(Pair<IExtendedBlockState, IModelState> key) throws Exception
{
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(key.getLeft().getClean());
if(model instanceof ISmartBlockModel)
{
model = ((ISmartBlockModel)model).handleBlockState(key.getLeft().withProperty(Properties.AnimationProperty, key.getRight()));
}
return model;
}
});
private static IBakedModel getModel(IExtendedBlockState state, IModelState modelState)
{
return modelCache.getUnchecked(Pair.of(state, modelState));
}
private void renderAnimatedModel(TileCorporeaCrystalCube te, double x, double y, double z, float partialTick) {
// From FastTESR.renderTileEntityAt
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldRenderer = tessellator.getWorldRenderer();
this.bindTexture(TextureMap.locationBlocksTexture);
RenderHelper.disableStandardItemLighting();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.enableBlend();
GlStateManager.disableCull();
if (Minecraft.isAmbientOcclusionEnabled())
{
GlStateManager.shadeModel(GL11.GL_SMOOTH);
}
else
{
GlStateManager.shadeModel(GL11.GL_FLAT);
}
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
// Inlined AnimationTESR.renderTileEntityFast
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.getPropertyNames().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);
Pair<IModelState, Iterable<Event>> pair = te.asm().apply(time);
// handleEvents(te, time, pair.getRight());
IBakedModel model = getModel(exState, pair.getLeft());
worldRenderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
blockRenderer.getBlockModelRenderer().renderModel(world, model, state, pos, worldRenderer, false);
}
}
// End inline AnimationTESR.renderTileEntityFast
worldRenderer.setTranslation(0, 0, 0);
tessellator.draw();
RenderHelper.enableStandardItemLighting();
}
}