Created
April 28, 2019 01:25
-
-
Save Cadiboo/19a928c6b3034f71c51ae333812950d5 to your computer and use it in GitHub Desktop.
REEEEEE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.github.cadiboo.nocubes.hooks; | |
import io.github.cadiboo.nocubes.NoCubes; | |
import io.github.cadiboo.nocubes.client.UVHelper; | |
import io.github.cadiboo.nocubes.client.render.RenderDispatcher; | |
import io.github.cadiboo.nocubes.config.Config; | |
import io.github.cadiboo.nocubes.mesh.MeshDispatcher; | |
import io.github.cadiboo.nocubes.util.pooled.Face; | |
import io.github.cadiboo.nocubes.util.pooled.FaceList; | |
import io.github.cadiboo.nocubes.util.pooled.Vec3; | |
import net.minecraft.block.Block; | |
import net.minecraft.block.state.IBlockState; | |
import net.minecraft.client.Minecraft; | |
import net.minecraft.client.multiplayer.WorldClient; | |
import net.minecraft.client.renderer.BlockRendererDispatcher; | |
import net.minecraft.client.renderer.BufferBuilder; | |
import net.minecraft.client.renderer.DestroyBlockProgress; | |
import net.minecraft.client.renderer.Tessellator; | |
import net.minecraft.client.renderer.chunk.ChunkRenderTask; | |
import net.minecraft.client.renderer.chunk.CompiledChunk; | |
import net.minecraft.client.renderer.chunk.RenderChunk; | |
import net.minecraft.client.renderer.chunk.RenderChunkCache; | |
import net.minecraft.client.renderer.chunk.VisGraph; | |
import net.minecraft.client.renderer.texture.TextureAtlasSprite; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.tileentity.TileEntity; | |
import net.minecraft.util.EnumBlockRenderType; | |
import net.minecraft.util.math.BlockPos; | |
import net.minecraft.world.World; | |
import java.util.HashSet; | |
import java.util.Random; | |
import static io.github.cadiboo.nocubes.util.IIsSmoothable.TERRAIN_SMOOTHABLE; | |
/** | |
* @author Cadiboo | |
*/ | |
public final class Hooks { | |
public static void preIteration(final RenderChunk renderChunk, final float x, final float y, final float z, final ChunkRenderTask generator, final CompiledChunk compiledchunk, final BlockPos blockpos, final BlockPos blockpos1, final World world, final RenderChunkCache lvt_10_1_, final VisGraph lvt_11_1_, final HashSet lvt_12_1_, final boolean[] aboolean, final Random random, final BlockRendererDispatcher blockrendererdispatcher) { | |
if (NoCubes.isEnabled()) { | |
RenderDispatcher.renderChunk(renderChunk, blockpos, generator, compiledchunk, world, aboolean); | |
} | |
} | |
//return if normal rendering should happen | |
public static boolean renderBlockDamage(final Tessellator tessellatorIn, final BufferBuilder bufferBuilderIn, final Entity entityIn, final float partialTicks, final double d0, final double d1, final double d2, final DestroyBlockProgress destroyblockprogress, final BlockPos blockpos, final Block block, final TileEntity te, final boolean hasBreak, final double d3, final double d4, final double d5, final IBlockState iblockstate, final WorldClient world, final int i, final TextureAtlasSprite textureatlassprite, final BlockRendererDispatcher blockrendererdispatcher) { | |
if (!NoCubes.isEnabled() || !Config.renderSmoothTerrain || !iblockstate.nocubes_isTerrainSmoothable()) { | |
return true; | |
} | |
if (iblockstate.getRenderType() == EnumBlockRenderType.MODEL) { | |
try (FaceList faces = MeshDispatcher.generateBlockMeshOffset(blockpos, world, TERRAIN_SMOOTHABLE, Config.terrainMeshGenerator)) { | |
float minU = UVHelper.getMinU(textureatlassprite); | |
float maxU = UVHelper.getMaxU(textureatlassprite); | |
float minV = UVHelper.getMinV(textureatlassprite); | |
float maxV = UVHelper.getMaxV(textureatlassprite); | |
int color = Minecraft.getInstance().getBlockColors().getColor(iblockstate, world, blockpos, -1); | |
float red = (float) (color >> 16 & 255) / 255.0F; | |
float green = (float) (color >> 8 & 255) / 255.0F; | |
float blue = (float) (color & 255) / 255.0F; | |
float alpha = 1.0F; | |
final int packed = iblockstate.getPackedLightmapCoords(world, blockpos); | |
int lightmapSkyLight = (packed >> 16) & 0xFFFF; | |
int lightmapBlockLight = packed & 0xFFFF; | |
for (final Face face : faces) { | |
try { | |
try ( | |
Vec3 v0 = face.getVertex0(); | |
Vec3 v1 = face.getVertex1(); | |
Vec3 v2 = face.getVertex2(); | |
Vec3 v3 = face.getVertex3() | |
) { | |
bufferBuilderIn.pos(v0.x, v0.y, v0.z).color(red, green, blue, alpha).tex(minU, minV).lightmap(lightmapSkyLight, lightmapBlockLight).endVertex(); | |
bufferBuilderIn.pos(v1.x, v1.y, v1.z).color(red, green, blue, alpha).tex(minU, maxV).lightmap(lightmapSkyLight, lightmapBlockLight).endVertex(); | |
bufferBuilderIn.pos(v2.x, v2.y, v2.z).color(red, green, blue, alpha).tex(maxU, maxV).lightmap(lightmapSkyLight, lightmapBlockLight).endVertex(); | |
bufferBuilderIn.pos(v3.x, v3.y, v3.z).color(red, green, blue, alpha).tex(maxU, minV).lightmap(lightmapSkyLight, lightmapBlockLight).endVertex(); | |
} | |
} finally { | |
face.close(); | |
} | |
} | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment