Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gamebuster19901.dungeonforge.client.render.tileentity;
- import org.apache.logging.log4j.Level;
- import org.lwjgl.opengl.GL11;
- import com.gamebuster19901.dungeonforge.Main;
- import com.gamebuster19901.dungeonforge.block.BlockWrapper;
- import com.gamebuster19901.dungeonforge.client.render.NonOccludedModel;
- import com.gamebuster19901.dungeonforge.tileentity.TileEntityChangeableBlock;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.entity.EntityPlayerSP;
- import net.minecraft.client.renderer.BlockRendererDispatcher;
- import net.minecraft.client.renderer.BufferBuilder;
- import net.minecraft.client.renderer.GlStateManager;
- import net.minecraft.client.renderer.RenderHelper;
- import net.minecraft.client.renderer.Tessellator;
- import net.minecraft.client.renderer.texture.TextureMap;
- import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
- import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
- import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.MathHelper;
- import net.minecraft.util.text.ITextComponent;
- public class TileEntityChangeableBlockRenderer<T extends TileEntityChangeableBlock> extends TileEntitySpecialRenderer<TileEntityChangeableBlock> {
- protected BlockRendererDispatcher renderer;
- private boolean canRenderTE = true;
- @Override
- public void render(TileEntityChangeableBlock te, double x, double y, double z, float partialTicks, int destroyStage, float alpha){
- EntityPlayerSP player = Minecraft.getMinecraft().player;
- ITextComponent itextcomponent = te.getHoverText(player);
- this.setLightmapDisabled(true);
- if (itextcomponent != null && this.rendererDispatcher.cameraHitResult != null && te.getPos().equals(this.rendererDispatcher.cameraHitResult.getBlockPos()))
- {
- if(player.isSneaking()) {
- this.drawNameplate(te, "When connected:", x, y + 0.3, z, 12);
- }
- else {
- this.drawNameplate(te, "When disconnected:", x, y + 0.3, z, 12);
- }
- this.drawNameplate(te, itextcomponent.getFormattedText(), x, y, z, 12);
- }
- renderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
- BlockWrapper wrapper = te.getDisplayingWrapper(Minecraft.getMinecraft().player);
- this.setLightmapDisabled(false);
- if(te == null || wrapper == null) {
- return;
- }
- Block block = wrapper.getBlock();
- BlockPos blockpos = new BlockPos(0,0,0);
- IBlockState blockState = block.getActualState(block.getStateFromMeta(wrapper.getMeta()), getWorld(), blockpos);
- TileEntitySpecialRenderer wrappedRenderer = null;
- if(block.hasTileEntity() && canRenderTE){
- TileEntity wrappedTileEntity = block.createTileEntity(getWorld(), block.getActualState(block.getStateFromMeta(wrapper.getMeta()), getWorld(), new BlockPos(x,y,z)));
- Class<TileEntity> wrappedTileEntityClass = (Class<TileEntity>) wrappedTileEntity.getClass();
- if (wrappedTileEntity != null) {
- wrappedRenderer = TileEntityRendererDispatcher.instance.renderers.get(wrappedTileEntityClass);
- if(wrappedRenderer != null) {
- try {
- wrappedTileEntity.setWorld(getWorld());
- wrappedRenderer.render(wrappedTileEntity, x, y, z, partialTicks, destroyStage, alpha);
- }
- catch(Exception e) {
- UnsupportedOperationException ex = new UnsupportedOperationException("Could not render TileEntityDoorwayMarkerRenderer with nbt " + wrapper.getNBT(), e);
- Main.LOGGER.catching(Level.ERROR, ex);
- canRenderTE = false;
- }
- }
- }
- }
- Tessellator tessellator = Tessellator.getInstance();
- BufferBuilder bufferbuilder = tessellator.getBuffer();
- if(block.getMaterial(blockState) != Material.AIR && wrappedRenderer == null || (wrappedRenderer != null && block.getBoundingBox(blockState, getWorld(), blockpos).equals(Block.FULL_BLOCK_AABB))){
- this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
- RenderHelper.disableStandardItemLighting();
- GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
- GlStateManager.enableBlend();
- GlStateManager.enableLighting();
- bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
- BlockPos tepos = te.getPos();
- bufferbuilder.setTranslation(x - tepos.getX(), tepos.getY(), tepos.getZ());
- if(partialTicks < 1.0F) {
- NonOccludedModel model = new NonOccludedModel(renderer.getModelForState(blockState));
- renderer.getBlockModelRenderer().renderModel(getWorld(), model, blockState, te.getPos(), bufferbuilder, false, MathHelper.getPositionRandom(blockpos));
- }
- tessellator.draw();
- bufferbuilder.setTranslation(0.0D, 0.0D, 0.0D);
- RenderHelper.enableStandardItemLighting();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement