Skip to content

Commit

Permalink
0.2.9-pre12
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadiboo committed May 12, 2019
1 parent 92faa92 commit 1ae69ea
Show file tree
Hide file tree
Showing 24 changed files with 1,439 additions and 1,048 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ org.gradle.daemon=false
# PATCH version when you make backwards-compatible bug fixes.
# Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
# We use the format MCVERSION-MAJOR.MINOR.PATCH
modVersion = 0.2.9-pre11
modVersion = 0.2.9-pre12

# The modid of our mod
modId = nocubes
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/cadiboo/nocubes/NoCubes.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.cadiboo.nocubes;

import io.github.cadiboo.nocubes.client.ClientProxy;
import io.github.cadiboo.nocubes.config.Config.ConfigHelper;
import io.github.cadiboo.nocubes.config.ConfigHelper;
import io.github.cadiboo.nocubes.config.ConfigHolder;
import io.github.cadiboo.nocubes.server.ServerProxy;
import io.github.cadiboo.nocubes.util.IProxy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.github.cadiboo.nocubes.NoCubes;
import io.github.cadiboo.nocubes.client.gui.toast.BlockStateToast;
import io.github.cadiboo.nocubes.config.Config;
import io.github.cadiboo.nocubes.config.Config.ConfigHelper;
import io.github.cadiboo.nocubes.config.ConfigHelper;
import io.github.cadiboo.nocubes.mesh.MeshDispatcher;
import io.github.cadiboo.nocubes.util.ModProfiler;
import io.github.cadiboo.nocubes.util.pooled.Face;
Expand All @@ -16,12 +16,15 @@
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.profiler.Profiler;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
Expand All @@ -34,6 +37,7 @@

import java.text.DecimalFormat;
import java.util.List;
import java.util.stream.Collectors;

import static io.github.cadiboo.nocubes.util.IsSmoothable.TERRAIN_SMOOTHABLE;
import static net.minecraft.util.math.RayTraceResult.Type.BLOCK;
Expand Down Expand Up @@ -64,14 +68,26 @@ public static void onClientTickEvent(final ClientTickEvent event) {
final boolean toggleLeavesSmoothableBlockStatePressed = ClientProxy.toggleLeavesSmoothableBlockState.isPressed();
final boolean toggleProfilersPressed = ClientProxy.toggleProfilers.isPressed();

if (ClientProxy.tempToggleCollisions.isPressed()) {
if (ClientProxy.tempToggleTerrainCollisions.isPressed()) {
final boolean oldTerrainCollisions = Config.terrainCollisions;
if (!Config.terrainCollisions) {
ConfigHelper.enableTerrainCollisions();
Minecraft.getInstance().player.sendMessage(new TextComponentTranslation(NoCubes.MOD_ID + ".collisionsEnabledWarning"));
Minecraft.getInstance().player.sendMessage(new TextComponentTranslation(NoCubes.MOD_ID + ".collisionsDisablePress", new TextComponentTranslation(ClientProxy.tempToggleCollisions.getKey().getTranslationKey())));
Minecraft.getInstance().player.sendMessage(new TextComponentTranslation(NoCubes.MOD_ID + ".collisionsDisablePress", new TextComponentTranslation(ClientProxy.tempToggleTerrainCollisions.getKey().getTranslationKey())));
} else {
ConfigHelper.disableTerrainCollisions();
Minecraft.getInstance().player.sendMessage(new TextComponentTranslation(NoCubes.MOD_ID + ".collisionsDisabled"));
}
Config.terrainCollisions = !Config.terrainCollisions;
//Config read+write is async so...
Config.terrainCollisions = !oldTerrainCollisions;
}

if (ClientProxy.tempToggleLeavesCollisions.isPressed()) {
if (!Config.leavesCollisions) {
ConfigHelper.enableLeavesCollisions();
} else {
ConfigHelper.disableLeavesCollisions();
}
}

if (toggleEnabledPressed || toggleTerrainSmoothableBlockStatePressed || toggleLeavesSmoothableBlockStatePressed || toggleProfilersPressed) {
Expand Down Expand Up @@ -302,6 +318,8 @@ protected static void renderProfilers() {
@SubscribeEvent
public static void onRenderWorldLastEvent(final RenderWorldLastEvent event) {

// if(true) return;

final EntityPlayer player = Minecraft.getInstance().player;
if (player == null) {
return;
Expand Down Expand Up @@ -478,6 +496,28 @@ public static void drawBlockHighlightEvent(final DrawBlockHighlightEvent event)

}

if (true) return;

GlStateManager.enableBlend();
GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.lineWidth(Math.max(2.5F, (float) Minecraft.getInstance().mainWindow.getFramebufferWidth() / 1920.0F * 2.5F));
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
GlStateManager.matrixMode(5889);
GlStateManager.pushMatrix();
GlStateManager.scalef(1.0F, 1.0F, 0.999F);
double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks;
double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks;
double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks;
for (final VoxelShape voxelShape : world.getCollisionBoxes(player, new AxisAlignedBB(player.getPosition()).grow(2)).collect(Collectors.toList())) {
WorldRenderer.drawShape(voxelShape, -d0, -d1, -d2, 0.0F, 1, 1, 0.4F);
}
GlStateManager.popMatrix();
GlStateManager.matrixMode(5888);
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();

// if (ModConfig.smoothBlockHighlighting || ModConfig.collisionsBlockHighlighting) {
// final EntityPlayer player = event.getPlayer();
// if (player == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.lwjgl.glfw.GLFW.GLFW_KEY_N;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_O;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_P;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_V;

/**
* The version of IProxy that gets injected into {@link NoCubes#PROXY} on a PHYSICAL CLIENT
Expand All @@ -28,7 +29,8 @@ public final class ClientProxy implements IProxy {
public static final KeyBinding toggleProfilers = new KeyBinding(MOD_ID + ".key.toggleProfilers", GLFW_KEY_P, "key.categories." + MOD_ID);
public static final KeyBinding toggleLeavesSmoothableBlockState = new KeyBinding(MOD_ID + ".key.toggleLeavesSmoothableBlockState", GLFW_KEY_K, "key.categories." + MOD_ID);

public static final KeyBinding tempToggleCollisions = new KeyBinding(MOD_ID + ".key.tempToggleCollisions", GLFW_KEY_C, "key.categories." + MOD_ID);
public static final KeyBinding tempToggleTerrainCollisions = new KeyBinding(MOD_ID + ".key.tempToggleTerrainCollisions", GLFW_KEY_C, "key.categories." + MOD_ID);
public static final KeyBinding tempToggleLeavesCollisions = new KeyBinding(MOD_ID + ".key.tempToggleLeavesCollisions", GLFW_KEY_V, "key.categories." + MOD_ID);

public static SmoothLightingBlockFluidRenderer fluidRenderer;

Expand Down
146 changes: 111 additions & 35 deletions src/main/java/io/github/cadiboo/nocubes/client/ClientUtil.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.github.cadiboo.nocubes.client;

import io.github.cadiboo.nocubes.util.IsSmoothable;
import io.github.cadiboo.nocubes.config.Config;
import io.github.cadiboo.nocubes.util.ModProfiler;
import io.github.cadiboo.nocubes.util.pooled.cache.SmoothableCache;
import io.github.cadiboo.nocubes.util.pooled.cache.StateCache;
import net.minecraft.block.BlockDirtSnowy;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
Expand All @@ -13,7 +14,6 @@
import net.minecraft.client.renderer.chunk.RenderChunk;
import net.minecraft.fluid.IFluidState;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.PooledMutableBlockPos;

Expand All @@ -22,6 +22,9 @@
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.round;
import static net.minecraft.init.Blocks.GRASS_BLOCK;
import static net.minecraft.init.Blocks.PODZOL;
import static net.minecraft.init.Blocks.SNOW;
import static net.minecraft.util.BlockRenderLayer.CUTOUT;
import static net.minecraft.util.BlockRenderLayer.CUTOUT_MIPPED;
import static net.minecraft.util.math.MathHelper.clamp;
Expand Down Expand Up @@ -116,57 +119,130 @@ public static int getLightmapBlockLightCoordsFromPackedLightmapCoords(int packed
}

/**
* @return a state and a texture pos which is guaranteed to be immutable
* Returns a state and sets the texturePooledMutablePos to the pos it found
*
* @return a state
*/
//TODO: smoothable cache
//TODO: texture cache?
public static Tuple<BlockPos, IBlockState> getTexturePosAndState(
@Nonnull final StateCache stateCache,
@Nonnull
public static IBlockState getTexturePosAndState(
final int posX, final int posY, final int posZ,
@Nonnull final PooledMutableBlockPos texturePooledMutablePos,
@Nonnull final IBlockState state,
@Deprecated @Nonnull final IsSmoothable isStateSmoothable,
@Nonnull final StateCache stateCache,
@Nonnull final SmoothableCache smoothableCache,
final byte relativePosX, final byte relativePosY, final byte relativePosZ
final int cacheAddX, final int cacheAddY, final int cacheAddZ,
final byte relativePosX, final byte relativePosY, final byte relativePosZ,
final boolean tryForBetterTexturesSnow, final boolean tryForBetterTexturesGrass
) {
try (final ModProfiler ignored = ModProfiler.get().start("getTexturePosAndState")) {

//check initial first
if (isStateSmoothable.apply(state)) {
return new Tuple<>(
texturePooledMutablePos.toImmutable(),
state
);
final boolean[] smoothableCacheArray = smoothableCache.getSmoothableCache();
final IBlockState[] blockCacheArray = stateCache.getBlockStates();

if (Config.betterTextures) {
if (tryForBetterTexturesSnow) {
try (final ModProfiler ignored = ModProfiler.get().start("getTexturePosAndState-tryForBetterTextures-snow")) {
IBlockState betterTextureState = blockCacheArray[stateCache.getIndex(
relativePosX + cacheAddX,
relativePosY + cacheAddY,
relativePosZ + cacheAddZ
)];

if (isStateSnow(betterTextureState)) {
texturePooledMutablePos.setPos(posX, posY, posZ);
return betterTextureState;
}
for (int[] offset : OFFSETS_ORDERED) {
betterTextureState = blockCacheArray[stateCache.getIndex(
relativePosX + offset[0] + cacheAddX,
relativePosY + offset[1] + cacheAddY,
relativePosZ + offset[2] + cacheAddZ
)];
if (isStateSnow(betterTextureState)) {
texturePooledMutablePos.setPos(posX + offset[0], posY + offset[1], posZ + offset[2]);
return betterTextureState;
}
}
}
}
if (tryForBetterTexturesGrass) {
try (final ModProfiler ignored = ModProfiler.get().start("getTexturePosAndState-tryForBetterTextures-grass")) {
IBlockState betterTextureState = blockCacheArray[stateCache.getIndex(
relativePosX + cacheAddX,
relativePosY + cacheAddY,
relativePosZ + cacheAddZ
)];

if (isStateGrass(betterTextureState)) {
texturePooledMutablePos.setPos(posX, posY, posZ);
return betterTextureState;
}
for (int[] offset : OFFSETS_ORDERED) {
betterTextureState = blockCacheArray[stateCache.getIndex(
relativePosX + offset[0] + cacheAddX,
relativePosY + offset[1] + cacheAddY,
relativePosZ + offset[2] + cacheAddZ
)];
if (isStateGrass(betterTextureState)) {
texturePooledMutablePos.setPos(posX + offset[0], posY + offset[1], posZ + offset[2]);
return betterTextureState;
}
}
}
}
}

final int posX = texturePooledMutablePos.getX();
final int posY = texturePooledMutablePos.getY();
final int posZ = texturePooledMutablePos.getZ();
try (final ModProfiler ignored = ModProfiler.get().start("getTexturePosAndState")) {

final IBlockState[] blockCacheArray = stateCache.getBlockStates();
// If pos passed in is smoothable return state from that pos
if (smoothableCacheArray[smoothableCache.getIndex(
relativePosX + cacheAddX,
relativePosY + cacheAddY,
relativePosZ + cacheAddZ
)]) {
texturePooledMutablePos.setPos(posX, posY, posZ);
return blockCacheArray[stateCache.getIndex(
relativePosX + cacheAddX,
relativePosY + cacheAddY,
relativePosZ + cacheAddZ
)];
}

IBlockState textureState = state;
// Start at state of pos passed in
IBlockState state = blockCacheArray[stateCache.getIndex(
relativePosX + cacheAddX,
relativePosY + cacheAddY,
relativePosZ + cacheAddZ
)];

// int[][] offsets = OFFSETS_ORDERED;
for (int[] offset : OFFSETS_ORDERED) {
final IBlockState tempState = blockCacheArray[stateCache.getIndex(
relativePosX + offset[0] + 2,
relativePosY + offset[1] + 2,
relativePosZ + offset[2] + 2
)];
if (isStateSmoothable.apply(tempState)) {
if (smoothableCacheArray[smoothableCache.getIndex(
relativePosX + offset[0] + cacheAddX,
relativePosY + offset[1] + cacheAddY,
relativePosZ + offset[2] + cacheAddZ
)]) {
texturePooledMutablePos.setPos(posX + offset[0], posY + offset[1], posZ + offset[2]);
textureState = tempState;
state = blockCacheArray[stateCache.getIndex(
relativePosX + offset[0] + cacheAddX,
relativePosY + offset[1] + cacheAddY,
relativePosZ + offset[2] + cacheAddZ
)];
break;
}
}

return new Tuple<>(
texturePooledMutablePos.toImmutable(),
textureState
);
return state;
}
}

private static boolean isStateSnow(final IBlockState betterTextureState) {
if (betterTextureState == SNOW.getDefaultState()) return true;
if (betterTextureState == GRASS_BLOCK.getDefaultState().with(BlockDirtSnowy.SNOWY, true)) return true;
if (betterTextureState == PODZOL.getDefaultState().with(BlockDirtSnowy.SNOWY, true)) return true;
return false;
}

private static boolean isStateGrass(final IBlockState betterTextureState) {
return betterTextureState == GRASS_BLOCK.getDefaultState();
}

@Nonnull
public static BlockRenderLayer getCorrectRenderLayer(@Nonnull final IBlockState state) {
return getCorrectRenderLayer(state.getBlock().getRenderLayer());
Expand Down
Loading

0 comments on commit 1ae69ea

Please sign in to comment.