diff --git a/gradle.properties b/gradle.properties index 92c54705..bcf49936 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/io/github/cadiboo/nocubes/NoCubes.java b/src/main/java/io/github/cadiboo/nocubes/NoCubes.java index 8d521990..157a14bb 100644 --- a/src/main/java/io/github/cadiboo/nocubes/NoCubes.java +++ b/src/main/java/io/github/cadiboo/nocubes/NoCubes.java @@ -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; diff --git a/src/main/java/io/github/cadiboo/nocubes/client/ClientEventSubscriber.java b/src/main/java/io/github/cadiboo/nocubes/client/ClientEventSubscriber.java index 24ff6843..aedd1b21 100644 --- a/src/main/java/io/github/cadiboo/nocubes/client/ClientEventSubscriber.java +++ b/src/main/java/io/github/cadiboo/nocubes/client/ClientEventSubscriber.java @@ -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; @@ -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; @@ -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; @@ -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) { @@ -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; @@ -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) { diff --git a/src/main/java/io/github/cadiboo/nocubes/client/ClientProxy.java b/src/main/java/io/github/cadiboo/nocubes/client/ClientProxy.java index 079af9a6..aaf11f72 100644 --- a/src/main/java/io/github/cadiboo/nocubes/client/ClientProxy.java +++ b/src/main/java/io/github/cadiboo/nocubes/client/ClientProxy.java @@ -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 @@ -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; diff --git a/src/main/java/io/github/cadiboo/nocubes/client/ClientUtil.java b/src/main/java/io/github/cadiboo/nocubes/client/ClientUtil.java index 2371a011..8d1e0e8d 100644 --- a/src/main/java/io/github/cadiboo/nocubes/client/ClientUtil.java +++ b/src/main/java/io/github/cadiboo/nocubes/client/ClientUtil.java @@ -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; @@ -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; @@ -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; @@ -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 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()); diff --git a/src/main/java/io/github/cadiboo/nocubes/client/UVHelper.java b/src/main/java/io/github/cadiboo/nocubes/client/UVHelper.java index a21fad90..be7b7e31 100644 --- a/src/main/java/io/github/cadiboo/nocubes/client/UVHelper.java +++ b/src/main/java/io/github/cadiboo/nocubes/client/UVHelper.java @@ -11,43 +11,77 @@ public final class UVHelper { public static final float UV_CORRECT = 1 / 10000F; /** - * Gets the fixed minimum U coordinate to use when rendering the sprite. + * Gets the corrected minimum U coordinate to use when rendering the sprite. * * @param sprite the sprite - * @return The fixed minimum U coordinate to use when rendering the sprite + * @return The corrected minimum U coordinate to use when rendering the sprite */ public static float getMinU(final TextureAtlasSprite sprite) { return sprite.getMinU() + UV_CORRECT; } /** - * Gets the fixed maximum U coordinate to use when rendering the sprite. + * Gets the corrected maximum U coordinate to use when rendering the sprite. * * @param sprite the sprite - * @return The fixed maximum U coordinate to use when rendering the sprite + * @return The corrected maximum U coordinate to use when rendering the sprite */ public static float getMaxU(final TextureAtlasSprite sprite) { return sprite.getMaxU() - UV_CORRECT; } /** - * Gets the fixed minimum V coordinate to use when rendering the sprite. + * Gets the corrected minimum V coordinate to use when rendering the sprite. * * @param sprite the sprite - * @return The fixed minimum V coordinate to use when rendering the sprite + * @return The corrected minimum V coordinate to use when rendering the sprite */ public static float getMinV(final TextureAtlasSprite sprite) { return sprite.getMinV() + UV_CORRECT; } /** - * Gets the fixed maximum V coordinate to use when rendering the sprite. + * Gets the corrected maximum V coordinate to use when rendering the sprite. * * @param sprite the sprite - * @return The fixed maximum V coordinate to use when rendering the sprite + * @return The corrected maximum V coordinate to use when rendering the sprite */ public static float getMaxV(final TextureAtlasSprite sprite) { return sprite.getMaxV() - UV_CORRECT; } + /** + * Clamps the given u value between the corrected minU and the corrected maxU + * + * @param u the u value to clamp + * @param sprite the sprite + * @return The corrected U coordinate to use when rendering the sprite + */ + public static float clampU(final float u, final TextureAtlasSprite sprite) { + float min = getMinU(sprite); + float max = getMaxU(sprite); + if (u < min) { + return min; + } else { + return u > max ? max : u; + } + } + + /** + * Clamps the given v value between the corrected minV and the corrected maxV + * + * @param v the v value to clamp + * @param sprite the sprite + * @return The corrected V coordinate to use when rendering the sprite + */ + public static float clampV(final float v, final TextureAtlasSprite sprite) { + float min = getMinV(sprite); + float max = getMaxV(sprite); + if (v < min) { + return min; + } else { + return v > max ? max : v; + } + } + } diff --git a/src/main/java/io/github/cadiboo/nocubes/client/render/ExtendedLiquidBlockRenderer.java b/src/main/java/io/github/cadiboo/nocubes/client/render/ExtendedFluidBlockRenderer.java similarity index 97% rename from src/main/java/io/github/cadiboo/nocubes/client/render/ExtendedLiquidBlockRenderer.java rename to src/main/java/io/github/cadiboo/nocubes/client/render/ExtendedFluidBlockRenderer.java index 512c4772..f87960cc 100644 --- a/src/main/java/io/github/cadiboo/nocubes/client/render/ExtendedLiquidBlockRenderer.java +++ b/src/main/java/io/github/cadiboo/nocubes/client/render/ExtendedFluidBlockRenderer.java @@ -23,9 +23,9 @@ /** * @author Cadiboo */ -public final class ExtendedLiquidBlockRenderer { +public final class ExtendedFluidBlockRenderer { - public static boolean renderExtendedLiquid( + public static boolean renderExtendedFluid( final double x, final double y, final double z, @Nonnull final BlockPos fluidPos, @Nonnull final IWorldReader worldIn, @@ -217,7 +217,8 @@ public static boolean renderExtendedLiquid( } } else { - final BlockPos down = renderPos.down(); + // I've fucked up somehow. I shouldn't need to offset this south + final BlockPos down = renderPos.down().south(); final float red0; final float green0; @@ -249,11 +250,13 @@ public static boolean renderExtendedLiquid( red0 = (float) (waterColor0 >> 16 & 0xFF) / 255.0F; green0 = (float) (waterColor0 >> 8 & 0xFF) / 255.0F; blue0 = (float) (waterColor0 & 0xFF) / 255.0F; - final int waterColor1 = BiomeColors.getWaterColor(worldIn, down.south()); + // I've fucked up somehow. I shouldn't need to offset this north, it should be south + final int waterColor1 = BiomeColors.getWaterColor(worldIn, down.north()); red1 = (float) (waterColor1 >> 16 & 0xFF) / 255.0F; green1 = (float) (waterColor1 >> 8 & 0xFF) / 255.0F; blue1 = (float) (waterColor1 & 0xFF) / 255.0F; - final int waterColor2 = BiomeColors.getWaterColor(worldIn, down.east().south()); + // I've fucked up somehow. I shouldn't need to offset this north, it should be south + final int waterColor2 = BiomeColors.getWaterColor(worldIn, down.east().north()); red2 = (float) (waterColor2 >> 16 & 0xFF) / 255.0F; green2 = (float) (waterColor2 >> 8 & 0xFF) / 255.0F; blue2 = (float) (waterColor2 & 0xFF) / 255.0F; diff --git a/src/main/java/io/github/cadiboo/nocubes/client/render/ExtendedLiquidChunkRenderer.java b/src/main/java/io/github/cadiboo/nocubes/client/render/ExtendedFluidChunkRenderer.java similarity index 88% rename from src/main/java/io/github/cadiboo/nocubes/client/render/ExtendedLiquidChunkRenderer.java rename to src/main/java/io/github/cadiboo/nocubes/client/render/ExtendedFluidChunkRenderer.java index 491e16d4..cb269070 100644 --- a/src/main/java/io/github/cadiboo/nocubes/client/render/ExtendedLiquidChunkRenderer.java +++ b/src/main/java/io/github/cadiboo/nocubes/client/render/ExtendedFluidChunkRenderer.java @@ -22,7 +22,7 @@ /** * @author Cadiboo */ -public final class ExtendedLiquidChunkRenderer { +public final class ExtendedFluidChunkRenderer { public static void renderChunk( @Nonnull final RenderChunk renderChunk, @@ -33,7 +33,6 @@ public static void renderChunk( @Nonnull final IWorldReader blockAccess, @Nonnull final BlockPos.PooledMutableBlockPos pooledMutableBlockPos, @Nonnull final boolean[] usedBlockRenderLayers, - @Nonnull final BlockRendererDispatcher blockRendererDispatcher, @Nonnull final StateCache stateCache, @Nonnull final SmoothableCache smoothableCache, @Nonnull final LazyPackedLightCache packedLightCache @@ -44,12 +43,11 @@ public static void renderChunk( final IBlockState[] blockCacheArray = stateCache.getBlockStates(); final IFluidState[] fluidCacheArray = stateCache.getFluidStates(); - final int blockCacheLength = blockCacheArray.length; final int fluidCacheLength = fluidCacheArray.length; - final boolean[] isLiquid = new boolean[fluidCacheLength]; + final boolean[] isFluidSource = new boolean[fluidCacheLength]; for (int i = 0; i < fluidCacheLength; i++) { - isLiquid[i] = fluidCacheArray[i].isSource(); + isFluidSource[i] = fluidCacheArray[i].isSource(); } final boolean[] isSmoothable = smoothableCache.getSmoothableCache(); @@ -71,6 +69,9 @@ public static void renderChunk( if (!isSmoothable[smoothableCache.getIndex(x + cacheAddX, y + cacheAddY, z + cacheAddZ)]) { continue; } + if (!fluidCacheArray[stateCache.getIndex(x + cacheAddX, y + cacheAddY, z + cacheAddZ)].isEmpty()) { + continue; + } OFFSET: for (int xOffset = -maxXOffset; xOffset <= maxXOffset; ++xOffset) { @@ -82,8 +83,8 @@ public static void renderChunk( } // Add 1 or 2 to account for offset=-1 or -2 - final int liquidStateIndex = stateCache.getIndex(x + xOffset + cacheAddX, y + cacheAddY, z + zOffset + cacheAddZ); - if (!isLiquid[liquidStateIndex]) { + final int fluidStateIndex = stateCache.getIndex(x + xOffset + cacheAddX, y + cacheAddY, z + zOffset + cacheAddZ); + if (!isFluidSource[fluidStateIndex]) { continue; } @@ -92,7 +93,7 @@ public static void renderChunk( continue; } - final IFluidState fluidState = fluidCacheArray[liquidStateIndex]; + final IFluidState fluidState = fluidCacheArray[fluidStateIndex]; final BlockRenderLayer blockRenderLayer = ClientUtil.getCorrectRenderLayer(fluidState); final int blockRenderLayerOrdinal = blockRenderLayer.ordinal(); @@ -104,7 +105,7 @@ public static void renderChunk( // renderChunkPositionZ + z // ), blockAccess, bufferBuilder); - usedBlockRenderLayers[blockRenderLayerOrdinal] |= ExtendedLiquidBlockRenderer.renderExtendedLiquid( + usedBlockRenderLayers[blockRenderLayerOrdinal] |= ExtendedFluidBlockRenderer.renderExtendedFluid( renderChunkPositionX + x, renderChunkPositionY + y, renderChunkPositionZ + z, diff --git a/src/main/java/io/github/cadiboo/nocubes/client/render/MeshRenderer.java b/src/main/java/io/github/cadiboo/nocubes/client/render/MeshRenderer.java index e28e372a..961aeee7 100644 --- a/src/main/java/io/github/cadiboo/nocubes/client/render/MeshRenderer.java +++ b/src/main/java/io/github/cadiboo/nocubes/client/render/MeshRenderer.java @@ -7,7 +7,6 @@ import io.github.cadiboo.nocubes.client.LightmapInfo; import io.github.cadiboo.nocubes.client.ModelHelper; import io.github.cadiboo.nocubes.config.Config; -import io.github.cadiboo.nocubes.util.IsSmoothable; import io.github.cadiboo.nocubes.util.ModProfiler; import io.github.cadiboo.nocubes.util.pooled.Face; import io.github.cadiboo.nocubes.util.pooled.FaceList; @@ -27,7 +26,6 @@ import net.minecraft.crash.ReportedException; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumFacing; -import net.minecraft.util.Tuple; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos.PooledMutableBlockPos; import net.minecraft.world.IWorldReaderBase; @@ -61,11 +59,12 @@ public static void renderMesh( @Nonnull final LazyPackedLightCache pooledPackedLightCache, @Nonnull final LazyBlockColorCache blockColorsCache, @Nonnull final Map chunkData, - @Deprecated @Nonnull final IsSmoothable isSmoothable, @Nonnull final SmoothableCache smoothableCache, + final int cacheAddX, final int cacheAddY, final int cacheAddZ, @Nonnull final PooledMutableBlockPos pooledMutableBlockPos, + @Nonnull final PooledMutableBlockPos texturePooledMutableBlockPos, @Nonnull final boolean[] usedBlockRenderLayers, - final boolean renderOppositeSides + final boolean renderOppositeSides, final boolean tryForBetterTexturesSnow, final boolean tryForBetterTexturesGrass ) { try (final ModProfiler ignored = ModProfiler.get().start("renderMesh")) { @@ -78,8 +77,8 @@ public static void renderMesh( continue; } - ModProfiler.get().end(); - ModProfiler.get().start("prepareRenderFaces"); + ModProfiler.get().end(); // HACKY + ModProfiler.get().start("prepareRenderFaces"); // HACKY final int initialPosX = renderChunkPositionX + pos.x; final int initialPosY = renderChunkPositionY + pos.y; @@ -91,38 +90,35 @@ public static void renderMesh( initialPosZ ); - //TODO use pos? (I've forgotten what this is even about) + //TODO use pos? (I've forgotten what this todo is even about) final byte relativePosX = ClientUtil.getRelativePos(renderChunkPositionX, initialPosX); final byte relativePosY = ClientUtil.getRelativePos(renderChunkPositionY, initialPosY); final byte relativePosZ = ClientUtil.getRelativePos(renderChunkPositionZ, initialPosZ); - final IBlockState realState = stateCache.getBlockStates()[stateCache.getIndex( - relativePosX + 2, - relativePosY + 2, - relativePosZ + 2 - )]; -// if (blockAccess.getBlockState(pooledMutableBlockPos) != realState) { -// LogManager.getLogger("Cache Error").error("world blockstate != cache blockstate! (" + initialPosX + ", " + initialPosY + ", " + initialPosZ + "), (" + renderChunkPositionX + relativePosX + ", " + renderChunkPositionY + relativePosY + ", " + renderChunkPositionZ + relativePosZ + ")"); -// } + ModProfiler.get().end(); // HACKY (end here because getTexturePosAndState profiles itself) - ModProfiler.get().end(); - final Tuple texturePosAndState = ClientUtil.getTexturePosAndState(stateCache, pooledMutableBlockPos, realState, isSmoothable, smoothableCache, relativePosX, relativePosY, relativePosZ); - final BlockPos texturePos = texturePosAndState.getA(); - final IBlockState textureState = texturePosAndState.getB(); + final IBlockState textureState = ClientUtil.getTexturePosAndState( + initialPosX, initialPosY, initialPosZ, + texturePooledMutableBlockPos, + stateCache, smoothableCache, + cacheAddX, cacheAddY, cacheAddZ, + relativePosX, relativePosY, relativePosZ, + tryForBetterTexturesSnow, tryForBetterTexturesGrass + ); - ModProfiler.get().start("renderMesh"); + ModProfiler.get().start("renderMesh"); // HACKY try { - renderFaces(renderChunk, generator, compiledChunk, renderChunkPosition, renderChunkPositionX, renderChunkPositionY, renderChunkPositionZ, blockAccess, blockRendererDispatcher, random, usedBlockRenderLayers, pooledPackedLightCache, blockColorsCache, renderOppositeSides, pos, faces, texturePos, textureState); + renderFaces(renderChunk, generator, compiledChunk, renderChunkPosition, renderChunkPositionX, renderChunkPositionY, renderChunkPositionZ, blockAccess, blockRendererDispatcher, random, usedBlockRenderLayers, pooledPackedLightCache, blockColorsCache, renderOppositeSides, pos, faces, texturePooledMutableBlockPos, textureState); } catch (Exception e) { final CrashReport crashReport = new CrashReport("Rendering faces for smooth block in world", e); CrashReportCategory realBlockCrashReportCategory = crashReport.makeCategory("Block being rendered"); final BlockPos blockPos = new BlockPos(renderChunkPositionX + pos.x, renderChunkPositionX + pos.y, renderChunkPositionX + pos.z); - CrashReportCategory.addBlockInfo(realBlockCrashReportCategory, blockPos, realState); + CrashReportCategory.addBlockInfo(realBlockCrashReportCategory, blockPos, blockAccess.getBlockState(new BlockPos(pooledMutableBlockPos.setPos(initialPosX, initialPosY, initialPosZ)))); CrashReportCategory textureBlockCrashReportCategory = crashReport.makeCategory("TextureBlock of Block being rendered"); - CrashReportCategory.addBlockInfo(textureBlockCrashReportCategory, texturePos, textureState); + CrashReportCategory.addBlockInfo(textureBlockCrashReportCategory, texturePooledMutableBlockPos, textureState); throw new ReportedException(crashReport); } diff --git a/src/main/java/io/github/cadiboo/nocubes/client/render/RenderDispatcher.java b/src/main/java/io/github/cadiboo/nocubes/client/render/RenderDispatcher.java index b9007145..c893c67f 100644 --- a/src/main/java/io/github/cadiboo/nocubes/client/render/RenderDispatcher.java +++ b/src/main/java/io/github/cadiboo/nocubes/client/render/RenderDispatcher.java @@ -144,6 +144,39 @@ private static void renderChunk( return; } try (LazyPackedLightCache packedLightCache = ClientCacheUtil.generatePackedLightCache(renderChunkPositionX, renderChunkPositionY, renderChunkPositionZ, stateCache, blockAccess)) { + + if (Config.renderExtendedFluids) { + try ( + final ModProfiler ignored = ModProfiler.get().start("extendFluids"); + SmoothableCache smoothableCache = CacheUtil.generateSmoothableCache( + stateCache, + (state) -> + TERRAIN_SMOOTHABLE.apply(state) || LEAVES_SMOOTHABLE.apply(state) + ) + ) { + try { + ExtendedFluidChunkRenderer.renderChunk( + renderChunk, + generator, + compiledChunk, + renderChunkPosition, + renderChunkPositionX, renderChunkPositionY, renderChunkPositionZ, + blockAccess, + pooledMutableBlockPos, + usedBlockRenderLayers, + stateCache, smoothableCache, + packedLightCache + ); + } catch (ReportedException e) { + throw e; + } catch (Exception e) { + CrashReport crashReport = new CrashReport("Error rendering extended fluids!", e); + crashReport.makeCategory("Rendering extended fluids"); + throw new ReportedException(crashReport); + } + } + } + try { if (Config.renderSmoothTerrain) { renderTerrain(renderChunk, generator, compiledChunk, renderChunkPosition, renderChunkPositionX, renderChunkPositionY, renderChunkPositionZ, blockAccess, stateCache, pooledMutableBlockPos, usedBlockRenderLayers, blockRendererDispatcher, random, packedLightCache); @@ -159,40 +192,6 @@ private static void renderChunk( throw new ReportedException(crashReport); } - if (!Config.renderExtendedFluids) { - return; - } - try ( - final ModProfiler ignored = ModProfiler.get().start("extendFluids"); - SmoothableCache smoothableCache = CacheUtil.generateSmoothableCache( - stateCache, - (state) -> - TERRAIN_SMOOTHABLE.apply(state) || LEAVES_SMOOTHABLE.apply(state) - ) - ) { - try { - ExtendedLiquidChunkRenderer.renderChunk( - renderChunk, - generator, - compiledChunk, - renderChunkPosition, - renderChunkPositionX, renderChunkPositionY, renderChunkPositionZ, - blockAccess, - pooledMutableBlockPos, - usedBlockRenderLayers, - blockRendererDispatcher, - stateCache, smoothableCache, - packedLightCache - ); - } catch (ReportedException e) { - throw e; - } catch (Exception e) { - CrashReport crashReport = new CrashReport("Error rendering extended fluids!", e); - crashReport.makeCategory("Rendering extended fluids"); - throw new ReportedException(crashReport); - } - } - } } @@ -213,7 +212,10 @@ private static void renderLeaves( if (Config.getLeavesSmoothableBlocks().isEmpty()) { return; } - try (LazyBlockColorCache blockColorsCache = ClientCacheUtil.generateLazyBlockColorCache(renderChunkPositionX, renderChunkPositionY, renderChunkPositionZ, blockAccess, BiomeColors.FOLIAGE_COLOR)) { + try ( + LazyBlockColorCache blockColorsCache = ClientCacheUtil.generateLazyBlockColorCache(renderChunkPositionX, renderChunkPositionY, renderChunkPositionZ, blockAccess, BiomeColors.FOLIAGE_COLOR); + PooledMutableBlockPos texturePooledMutableBlockPos = PooledMutableBlockPos.retain() + ) { switch (Config.smoothLeavesType) { case SEPARATE: for (final Block smoothableBlock : Config.getLeavesSmoothableBlocks()) { @@ -242,9 +244,11 @@ private static void renderLeaves( isSmoothable, Config.leavesMeshGenerator ), - isSmoothable, //TODO: remove? textureSmoothableCache, - pooledMutableBlockPos, usedBlockRenderLayers, true + // state cache begins at -2 and density cache expects 0 + 2, 2, 2, + pooledMutableBlockPos, texturePooledMutableBlockPos, usedBlockRenderLayers, + true, true, false ); } } @@ -275,9 +279,11 @@ private static void renderLeaves( isSmoothable, Config.leavesMeshGenerator ), - isSmoothable, //TODO: remove? textureSmoothableCache, - pooledMutableBlockPos, usedBlockRenderLayers, true + // state cache begins at -2 and density cache expects 0 + 2, 2, 2, + pooledMutableBlockPos, texturePooledMutableBlockPos, usedBlockRenderLayers, + true, true, false ); } break; @@ -302,8 +308,9 @@ private static void renderTerrain( @Nonnull final LazyPackedLightCache pooledPackedLightCache ) { try ( - final SmoothableCache smoothableCache = CacheUtil.generateSmoothableCache(stateCache, IsSmoothable.TERRAIN_SMOOTHABLE); - final LazyBlockColorCache blockColorsCache = ClientCacheUtil.generateLazyBlockColorCache(renderChunkPositionX, renderChunkPositionY, renderChunkPositionZ, blockAccess, BiomeColors.GRASS_COLOR) + SmoothableCache smoothableCache = CacheUtil.generateSmoothableCache(stateCache, IsSmoothable.TERRAIN_SMOOTHABLE); + LazyBlockColorCache blockColorsCache = ClientCacheUtil.generateLazyBlockColorCache(renderChunkPositionX, renderChunkPositionY, renderChunkPositionZ, blockAccess, BiomeColors.GRASS_COLOR); + PooledMutableBlockPos texturePooledMutableBlockPos = PooledMutableBlockPos.retain() ) { MeshRenderer.renderMesh( renderChunk, @@ -324,9 +331,11 @@ private static void renderTerrain( TERRAIN_SMOOTHABLE, Config.terrainMeshGenerator ), - TERRAIN_SMOOTHABLE, //TODO: remove? smoothableCache, - pooledMutableBlockPos, usedBlockRenderLayers, false + // state cache begins at -2 and density cache expects 0 + 2, 2, 2, + pooledMutableBlockPos, texturePooledMutableBlockPos, usedBlockRenderLayers, + false, true, true ); } } diff --git a/src/main/java/io/github/cadiboo/nocubes/client/render/SmoothLightingBlockFluidRenderer.java b/src/main/java/io/github/cadiboo/nocubes/client/render/SmoothLightingBlockFluidRenderer.java index bc9ca001..9e76ce6b 100644 --- a/src/main/java/io/github/cadiboo/nocubes/client/render/SmoothLightingBlockFluidRenderer.java +++ b/src/main/java/io/github/cadiboo/nocubes/client/render/SmoothLightingBlockFluidRenderer.java @@ -505,7 +505,7 @@ public float getFluidHeight(IWorldReaderBase reader, BlockPos pos, Fluid fluidIn } public boolean renderUp( - final BufferBuilder buffer, final TextureAtlasSprite[] atextureatlassprite, + final BufferBuilder buffer, final TextureAtlasSprite[] sprites, final float red0, final float green0, final float blue0, final float red1, final float green1, final float blue1, final float red2, final float green2, final float blue2, @@ -524,37 +524,37 @@ public boolean renderUp( float v2; float v3; if (flowVec.x == 0.0D && flowVec.z == 0.0D) { - TextureAtlasSprite textureatlassprite1 = atextureatlassprite[0]; + TextureAtlasSprite stillSprite = sprites[0]; if (textures()) { final int rand = (int) (positionRandom % 7); switch (rand) { default: case 0: - u0 = UVHelper.getMinU(textureatlassprite1); - v0 = UVHelper.getMinV(textureatlassprite1); - v1 = UVHelper.getMaxV(textureatlassprite1); - u2 = UVHelper.getMaxU(textureatlassprite1); + u0 = UVHelper.getMinU(stillSprite); + v0 = UVHelper.getMinV(stillSprite); + v1 = UVHelper.getMaxV(stillSprite); + u2 = UVHelper.getMaxU(stillSprite); break; case 1: case 2: - u0 = UVHelper.getMaxU(textureatlassprite1); - v0 = UVHelper.getMaxV(textureatlassprite1); - v1 = UVHelper.getMinV(textureatlassprite1); - u2 = UVHelper.getMinU(textureatlassprite1); + u0 = UVHelper.getMaxU(stillSprite); + v0 = UVHelper.getMaxV(stillSprite); + v1 = UVHelper.getMinV(stillSprite); + u2 = UVHelper.getMinU(stillSprite); break; case 3: case 4: - u0 = UVHelper.getMinU(textureatlassprite1); - v0 = UVHelper.getMinV(textureatlassprite1); - v1 = UVHelper.getMaxV(textureatlassprite1); - u2 = UVHelper.getMaxU(textureatlassprite1); + u0 = UVHelper.getMinU(stillSprite); + v0 = UVHelper.getMinV(stillSprite); + v1 = UVHelper.getMaxV(stillSprite); + u2 = UVHelper.getMaxU(stillSprite); break; case 5: case 6: - u0 = UVHelper.getMaxU(textureatlassprite1); - v0 = UVHelper.getMaxV(textureatlassprite1); - v1 = UVHelper.getMinV(textureatlassprite1); - u2 = UVHelper.getMinU(textureatlassprite1); + u0 = UVHelper.getMaxU(stillSprite); + v0 = UVHelper.getMaxV(stillSprite); + v1 = UVHelper.getMinV(stillSprite); + u2 = UVHelper.getMinU(stillSprite); break; } u1 = u0; @@ -562,28 +562,28 @@ public boolean renderUp( u3 = u2; v3 = v0; } else { - u0 = UVHelper.getMinU(textureatlassprite1); - v0 = UVHelper.getMinV(textureatlassprite1); + u0 = UVHelper.getMinU(stillSprite); + v0 = UVHelper.getMinV(stillSprite); u1 = u0; - v1 = UVHelper.getMaxV(textureatlassprite1); - u2 = UVHelper.getMaxU(textureatlassprite1); + v1 = UVHelper.getMaxV(stillSprite); + u2 = UVHelper.getMaxU(stillSprite); v2 = v1; u3 = u2; v3 = v0; } } else { - TextureAtlasSprite textureatlassprite = atextureatlassprite[1]; + TextureAtlasSprite flowingSprite = sprites[1]; float magicAtan2Flow = (float) MathHelper.atan2(flowVec.z, flowVec.x) - ((float) Math.PI / 2F); float sinMagicAtan2Flow = MathHelper.sin(magicAtan2Flow) * 0.25F; float cosMagicAtan2Flow = MathHelper.cos(magicAtan2Flow) * 0.25F; - u0 = textureatlassprite.getInterpolatedU((double) (8.0F + (-cosMagicAtan2Flow - sinMagicAtan2Flow) * 16.0F)); - v0 = textureatlassprite.getInterpolatedV((double) (8.0F + (-cosMagicAtan2Flow + sinMagicAtan2Flow) * 16.0F)); - u1 = textureatlassprite.getInterpolatedU((double) (8.0F + (-cosMagicAtan2Flow + sinMagicAtan2Flow) * 16.0F)); - v1 = textureatlassprite.getInterpolatedV((double) (8.0F + (cosMagicAtan2Flow + sinMagicAtan2Flow) * 16.0F)); - u2 = textureatlassprite.getInterpolatedU((double) (8.0F + (cosMagicAtan2Flow + sinMagicAtan2Flow) * 16.0F)); - v2 = textureatlassprite.getInterpolatedV((double) (8.0F + (cosMagicAtan2Flow - sinMagicAtan2Flow) * 16.0F)); - u3 = textureatlassprite.getInterpolatedU((double) (8.0F + (cosMagicAtan2Flow - sinMagicAtan2Flow) * 16.0F)); - v3 = textureatlassprite.getInterpolatedV((double) (8.0F + (-cosMagicAtan2Flow - sinMagicAtan2Flow) * 16.0F)); + u0 = UVHelper.clampU(flowingSprite.getInterpolatedU((double) (8.0F + (-cosMagicAtan2Flow - sinMagicAtan2Flow) * 16.0F)), flowingSprite); + v0 = UVHelper.clampV(flowingSprite.getInterpolatedV((double) (8.0F + (-cosMagicAtan2Flow + sinMagicAtan2Flow) * 16.0F)), flowingSprite); + u1 = UVHelper.clampU(flowingSprite.getInterpolatedU((double) (8.0F + (-cosMagicAtan2Flow + sinMagicAtan2Flow) * 16.0F)), flowingSprite); + v1 = UVHelper.clampV(flowingSprite.getInterpolatedV((double) (8.0F + (cosMagicAtan2Flow + sinMagicAtan2Flow) * 16.0F)), flowingSprite); + u2 = UVHelper.clampU(flowingSprite.getInterpolatedU((double) (8.0F + (cosMagicAtan2Flow + sinMagicAtan2Flow) * 16.0F)), flowingSprite); + v2 = UVHelper.clampV(flowingSprite.getInterpolatedV((double) (8.0F + (cosMagicAtan2Flow - sinMagicAtan2Flow) * 16.0F)), flowingSprite); + u3 = UVHelper.clampU(flowingSprite.getInterpolatedU((double) (8.0F + (cosMagicAtan2Flow - sinMagicAtan2Flow) * 16.0F)), flowingSprite); + v3 = UVHelper.clampV(flowingSprite.getInterpolatedV((double) (8.0F + (-cosMagicAtan2Flow - sinMagicAtan2Flow) * 16.0F)), flowingSprite); } final int skyLight0 = combinedLightUpMax0 >> 16 & '\uffff'; @@ -622,8 +622,8 @@ public boolean renderSide( ) { final float u0 = UVHelper.getMinU(textureatlassprite); final float u1 = textureatlassprite.getInterpolatedU(8.0D); - final float v0 = textureatlassprite.getInterpolatedV((double) ((1.0F - y0) * 16.0F * 0.5F)); - final float v1 = textureatlassprite.getInterpolatedV((double) ((1.0F - y1) * 16.0F * 0.5F)); + final float v0 = UVHelper.clampV(textureatlassprite.getInterpolatedV((double) ((1.0F - y0) * 16.0F * 0.5F)), textureatlassprite); + final float v1 = UVHelper.clampV(textureatlassprite.getInterpolatedV((double) ((1.0F - y1) * 16.0F * 0.5F)), textureatlassprite); final float v2 = textureatlassprite.getInterpolatedV(8.0D); final int skyLight0 = combinedLightUpMax0 >> 16 & '\uffff'; diff --git a/src/main/java/io/github/cadiboo/nocubes/collision/CollisionHandler.java b/src/main/java/io/github/cadiboo/nocubes/collision/CollisionHandler.java index ac829625..1131afe3 100644 --- a/src/main/java/io/github/cadiboo/nocubes/collision/CollisionHandler.java +++ b/src/main/java/io/github/cadiboo/nocubes/collision/CollisionHandler.java @@ -14,10 +14,12 @@ import io.github.cadiboo.nocubes.util.pooled.cache.SmoothableCache; import io.github.cadiboo.nocubes.util.pooled.cache.StateCache; import net.minecraft.block.state.IBlockState; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos.PooledMutableBlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.shapes.IBooleanFunction; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapeInt; @@ -35,6 +37,7 @@ import java.util.stream.StreamSupport; import static io.github.cadiboo.nocubes.util.IsSmoothable.TERRAIN_SMOOTHABLE; +import static net.minecraft.util.EnumFacing.Axis; import static net.minecraft.util.math.MathHelper.clamp; /** @@ -42,7 +45,7 @@ */ public final class CollisionHandler { - public static Stream getCollisionBoxes(final IWorldReaderBase iWorldReaderBase, final VoxelShape area, final VoxelShape entityShape, final boolean isEntityInsideWorldBorder, final int minXm1, final int maxXp1, final int minYm1, final int maxYp1, final int minZm1, final int maxZp1, final WorldBorder worldborder, final boolean isAreaInsideWorldBorder, final VoxelShapePart voxelshapepart, final Predicate predicate) { + public static Stream getCollisionShapes(final IWorldReaderBase iWorldReaderBase, final VoxelShape area, final VoxelShape entityShape, final boolean isEntityInsideWorldBorder, final int minXm1, final int maxXp1, final int minYm1, final int maxYp1, final int minZm1, final int maxZp1, final WorldBorder worldborder, final boolean isAreaInsideWorldBorder, final VoxelShapePart voxelshapepart, final Predicate predicate) { // Density calculation needs -1 on all axis final int additionalSizeNegX = 1; @@ -71,7 +74,7 @@ public static Stream getCollisionBoxes(final IWorldReaderBase iWorld PooledMutableBlockPos pooledMutableBlockPos = PooledMutableBlockPos.retain(); StateCache stateCache = CacheUtil.generateStateCache( startPosX, startPosY, startPosZ, - sizeX , sizeY , sizeZ , + sizeX, sizeY, sizeZ, iWorldReaderBase, pooledMutableBlockPos ); SmoothableCache smoothableCache = CacheUtil.generateSmoothableCache(stateCache, TERRAIN_SMOOTHABLE); @@ -106,18 +109,22 @@ public static Stream getCollisionBoxes(final IWorldReaderBase iWorld final Vec3 v2 = face.getVertex2(); final Vec3 v3 = face.getVertex3() ) { - final int relativeX = clamp(roundAvg(v0.x, v1.x, v2.x, v3.x), startPosX, startPosX + sizeX); - final int relativeY = clamp(roundAvg(v0.y, v1.y, v2.y, v3.y), startPosY, startPosY + sizeY); - final int relativeZ = clamp(roundAvg(v0.z, v1.z, v2.z, v3.z), startPosZ, startPosZ + sizeZ); + // Snap collision VoxelShapes max Y to max Y VoxelShapes of original block at pos if smaller than original + // To stop players falling down through the world when they enable collisions + // (Only works on flat or near-flat surfaces) + //TODO: remove + final int approximateX = clamp(floorAvg(v0.x, v1.x, v2.x, v3.x), startPosX, startPosX + sizeX); + final int approximateY = clamp(floorAvg(v0.y - 0.5, v1.y - 0.5, v2.y - 0.5, v3.y - 0.5), startPosY, startPosY + sizeY); + final int approximateZ = clamp(floorAvg(v0.z, v1.z, v2.z, v3.z), startPosZ, startPosZ + sizeZ); final IBlockState state = stateCache.getBlockStates()[stateCache.getIndex( - relativeX - startPosX, - relativeY - startPosY, - relativeZ - startPosZ + approximateX - startPosX, + approximateY - startPosY, + approximateZ - startPosZ )]; final VoxelShape originalBoxShape = state.getCollisionShape(iWorldReaderBase, pooledMutableBlockPos.setPos( - relativeX, relativeY, relativeZ + approximateX, approximateY, approximateZ )); - addFaceBoxesToList(tempCollidingShapes, face, profiler, null, 0.125F); + addFaceBoxesToList(tempCollidingShapes, face, profiler, approximateY + originalBoxShape.getEnd(Axis.Y), 0.15F); } face.close(); } @@ -128,7 +135,7 @@ public static Stream getCollisionBoxes(final IWorldReaderBase iWorld return Stream.concat( Stream.concat( - getCollisionBoxesExcludingSmoothable(TERRAIN_SMOOTHABLE, iWorldReaderBase, area, entityShape, isEntityInsideWorldBorder, minXm1, maxXp1, minYm1, maxYp1, minZm1, maxZp1, worldborder, isAreaInsideWorldBorder, voxelshapepart, predicate), + getCollisionShapesExcludingSmoothable(TERRAIN_SMOOTHABLE, iWorldReaderBase, area, entityShape, isEntityInsideWorldBorder, minXm1, maxXp1, minYm1, maxYp1, minZm1, maxZp1, worldborder, isAreaInsideWorldBorder, voxelshapepart, predicate), finalCollidingShapes.stream() ), Stream.generate(() -> new VoxelShapeInt(voxelshapepart, minXm1, minYm1, minZm1)) .limit(1L) @@ -142,12 +149,17 @@ private static int roundAvg(double d0, double d1, double d2, double d3) { return (int) ((Math.round(d0) + Math.round(d1) + Math.round(d2) + Math.round(d3)) / 4D); } + //hmmm + private static int floorAvg(double d0, double d1, double d2, double d3) { + return MathHelper.floor((d0 + d1 + d2 + d3) / 4D); + } + //hmmm private static int average(final double d0, final double d1, final double d2, final double d3) { return (int) ((d0 + d1 + d2 + d3) / 4); } - private static Stream getCollisionBoxesExcludingSmoothable(final IsSmoothable isSmoothable, final IWorldReaderBase iWorldReaderBase, final VoxelShape area, final VoxelShape entityShape, final boolean isEntityInsideWorldBorder, final int i, final int j, final int k, final int l, final int i1, final int j1, final WorldBorder worldborder, final boolean isAreaInsideWorldBorder, final VoxelShapePart voxelshapepart, final Predicate predicate) { + public static Stream getCollisionShapesExcludingSmoothable(@Nullable final IsSmoothable isSmoothable, final IWorldReaderBase iWorldReaderBase, final VoxelShape area, final VoxelShape entityShape, final boolean isEntityInsideWorldBorder, final int i, final int j, final int k, final int l, final int i1, final int j1, final WorldBorder worldborder, final boolean isAreaInsideWorldBorder, final VoxelShapePart voxelshapepart, final Predicate predicate) { return StreamSupport.stream(BlockPos.MutableBlockPos.getAllInBoxMutable(i, k, i1, j - 1, l - 1, j1 - 1).spliterator(), false).map((pos) -> { int k1 = pos.getX(); int l1 = pos.getY(); @@ -162,7 +174,7 @@ private static Stream getCollisionBoxesExcludingSmoothable(final IsS } else { //Added stuff here final IBlockState blockState = iWorldReaderBase.getBlockState(pos); - if (isSmoothable.apply(blockState) || (Config.terrainCollisions && blockState.nocubes_isLeavesSmoothable())) { + if (isSmoothable != null && (isSmoothable.apply(blockState) || (Config.terrainCollisions && blockState.nocubes_isLeavesSmoothable()))) { voxelshape = VoxelShapes.empty(); } else { voxelshape = blockState.getCollisionShape(iWorldReaderBase, pos); @@ -185,7 +197,7 @@ private static Stream getCollisionBoxesExcludingSmoothable(final IsS }).filter(predicate); } - private static void addFaceBoxesToList(final List outBoxes, final Face face, final ModProfiler profiler, final VoxelShape originalBoxOffset, final float boxRadius) { + private static void addFaceBoxesToList(final List outBoxes, final Face face, final ModProfiler profiler, final double maxYLevel, final float boxRadius) { //0___3 //_____ @@ -278,10 +290,10 @@ private static void addFaceBoxesToList(final List outBoxes, final Fa //_____ //_____ //1___2 - final VoxelShape v0box; - final VoxelShape v1box; - final VoxelShape v2box; - final VoxelShape v3box; +// final VoxelShape v0box; +// final VoxelShape v1box; +// final VoxelShape v2box; +// final VoxelShape v3box; //0_*_3 //_____ //*___* @@ -331,14 +343,14 @@ private static void addFaceBoxesToList(final List outBoxes, final Fa // final VoxelShape v1v2v2v3v2v3v3v0v3v0v0v1v0v1v1v2box; try (final ModProfiler ignored = profiler.start("createBoxes")) { - v0box = createVoxelShapeForVertex(v0, boxRadius, originalBoxOffset); - v1box = createVoxelShapeForVertex(v1, boxRadius, originalBoxOffset); - v2box = createVoxelShapeForVertex(v2, boxRadius, originalBoxOffset); - v3box = createVoxelShapeForVertex(v3, boxRadius, originalBoxOffset); - v0v1box = createVoxelShapeForVertex(v0v1, boxRadius, originalBoxOffset); - v1v2box = createVoxelShapeForVertex(v1v2, boxRadius, originalBoxOffset); - v2v3box = createVoxelShapeForVertex(v2v3, boxRadius, originalBoxOffset); - v3v0box = createVoxelShapeForVertex(v3v0, boxRadius, originalBoxOffset); +// v0box = createVoxelShapeForVertex(v0, boxRadius, maxYLevel); +// v1box = createVoxelShapeForVertex(v1, boxRadius, maxYLevel); +// v2box = createVoxelShapeForVertex(v2, boxRadius, maxYLevel); +// v3box = createVoxelShapeForVertex(v3, boxRadius, maxYLevel); + v0v1box = createVoxelShapeForVertex(v0v1, boxRadius, maxYLevel); + v1v2box = createVoxelShapeForVertex(v1v2, boxRadius, maxYLevel); + v2v3box = createVoxelShapeForVertex(v2v3, boxRadius, maxYLevel); + v3v0box = createVoxelShapeForVertex(v3v0, boxRadius, maxYLevel); // v0v1v0box = createVoxelShapeForVertex(v0v1v0, boxRadius, originalBoxOffset); // v0v1v1box = createVoxelShapeForVertex(v0v1v1, boxRadius, originalBoxOffset); // v1v2v1box = createVoxelShapeForVertex(v1v2v1, boxRadius, originalBoxOffset); @@ -347,10 +359,10 @@ private static void addFaceBoxesToList(final List outBoxes, final Fa // v2v3v3box = createVoxelShapeForVertex(v2v3v3, boxRadius, originalBoxOffset); // v3v0v3box = createVoxelShapeForVertex(v3v0v3, boxRadius, originalBoxOffset); // v3v0v0box = createVoxelShapeForVertex(v3v0v0, boxRadius, originalBoxOffset); - v0v1v1v2box = createVoxelShapeForVertex(v0v1v1v2, boxRadius, originalBoxOffset); - v1v2v2v3box = createVoxelShapeForVertex(v1v2v2v3, boxRadius, originalBoxOffset); - v2v3v3v0box = createVoxelShapeForVertex(v2v3v3v0, boxRadius, originalBoxOffset); - v3v0v0v1box = createVoxelShapeForVertex(v3v0v0v1, boxRadius, originalBoxOffset); + v0v1v1v2box = createVoxelShapeForVertex(v0v1v1v2, boxRadius, maxYLevel); + v1v2v2v3box = createVoxelShapeForVertex(v1v2v2v3, boxRadius, maxYLevel); + v2v3v3v0box = createVoxelShapeForVertex(v2v3v3v0, boxRadius, maxYLevel); + v3v0v0v1box = createVoxelShapeForVertex(v3v0v0v1, boxRadius, maxYLevel); // v0v1v1v2v1v2v2v3box = createVoxelShapeForVertex(v0v1v1v2v1v2v2v3, boxRadius, originalBoxOffset); // v1v2v2v3v2v3v3v0box = createVoxelShapeForVertex(v1v2v2v3v2v3v3v0, boxRadius, originalBoxOffset); // v2v3v3v0v3v0v0v1box = createVoxelShapeForVertex(v2v3v3v0v3v0v0v1, boxRadius, originalBoxOffset); @@ -360,10 +372,10 @@ private static void addFaceBoxesToList(final List outBoxes, final Fa } try (final ModProfiler ignored = profiler.start("addBoxes")) { - outBoxes.add(v0box); - outBoxes.add(v1box); - outBoxes.add(v2box); - outBoxes.add(v3box); +// outBoxes.add(v0box); +// outBoxes.add(v1box); +// outBoxes.add(v2box); +// outBoxes.add(v3box); outBoxes.add(v0v1box); outBoxes.add(v1v2box); outBoxes.add(v2v3box); @@ -440,28 +452,32 @@ private static Vec3 interp(final Vec3 v0, final Vec3 v1, final float t) { } - private static VoxelShape createVoxelShapeForVertex(final Vec3 vec3, final float boxRadius, - @Nullable final VoxelShape originalBox) { + private static VoxelShape createVoxelShapeForVertex(final Vec3 vec3, final float boxRadius, final double maxY) { final double vy = vec3.y; final double vx = vec3.x; final double vz = vec3.z; - final boolean originalBoxMaxYGreaterThanVertex = originalBox != null && originalBox.getEnd(EnumFacing.Axis.Y) >= vy; - + final boolean isOverMax = vy + boxRadius > maxY; return VoxelShapes.create( - new AxisAlignedBB( - //min - vx - boxRadius, - originalBoxMaxYGreaterThanVertex ? vy - boxRadius - boxRadius : vy - boxRadius, - vz - boxRadius, - //max - vx + boxRadius, - originalBoxMaxYGreaterThanVertex ? vy : vy + boxRadius, - vz + boxRadius - ) + //min + vx - boxRadius, + isOverMax ? vy - boxRadius - boxRadius : vy - boxRadius, + vz - boxRadius, + //max + vx + boxRadius, + isOverMax ? vy : vy + boxRadius, + vz + boxRadius ); } + public static boolean shouldApplyCollisions(@Nullable final Entity entity) { + if (entity == null) { + return true; + } else { + return entity instanceof EntityItem || entity instanceof EntityLivingBase; + } + } + } diff --git a/src/main/java/io/github/cadiboo/nocubes/config/ClientConfig.java b/src/main/java/io/github/cadiboo/nocubes/config/ClientConfig.java index de4a8a0c..df255f2b 100644 --- a/src/main/java/io/github/cadiboo/nocubes/config/ClientConfig.java +++ b/src/main/java/io/github/cadiboo/nocubes/config/ClientConfig.java @@ -24,6 +24,8 @@ final class ClientConfig { ForgeConfigSpec.BooleanValue applyDiffuseLighting; + ForgeConfigSpec.BooleanValue betterTextures; + ForgeConfigSpec.BooleanValue smoothFluidLighting; ForgeConfigSpec.BooleanValue smoothFluidColors; ForgeConfigSpec.BooleanValue naturalFluidTextures; @@ -42,7 +44,7 @@ final class ClientConfig { leavesSmoothable = builder .comment("leavesSmoothable") // TODO .translation(MOD_ID + ".config.leavesSmoothable") - .defineList("leavesSmoothable", Config.ConfigHelper.getDefaultLeavesSmoothable(), o -> o instanceof String); + .defineList("leavesSmoothable", ConfigHelper.getDefaultLeavesSmoothable(), o -> o instanceof String); leavesMeshGenerator = builder .comment("leavesMeshGenerator") // TODO .translation(MOD_ID + ".config.leavesMeshGenerator") @@ -62,6 +64,11 @@ final class ClientConfig { .translation(MOD_ID + ".config.applyDiffuseLighting") .define("applyDiffuseLighting", true); + betterTextures = builder + .comment("betterTextures") // TODO + .translation(MOD_ID + ".config.betterTextures") + .define("betterTextures", true); + smoothFluidLighting = builder .comment("smoothFluidLighting") // TODO .translation(MOD_ID + ".config.smoothFluidLighting") diff --git a/src/main/java/io/github/cadiboo/nocubes/config/Config.java b/src/main/java/io/github/cadiboo/nocubes/config/Config.java index 197e7af8..8577b762 100644 --- a/src/main/java/io/github/cadiboo/nocubes/config/Config.java +++ b/src/main/java/io/github/cadiboo/nocubes/config/Config.java @@ -1,83 +1,14 @@ package io.github.cadiboo.nocubes.config; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; import io.github.cadiboo.nocubes.mesh.MeshGeneratorType; import io.github.cadiboo.nocubes.util.ExtendFluidsRange; import io.github.cadiboo.nocubes.util.SmoothLeavesType; -import joptsimple.internal.Strings; import net.minecraft.block.Block; -import net.minecraft.block.BlockDirtSnowy; -import net.minecraft.block.BlockMycelium; -import net.minecraft.block.BlockRedstoneOre; -import net.minecraft.block.state.IBlockState; -import net.minecraft.command.arguments.BlockStateArgument; -import net.minecraft.state.IProperty; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.Util; -import net.minecraftforge.fml.config.ModConfig; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.ArrayList; import java.util.HashSet; -import java.util.List; -import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; - -import static net.minecraft.init.Blocks.ACACIA_LEAVES; -import static net.minecraft.init.Blocks.ANDESITE; -import static net.minecraft.init.Blocks.BEDROCK; -import static net.minecraft.init.Blocks.BIRCH_LEAVES; -import static net.minecraft.init.Blocks.BLACK_TERRACOTTA; -import static net.minecraft.init.Blocks.BROWN_TERRACOTTA; -import static net.minecraft.init.Blocks.CLAY; -import static net.minecraft.init.Blocks.COAL_ORE; -import static net.minecraft.init.Blocks.COARSE_DIRT; -import static net.minecraft.init.Blocks.DARK_OAK_LEAVES; -import static net.minecraft.init.Blocks.DIAMOND_ORE; -import static net.minecraft.init.Blocks.DIORITE; -import static net.minecraft.init.Blocks.DIRT; -import static net.minecraft.init.Blocks.EMERALD_ORE; -import static net.minecraft.init.Blocks.END_STONE; -import static net.minecraft.init.Blocks.GLOWSTONE; -import static net.minecraft.init.Blocks.GOLD_ORE; -import static net.minecraft.init.Blocks.GRANITE; -import static net.minecraft.init.Blocks.GRASS_BLOCK; -import static net.minecraft.init.Blocks.GRASS_PATH; -import static net.minecraft.init.Blocks.GRAVEL; -import static net.minecraft.init.Blocks.GRAY_TERRACOTTA; -import static net.minecraft.init.Blocks.INFESTED_STONE; -import static net.minecraft.init.Blocks.IRON_ORE; -import static net.minecraft.init.Blocks.JUNGLE_LEAVES; -import static net.minecraft.init.Blocks.LAPIS_ORE; -import static net.minecraft.init.Blocks.MAGMA_BLOCK; -import static net.minecraft.init.Blocks.MYCELIUM; -import static net.minecraft.init.Blocks.NETHERRACK; -import static net.minecraft.init.Blocks.NETHER_QUARTZ_ORE; -import static net.minecraft.init.Blocks.OAK_LEAVES; -import static net.minecraft.init.Blocks.ORANGE_TERRACOTTA; -import static net.minecraft.init.Blocks.PACKED_ICE; -import static net.minecraft.init.Blocks.PODZOL; -import static net.minecraft.init.Blocks.REDSTONE_ORE; -import static net.minecraft.init.Blocks.RED_SAND; -import static net.minecraft.init.Blocks.RED_SANDSTONE; -import static net.minecraft.init.Blocks.RED_TERRACOTTA; -import static net.minecraft.init.Blocks.SAND; -import static net.minecraft.init.Blocks.SANDSTONE; -import static net.minecraft.init.Blocks.SNOW; -import static net.minecraft.init.Blocks.SOUL_SAND; -import static net.minecraft.init.Blocks.SPRUCE_LEAVES; -import static net.minecraft.init.Blocks.STONE; -import static net.minecraft.init.Blocks.TERRACOTTA; -import static net.minecraft.init.Blocks.WHITE_TERRACOTTA; -import static net.minecraft.init.Blocks.YELLOW_TERRACOTTA; /** * @author Cadiboo @@ -86,7 +17,7 @@ public final class Config { static final Logger LOGGER = LogManager.getLogger(); - private static final HashSet leavesSmoothableBlocks = new HashSet<>(); + static final HashSet leavesSmoothableBlocks = new HashSet<>(); // Client public static boolean renderSmoothTerrain; @@ -99,6 +30,8 @@ public final class Config { public static boolean applyDiffuseLighting; + public static boolean betterTextures; + public static boolean smoothFluidLighting; public static boolean smoothFluidColors; public static boolean naturalFluidTextures; @@ -110,257 +43,10 @@ public final class Config { public static boolean terrainCollisions; public static Set terrainSmoothable; + public static boolean leavesCollisions; + public static HashSet getLeavesSmoothableBlocks() { return leavesSmoothableBlocks; } - public static final class ConfigHelper { - - private static ModConfig clientConfig; - - private static ModConfig serverConfig; - - public static void bakeClient(final ModConfig config) { - clientConfig = config; - - renderSmoothTerrain = ConfigHolder.CLIENT.renderSmoothTerrain.get(); - - renderSmoothLeaves = ConfigHolder.CLIENT.renderSmoothLeaves.get(); - leavesMeshGenerator = ConfigHolder.CLIENT.leavesMeshGenerator.get(); - leavesSmoothable = Sets.newHashSet(ConfigHolder.CLIENT.leavesSmoothable.get()); - initLeavesSmoothable(); - smoothLeavesType = ConfigHolder.CLIENT.smoothLeavesType.get(); - - renderExtendedFluids = ConfigHolder.CLIENT.renderExtendedFluids.get(); - - applyDiffuseLighting = ConfigHolder.CLIENT.applyDiffuseLighting.get(); - - smoothFluidLighting = ConfigHolder.CLIENT.smoothFluidLighting.get(); - smoothFluidColors = ConfigHolder.CLIENT.smoothFluidColors.get(); - naturalFluidTextures = ConfigHolder.CLIENT.naturalFluidTextures.get(); - - } - - public static void bakeServer(final ModConfig config) { - serverConfig = config; - - terrainSmoothable = Sets.newHashSet(ConfigHolder.SERVER.terrainSmoothable.get()); - initTerrainSmoothable(); - - extendFluidsRange = ConfigHolder.SERVER.extendFluidsRange.get(); - - terrainMeshGenerator = ConfigHolder.SERVER.terrainMeshGenerator.get(); - terrainCollisions = ConfigHolder.SERVER.terrainCollisions.get(); - } - - public static void addTerrainSmoothable(final IBlockState... states) { - if (states.length > 0) { - for (final IBlockState state : states) { - LOGGER.debug("Adding terrain smoothable: " + state); - state.nocubes_setTerrainSmoothable(true); - terrainSmoothable.add(getStringFromState(state)); - } - serverConfig.getConfigData().set("general.terrainSmoothable", new ArrayList<>(terrainSmoothable)); - serverConfig.save(); - } - } - - public static void removeTerrainSmoothable(final IBlockState... states) { - if (states.length > 0) { - for (final IBlockState state : states) { - LOGGER.debug("Removing terrain smoothable: " + state); - state.nocubes_setTerrainSmoothable(false); - terrainSmoothable.remove(getStringFromState(state)); - } - serverConfig.getConfigData().set("general.terrainSmoothable", new ArrayList<>(terrainSmoothable)); - serverConfig.save(); - } - } - - public static void addLeavesSmoothable(final IBlockState... states) { - if (states.length > 0) { - synchronized (leavesSmoothableBlocks) { - for (final IBlockState originalState : states) { - final Block block = originalState.getBlock(); - LOGGER.debug("Adding leaves smoothable block: " + block); - for (final IBlockState state : block.getStateContainer().getValidStates()) { - LOGGER.debug("Adding leaves smoothable state: " + state); - state.nocubes_setLeavesSmoothable(true); - } - leavesSmoothable.add(block.getRegistryName().toString()); - leavesSmoothableBlocks.add(block); - } - } - clientConfig.getConfigData().set("general.leavesSmoothable", new ArrayList<>(leavesSmoothable)); - clientConfig.save(); - } - } - - public static void removeLeavesSmoothable(final IBlockState... states) { - if (states.length > 0) { - synchronized (leavesSmoothableBlocks) { - for (final IBlockState originalState : states) { - final Block block = originalState.getBlock(); - LOGGER.debug("Removing leaves smoothable block: " + block); - for (final IBlockState state : block.getStateContainer().getValidStates()) { - LOGGER.debug("Removing leaves smoothable state: " + state); - state.nocubes_setLeavesSmoothable(false); - } - leavesSmoothable.remove(block.getRegistryName().toString()); - leavesSmoothableBlocks.remove(block); - } - } - clientConfig.getConfigData().set("general.leavesSmoothable", new ArrayList<>(leavesSmoothable)); - clientConfig.save(); - } - } - - private static void initTerrainSmoothable() { - LOGGER.debug("Initialising terrain smoothable"); - for (final String stateString : terrainSmoothable) { - LOGGER.debug("Preparing to add \"" + stateString + "\" to terrain smoothable"); - final IBlockState state = getStateFromString(stateString); - if (state != null) { - LOGGER.debug("Added \"" + state + "\" to terrain smoothable"); - state.nocubes_setTerrainSmoothable(true); - } else { - LOGGER.debug("Cannot add invalid state \"" + stateString + "\" to terrain smoothable"); - } - } - } - - private static void initLeavesSmoothable() { - LOGGER.debug("Initialising leaves smoothable"); - for (final String blockString : leavesSmoothable) { - LOGGER.debug("Preparing to add block \"" + blockString + "\" to leaves smoothable"); - final IBlockState defaultState = getStateFromString(blockString); - if (defaultState != null) { - final Block block = defaultState.getBlock(); - LOGGER.debug("Added \"" + defaultState + "\" to leaves smoothable"); - for (final IBlockState state : block.getStateContainer().getValidStates()) { - state.nocubes_setLeavesSmoothable(true); - } - leavesSmoothableBlocks.add(block); - } else { - LOGGER.debug("Cannot add invalid block \"" + blockString + "\" to leaves smoothable"); - } - } - } - - @Nullable - private static IBlockState getStateFromString(@Nonnull final String stateString) { - Preconditions.checkNotNull(stateString, "String to parse must not be null"); - try { - return new BlockStateArgument().parse(new StringReader(stateString)).getState(); - } catch (final CommandSyntaxException e) { - LOGGER.error("Failed to parse blockstate \"" + stateString + "\"!", e); - return null; - } - } - - @Nonnull - private static String getStringFromState(@Nonnull final IBlockState state) { - Preconditions.checkNotNull(state, "String to serialise must not be null"); - String stateString = state.getBlock().getRegistryName().toString(); - final ArrayList properties = new ArrayList<>(); - for (Map.Entry, Comparable> entry : state.getValues().entrySet()) { - final IProperty property = entry.getKey(); - final Comparable value = entry.getValue(); - properties.add(property.getName() + "=" + Util.getValueName(property, value)); - } - if (!properties.isEmpty()) { - stateString += "["; - stateString += Strings.join(properties, ","); - stateString += "]"; - } - return stateString; - } - - @Nonnull - public static List getDefaultTerrainSmoothable() { - return Lists.newArrayList( - - GRASS_BLOCK.getDefaultState().with(BlockDirtSnowy.SNOWY, false), - GRASS_BLOCK.getDefaultState().with(BlockDirtSnowy.SNOWY, true), - - STONE.getDefaultState(), - GRANITE.getDefaultState(), - DIORITE.getDefaultState(), - ANDESITE.getDefaultState(), - - DIRT.getDefaultState(), - COARSE_DIRT.getDefaultState(), - - PODZOL.getDefaultState().with(BlockDirtSnowy.SNOWY, false), - PODZOL.getDefaultState().with(BlockDirtSnowy.SNOWY, true), - - SAND.getDefaultState(), - RED_SAND.getDefaultState(), - - SANDSTONE.getDefaultState(), - - RED_SANDSTONE.getDefaultState(), - - GRAVEL.getDefaultState(), - - COAL_ORE.getDefaultState(), - IRON_ORE.getDefaultState(), - GOLD_ORE.getDefaultState(), - REDSTONE_ORE.getDefaultState().with(BlockRedstoneOre.LIT, false), - REDSTONE_ORE.getDefaultState().with(BlockRedstoneOre.LIT, true), - DIAMOND_ORE.getDefaultState(), - LAPIS_ORE.getDefaultState(), - EMERALD_ORE.getDefaultState(), - NETHER_QUARTZ_ORE.getDefaultState(), - - INFESTED_STONE.getDefaultState(), - - GRASS_PATH.getDefaultState(), - - CLAY.getDefaultState(), - TERRACOTTA.getDefaultState(), - - WHITE_TERRACOTTA.getDefaultState(), - ORANGE_TERRACOTTA.getDefaultState(), - YELLOW_TERRACOTTA.getDefaultState(), - GRAY_TERRACOTTA.getDefaultState(), - BROWN_TERRACOTTA.getDefaultState(), - RED_TERRACOTTA.getDefaultState(), - BLACK_TERRACOTTA.getDefaultState(), - - PACKED_ICE.getDefaultState(), - - SNOW.getDefaultState(), - - BEDROCK.getDefaultState(), - - NETHERRACK.getDefaultState(), - SOUL_SAND.getDefaultState(), - MAGMA_BLOCK.getDefaultState(), - GLOWSTONE.getDefaultState(), - - END_STONE.getDefaultState(), - - MYCELIUM.getDefaultState().with(BlockMycelium.SNOWY, true), - MYCELIUM.getDefaultState().with(BlockMycelium.SNOWY, false) - - ).stream().map(ConfigHelper::getStringFromState).collect(Collectors.toList()); - } - - @Nonnull - public static List getDefaultLeavesSmoothable() { - return Lists.newArrayList( - - OAK_LEAVES, - SPRUCE_LEAVES, - BIRCH_LEAVES, - JUNGLE_LEAVES, - ACACIA_LEAVES, - DARK_OAK_LEAVES - - ).stream().map(Block::getRegistryName).map(ResourceLocation::toString).collect(Collectors.toList()); - } - - } - } diff --git a/src/main/java/io/github/cadiboo/nocubes/config/ConfigHelper.java b/src/main/java/io/github/cadiboo/nocubes/config/ConfigHelper.java new file mode 100644 index 00000000..5f433554 --- /dev/null +++ b/src/main/java/io/github/cadiboo/nocubes/config/ConfigHelper.java @@ -0,0 +1,362 @@ +package io.github.cadiboo.nocubes.config; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import joptsimple.internal.Strings; +import net.minecraft.block.Block; +import net.minecraft.block.BlockDirtSnowy; +import net.minecraft.block.BlockMycelium; +import net.minecraft.block.BlockRedstoneOre; +import net.minecraft.block.state.IBlockState; +import net.minecraft.command.arguments.BlockStateArgument; +import net.minecraft.state.IProperty; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.Util; +import net.minecraftforge.fml.config.ModConfig; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static net.minecraft.init.Blocks.ACACIA_LEAVES; +import static net.minecraft.init.Blocks.ANDESITE; +import static net.minecraft.init.Blocks.BEDROCK; +import static net.minecraft.init.Blocks.BIRCH_LEAVES; +import static net.minecraft.init.Blocks.BLACK_TERRACOTTA; +import static net.minecraft.init.Blocks.BROWN_TERRACOTTA; +import static net.minecraft.init.Blocks.CLAY; +import static net.minecraft.init.Blocks.COAL_ORE; +import static net.minecraft.init.Blocks.COARSE_DIRT; +import static net.minecraft.init.Blocks.DARK_OAK_LEAVES; +import static net.minecraft.init.Blocks.DIAMOND_ORE; +import static net.minecraft.init.Blocks.DIORITE; +import static net.minecraft.init.Blocks.DIRT; +import static net.minecraft.init.Blocks.EMERALD_ORE; +import static net.minecraft.init.Blocks.END_STONE; +import static net.minecraft.init.Blocks.GLOWSTONE; +import static net.minecraft.init.Blocks.GOLD_ORE; +import static net.minecraft.init.Blocks.GRANITE; +import static net.minecraft.init.Blocks.GRASS_BLOCK; +import static net.minecraft.init.Blocks.GRASS_PATH; +import static net.minecraft.init.Blocks.GRAVEL; +import static net.minecraft.init.Blocks.GRAY_TERRACOTTA; +import static net.minecraft.init.Blocks.INFESTED_STONE; +import static net.minecraft.init.Blocks.IRON_ORE; +import static net.minecraft.init.Blocks.JUNGLE_LEAVES; +import static net.minecraft.init.Blocks.LAPIS_ORE; +import static net.minecraft.init.Blocks.MAGMA_BLOCK; +import static net.minecraft.init.Blocks.MYCELIUM; +import static net.minecraft.init.Blocks.NETHERRACK; +import static net.minecraft.init.Blocks.NETHER_QUARTZ_ORE; +import static net.minecraft.init.Blocks.OAK_LEAVES; +import static net.minecraft.init.Blocks.ORANGE_TERRACOTTA; +import static net.minecraft.init.Blocks.PACKED_ICE; +import static net.minecraft.init.Blocks.PODZOL; +import static net.minecraft.init.Blocks.REDSTONE_ORE; +import static net.minecraft.init.Blocks.RED_SAND; +import static net.minecraft.init.Blocks.RED_SANDSTONE; +import static net.minecraft.init.Blocks.RED_TERRACOTTA; +import static net.minecraft.init.Blocks.SAND; +import static net.minecraft.init.Blocks.SANDSTONE; +import static net.minecraft.init.Blocks.SNOW; +import static net.minecraft.init.Blocks.SOUL_SAND; +import static net.minecraft.init.Blocks.SPRUCE_LEAVES; +import static net.minecraft.init.Blocks.STONE; +import static net.minecraft.init.Blocks.TERRACOTTA; +import static net.minecraft.init.Blocks.WHITE_TERRACOTTA; +import static net.minecraft.init.Blocks.YELLOW_TERRACOTTA; + +/** + * @author Cadiboo + */ +public final class ConfigHelper { + + private static ModConfig clientConfig; + + private static ModConfig serverConfig; + + public static void bakeClient(final ModConfig config) { + clientConfig = config; + + Config.renderSmoothTerrain = ConfigHolder.CLIENT.renderSmoothTerrain.get(); + + Config.renderSmoothLeaves = ConfigHolder.CLIENT.renderSmoothLeaves.get(); + Config.leavesMeshGenerator = ConfigHolder.CLIENT.leavesMeshGenerator.get(); + Config.leavesSmoothable = Sets.newHashSet(ConfigHolder.CLIENT.leavesSmoothable.get()); + initLeavesSmoothable(); + Config.smoothLeavesType = ConfigHolder.CLIENT.smoothLeavesType.get(); + + Config.renderExtendedFluids = ConfigHolder.CLIENT.renderExtendedFluids.get(); + + Config.applyDiffuseLighting = ConfigHolder.CLIENT.applyDiffuseLighting.get(); + + Config.betterTextures = ConfigHolder.CLIENT.betterTextures.get(); + + Config.smoothFluidLighting = ConfigHolder.CLIENT.smoothFluidLighting.get(); + Config.smoothFluidColors = ConfigHolder.CLIENT.smoothFluidColors.get(); + Config.naturalFluidTextures = ConfigHolder.CLIENT.naturalFluidTextures.get(); + + } + + public static void bakeServer(final ModConfig config) { + serverConfig = config; + + Config.terrainSmoothable = Sets.newHashSet(ConfigHolder.SERVER.terrainSmoothable.get()); + initTerrainSmoothable(); + + Config.extendFluidsRange = ConfigHolder.SERVER.extendFluidsRange.get(); + + Config.terrainMeshGenerator = ConfigHolder.SERVER.terrainMeshGenerator.get(); + Config.terrainCollisions = ConfigHolder.SERVER.terrainCollisions.get(); + Config.leavesCollisions = ConfigHolder.SERVER.leavesCollisions.get(); + } + + public static void addTerrainSmoothable(final IBlockState... states) { + if (states.length > 0) { + for (final IBlockState state : states) { + Config.LOGGER.debug("Adding terrain smoothable: " + state); + state.nocubes_setTerrainSmoothable(true); + Config.terrainSmoothable.add(getStringFromState(state)); + } + serverConfig.getConfigData().set("general.terrainSmoothable", new ArrayList<>(Config.terrainSmoothable)); + serverConfig.save(); + } + } + + public static void removeTerrainSmoothable(final IBlockState... states) { + if (states.length > 0) { + for (final IBlockState state : states) { + Config.LOGGER.debug("Removing terrain smoothable: " + state); + state.nocubes_setTerrainSmoothable(false); + Config.terrainSmoothable.remove(getStringFromState(state)); + } + serverConfig.getConfigData().set("general.terrainSmoothable", new ArrayList<>(Config.terrainSmoothable)); + serverConfig.save(); + } + } + + public static void addLeavesSmoothable(final IBlockState... states) { + if (states.length > 0) { + synchronized (Config.leavesSmoothableBlocks) { + for (final IBlockState originalState : states) { + final Block block = originalState.getBlock(); + Config.LOGGER.debug("Adding leaves smoothable block: " + block); + for (final IBlockState state : block.getStateContainer().getValidStates()) { + Config.LOGGER.debug("Adding leaves smoothable state: " + state); + state.nocubes_setLeavesSmoothable(true); + } + Config.leavesSmoothable.add(block.getRegistryName().toString()); + Config.leavesSmoothableBlocks.add(block); + } + } + clientConfig.getConfigData().set("general.leavesSmoothable", new ArrayList<>(Config.leavesSmoothable)); + clientConfig.save(); + } + } + + public static void removeLeavesSmoothable(final IBlockState... states) { + if (states.length > 0) { + synchronized (Config.leavesSmoothableBlocks) { + for (final IBlockState originalState : states) { + final Block block = originalState.getBlock(); + Config.LOGGER.debug("Removing leaves smoothable block: " + block); + for (final IBlockState state : block.getStateContainer().getValidStates()) { + Config.LOGGER.debug("Removing leaves smoothable state: " + state); + state.nocubes_setLeavesSmoothable(false); + } + Config.leavesSmoothable.remove(block.getRegistryName().toString()); + Config.leavesSmoothableBlocks.remove(block); + } + } + clientConfig.getConfigData().set("general.leavesSmoothable", new ArrayList<>(Config.leavesSmoothable)); + clientConfig.save(); + } + } + + private static void initTerrainSmoothable() { + Config.LOGGER.debug("Initialising terrain smoothable"); + for (final String stateString : Config.terrainSmoothable) { + Config.LOGGER.debug("Preparing to add \"" + stateString + "\" to terrain smoothable"); + final IBlockState state = getStateFromString(stateString); + if (state != null) { + Config.LOGGER.debug("Added \"" + state + "\" to terrain smoothable"); + state.nocubes_setTerrainSmoothable(true); + } else { + Config.LOGGER.debug("Cannot add invalid state \"" + stateString + "\" to terrain smoothable"); + } + } + } + + private static void initLeavesSmoothable() { + Config.LOGGER.debug("Initialising leaves smoothable"); + for (final String blockString : Config.leavesSmoothable) { + Config.LOGGER.debug("Preparing to add block \"" + blockString + "\" to leaves smoothable"); + final IBlockState defaultState = getStateFromString(blockString); + if (defaultState != null) { + final Block block = defaultState.getBlock(); + Config.LOGGER.debug("Added \"" + defaultState + "\" to leaves smoothable"); + for (final IBlockState state : block.getStateContainer().getValidStates()) { + state.nocubes_setLeavesSmoothable(true); + } + Config.leavesSmoothableBlocks.add(block); + } else { + Config.LOGGER.debug("Cannot add invalid block \"" + blockString + "\" to leaves smoothable"); + } + } + } + + @Nullable + private static IBlockState getStateFromString(@Nonnull final String stateString) { + Preconditions.checkNotNull(stateString, "String to parse must not be null"); + try { + return new BlockStateArgument().parse(new StringReader(stateString)).getState(); + } catch (final CommandSyntaxException e) { + Config.LOGGER.error("Failed to parse blockstate \"" + stateString + "\"!", e); + return null; + } + } + + @Nonnull + private static String getStringFromState(@Nonnull final IBlockState state) { + Preconditions.checkNotNull(state, "String to serialise must not be null"); + String stateString = state.getBlock().getRegistryName().toString(); + final ArrayList properties = new ArrayList<>(); + for (Map.Entry, Comparable> entry : state.getValues().entrySet()) { + final IProperty property = entry.getKey(); + final Comparable value = entry.getValue(); + properties.add(property.getName() + "=" + Util.getValueName(property, value)); + } + if (!properties.isEmpty()) { + stateString += "["; + stateString += Strings.join(properties, ","); + stateString += "]"; + } + return stateString; + } + + @Nonnull + public static List getDefaultTerrainSmoothable() { + final List vanillaStates = Lists.newArrayList( + + GRASS_BLOCK.getDefaultState().with(BlockDirtSnowy.SNOWY, false), + GRASS_BLOCK.getDefaultState().with(BlockDirtSnowy.SNOWY, true), + + STONE.getDefaultState(), + GRANITE.getDefaultState(), + DIORITE.getDefaultState(), + ANDESITE.getDefaultState(), + + DIRT.getDefaultState(), + COARSE_DIRT.getDefaultState(), + + PODZOL.getDefaultState().with(BlockDirtSnowy.SNOWY, false), + PODZOL.getDefaultState().with(BlockDirtSnowy.SNOWY, true), + + SAND.getDefaultState(), + RED_SAND.getDefaultState(), + + SANDSTONE.getDefaultState(), + + RED_SANDSTONE.getDefaultState(), + + GRAVEL.getDefaultState(), + + COAL_ORE.getDefaultState(), + IRON_ORE.getDefaultState(), + GOLD_ORE.getDefaultState(), + REDSTONE_ORE.getDefaultState().with(BlockRedstoneOre.LIT, false), + REDSTONE_ORE.getDefaultState().with(BlockRedstoneOre.LIT, true), + DIAMOND_ORE.getDefaultState(), + LAPIS_ORE.getDefaultState(), + EMERALD_ORE.getDefaultState(), + NETHER_QUARTZ_ORE.getDefaultState(), + + INFESTED_STONE.getDefaultState(), + + GRASS_PATH.getDefaultState(), + + CLAY.getDefaultState(), + TERRACOTTA.getDefaultState(), + + WHITE_TERRACOTTA.getDefaultState(), + ORANGE_TERRACOTTA.getDefaultState(), + YELLOW_TERRACOTTA.getDefaultState(), + GRAY_TERRACOTTA.getDefaultState(), + BROWN_TERRACOTTA.getDefaultState(), + RED_TERRACOTTA.getDefaultState(), + BLACK_TERRACOTTA.getDefaultState(), + + PACKED_ICE.getDefaultState(), + + SNOW.getDefaultState(), + + BEDROCK.getDefaultState(), + + NETHERRACK.getDefaultState(), + SOUL_SAND.getDefaultState(), + MAGMA_BLOCK.getDefaultState(), + GLOWSTONE.getDefaultState(), + + END_STONE.getDefaultState(), + + MYCELIUM.getDefaultState().with(BlockMycelium.SNOWY, true), + MYCELIUM.getDefaultState().with(BlockMycelium.SNOWY, false) + + ).stream().map(ConfigHelper::getStringFromState).collect(Collectors.toList()); + + final List moddedStates = Lists.newArrayList( + + ); + + final ArrayList finalStates = Lists.newArrayList(); + finalStates.addAll(vanillaStates); + finalStates.addAll(moddedStates); + return finalStates; + } + + @Nonnull + public static List getDefaultLeavesSmoothable() { + final List vanillaStates = Lists.newArrayList( + + OAK_LEAVES, + SPRUCE_LEAVES, + BIRCH_LEAVES, + JUNGLE_LEAVES, + ACACIA_LEAVES, + DARK_OAK_LEAVES + + ).stream().map(Block::getRegistryName).map(ResourceLocation::toString).collect(Collectors.toList()); + + final List moddedStates = Lists.newArrayList( + + ); + + final ArrayList finalStates = Lists.newArrayList(); + finalStates.addAll(vanillaStates); + finalStates.addAll(moddedStates); + return finalStates; + } + + public static void enableTerrainCollisions() { + serverConfig.getConfigData().set("general.terrainCollisions", true); + } + + public static void disableTerrainCollisions() { + serverConfig.getConfigData().set("general.terrainCollisions", false); + } + + public static void enableLeavesCollisions() { + serverConfig.getConfigData().set("general.leavesCollisions", true); + } + + public static void disableLeavesCollisions() { + serverConfig.getConfigData().set("general.leavesCollisions", false); + } + +} diff --git a/src/main/java/io/github/cadiboo/nocubes/config/ServerConfig.java b/src/main/java/io/github/cadiboo/nocubes/config/ServerConfig.java index c8639fb6..8380a66a 100644 --- a/src/main/java/io/github/cadiboo/nocubes/config/ServerConfig.java +++ b/src/main/java/io/github/cadiboo/nocubes/config/ServerConfig.java @@ -1,6 +1,5 @@ package io.github.cadiboo.nocubes.config; -import io.github.cadiboo.nocubes.config.Config.ConfigHelper; import io.github.cadiboo.nocubes.mesh.MeshGeneratorType; import io.github.cadiboo.nocubes.util.ExtendFluidsRange; import net.minecraftforge.common.ForgeConfigSpec; @@ -18,6 +17,7 @@ final class ServerConfig { ForgeConfigSpec.ConfigValue extendFluidsRange; ForgeConfigSpec.ConfigValue terrainMeshGenerator; ForgeConfigSpec.BooleanValue terrainCollisions; + ForgeConfigSpec.BooleanValue leavesCollisions; ServerConfig(ForgeConfigSpec.Builder builder) { builder.push("general"); @@ -37,6 +37,10 @@ final class ServerConfig { .comment("terrainCollisions") // TODO .translation(MOD_ID + ".config.terrainCollisions") .define("terrainCollisions", false); + leavesCollisions = builder + .comment("leavesCollisions") // TODO + .translation(MOD_ID + ".config.leavesCollisions") + .define("leavesCollisions", false); builder.pop(); } diff --git a/src/main/java/io/github/cadiboo/nocubes/hooks/Hooks.java b/src/main/java/io/github/cadiboo/nocubes/hooks/Hooks.java index d097cdf7..81d109a8 100644 --- a/src/main/java/io/github/cadiboo/nocubes/hooks/Hooks.java +++ b/src/main/java/io/github/cadiboo/nocubes/hooks/Hooks.java @@ -15,11 +15,15 @@ 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.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.shapes.IBooleanFunction; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapeInt; import net.minecraft.util.math.shapes.VoxelShapePart; +import net.minecraft.util.math.shapes.VoxelShapePartBitSet; import net.minecraft.util.math.shapes.VoxelShapes; import net.minecraft.world.IWorldReaderBase; import net.minecraft.world.World; @@ -34,6 +38,7 @@ /** * @author Cadiboo */ +@SuppressWarnings("WeakerAccess") // Hooks are called with ASM 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) { @@ -52,40 +57,74 @@ public static boolean renderBlockDamage(final Tessellator tessellatorIn, final B } //return all the voxel shapes that entityShape intersects inside area - public static Stream getCollisionBoxes(final IWorldReaderBase iWorldReaderBase, final VoxelShape p_212391_1_, final VoxelShape p_212391_2_, final boolean p_212391_3_, final int i, final int j, final int k, final int l, final int i1, final int j1, final WorldBorder worldborder, final boolean flag, final VoxelShapePart voxelshapepart, final Predicate predicate) { + public static Stream getCollisionShapes(final IWorldReaderBase iWorldReaderBase, final VoxelShape area, final VoxelShape entityShape, final boolean isEntityInsideWorldBorder, final int i, final int j, final int k, final int l, final int i1, final int j1, final WorldBorder worldborder, final boolean flag, final VoxelShapePart voxelshapepart, final Predicate predicate) { try { - return CollisionHandler.getCollisionBoxes(iWorldReaderBase, p_212391_1_, p_212391_2_, p_212391_3_, i, j, k, l, i1, j1, worldborder, flag, voxelshapepart, predicate); - } catch (Exception e) { - Stream stream = StreamSupport.stream(BlockPos.MutableBlockPos.getAllInBoxMutable(i, k, i1, j - 1, l - 1, j1 - 1).spliterator(), false).map((p_212390_12_) -> { - int k1 = p_212390_12_.getX(); - int l1 = p_212390_12_.getY(); - int i2 = p_212390_12_.getZ(); - boolean flag1 = k1 == i || k1 == j - 1; - boolean flag2 = l1 == k || l1 == l - 1; - boolean flag3 = i2 == i1 || i2 == j1 - 1; - if ((!flag1 || !flag2) && (!flag2 || !flag3) && (!flag3 || !flag1) && iWorldReaderBase.isBlockLoaded(p_212390_12_)) { - VoxelShape voxelshape; - if (p_212391_3_ && !flag && !worldborder.contains(p_212390_12_)) { - voxelshape = VoxelShapes.fullCube(); - } else { - voxelshape = iWorldReaderBase.getBlockState(p_212390_12_).getCollisionShape(iWorldReaderBase, p_212390_12_); - } + return CollisionHandler.getCollisionShapes(iWorldReaderBase, area, entityShape, isEntityInsideWorldBorder, i, j, k, l, i1, j1, worldborder, flag, voxelshapepart, predicate); + } catch (final Exception e) { + NoCubes.LOGGER.error("Error with collisions! Falling back to vanilla.", e); + return Stream.concat( + CollisionHandler.getCollisionShapesExcludingSmoothable(null, iWorldReaderBase, area, entityShape, isEntityInsideWorldBorder, i, j, k, l, i1, j1, worldborder, flag, voxelshapepart, predicate), + Stream.generate(() -> new VoxelShapeInt(voxelshapepart, i, k, i1)) + .limit(1L) + .filter(predicate) + ); + } + } - VoxelShape voxelshape1 = p_212391_2_.withOffset((double) (-k1), (double) (-l1), (double) (-i2)); - if (VoxelShapes.compare(voxelshape1, voxelshape, IBooleanFunction.AND)) { - return VoxelShapes.empty(); - } else if (voxelshape == VoxelShapes.fullCube()) { - voxelshapepart.setFilled(k1 - i, l1 - k, i2 - i1, true, true); - return VoxelShapes.empty(); - } else { - return voxelshape.withOffset((double) k1, (double) l1, (double) i2); - } + public static Stream getCollisionShapes(final IWorldReaderBase _this, final Entity movingEntity, final VoxelShape area, final VoxelShape entityShape, boolean isEntityInsideWorldBorder) { + int i = MathHelper.floor(area.getStart(EnumFacing.Axis.X)) - 1; + int j = MathHelper.ceil(area.getEnd(EnumFacing.Axis.X)) + 1; + int k = MathHelper.floor(area.getStart(EnumFacing.Axis.Y)) - 1; + int l = MathHelper.ceil(area.getEnd(EnumFacing.Axis.Y)) + 1; + int i1 = MathHelper.floor(area.getStart(EnumFacing.Axis.Z)) - 1; + int j1 = MathHelper.ceil(area.getEnd(EnumFacing.Axis.Z)) + 1; + WorldBorder worldborder = _this.getWorldBorder(); + boolean flag = worldborder.minX() < (double) i && (double) j < worldborder.maxX() && worldborder.minZ() < (double) i1 && (double) j1 < worldborder.maxZ(); + VoxelShapePart voxelshapepart = new VoxelShapePartBitSet(j - i, l - k, j1 - i1); + Predicate predicate = (p_212393_1_) -> { + return !p_212393_1_.isEmpty() && VoxelShapes.compare(area, p_212393_1_, IBooleanFunction.AND); + }; + // NoCubes Start + // Commented out because its handled by the hook that calls _this +// if (io.github.cadiboo.nocubes.config.Config.terrainCollisions && io.github.cadiboo.nocubes.NoCubes.isEnabled()) + if (io.github.cadiboo.nocubes.hooks.Hooks.shouldApplyCollisions(movingEntity)) + return Hooks.getCollisionShapes(_this, area, entityShape, isEntityInsideWorldBorder, i, j, k, l, i1, j1, worldborder, flag, voxelshapepart, predicate); + // NoCubes End + Stream stream = StreamSupport.stream(BlockPos.MutableBlockPos.getAllInBoxMutable(i, k, i1, j - 1, l - 1, j1 - 1).spliterator(), false).map((p_212390_12_) -> { + int k1 = p_212390_12_.getX(); + int l1 = p_212390_12_.getY(); + int i2 = p_212390_12_.getZ(); + boolean flag1 = k1 == i || k1 == j - 1; + boolean flag2 = l1 == k || l1 == l - 1; + boolean flag3 = i2 == i1 || i2 == j1 - 1; + if ((!flag1 || !flag2) && (!flag2 || !flag3) && (!flag3 || !flag1) && _this.isBlockLoaded(p_212390_12_)) { + VoxelShape voxelshape; + if (isEntityInsideWorldBorder && !flag && !worldborder.contains(p_212390_12_)) { + voxelshape = VoxelShapes.fullCube(); } else { + voxelshape = _this.getBlockState(p_212390_12_).getCollisionShape(_this, p_212390_12_); + } + + VoxelShape voxelshape1 = entityShape.withOffset((double) (-k1), (double) (-l1), (double) (-i2)); + if (VoxelShapes.compare(voxelshape1, voxelshape, IBooleanFunction.AND)) { + return VoxelShapes.empty(); + } else if (voxelshape == VoxelShapes.fullCube()) { + voxelshapepart.setFilled(k1 - i, l1 - k, i2 - i1, true, true); return VoxelShapes.empty(); + } else { + return voxelshape.withOffset((double) k1, (double) l1, (double) i2); } - }).filter(predicate); - return Stream.concat(stream, Stream.generate(() -> new VoxelShapeInt(voxelshapepart, i, k, i1)).limit(1L).filter(predicate)); - } + } else { + return VoxelShapes.empty(); + } + }).filter(predicate); + return Stream.concat(stream, Stream.generate(() -> { + return new VoxelShapeInt(voxelshapepart, i, k, i1); + }).limit(1L).filter(predicate)); + } + + private static boolean shouldApplyCollisions(final Entity movingEntity) { + return CollisionHandler.shouldApplyCollisions(movingEntity); } } diff --git a/src/main/java/net/minecraft/block/state/IBlockState.java b/src/main/java/net/minecraft/block/state/IBlockState.java index fc646fea..5d6397f1 100644 --- a/src/main/java/net/minecraft/block/state/IBlockState.java +++ b/src/main/java/net/minecraft/block/state/IBlockState.java @@ -327,7 +327,7 @@ default void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer player) { } default boolean causesSuffocation() { - return this.getBlock().causesSuffocation(this); + return !this.nocubes_isTerrainSmoothable() && this.getBlock().causesSuffocation(this); } default BlockFaceShape getBlockFaceShape(IBlockReader worldIn, BlockPos pos, EnumFacing facing) { diff --git a/src/main/java/net/minecraft/world/IWorldReaderBase.java b/src/main/java/net/minecraft/world/IWorldReaderBase.java index aa933196..243096d0 100644 --- a/src/main/java/net/minecraft/world/IWorldReaderBase.java +++ b/src/main/java/net/minecraft/world/IWorldReaderBase.java @@ -1,5 +1,11 @@ package net.minecraft.world; +import java.util.Collections; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; +import javax.annotation.Nullable; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -21,13 +27,6 @@ import net.minecraft.world.dimension.Dimension; import net.minecraft.world.gen.Heightmap; -import javax.annotation.Nullable; -import java.util.Collections; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - public interface IWorldReaderBase extends IBlockReader { /** * Checks to see if an air block exists at the provided location. Note that this only checks to see if the blocks @@ -118,23 +117,19 @@ default boolean checkNoEntityCollision(@Nullable Entity entityIn, AxisAlignedBB return this.checkNoEntityCollision(entityIn, VoxelShapes.create(aabb)); } - default Stream func_212391_a(VoxelShape p_212391_1_, VoxelShape p_212391_2_, boolean p_212391_3_) { - int i = MathHelper.floor(p_212391_1_.getStart(EnumFacing.Axis.X)) - 1; - int j = MathHelper.ceil(p_212391_1_.getEnd(EnumFacing.Axis.X)) + 1; - int k = MathHelper.floor(p_212391_1_.getStart(EnumFacing.Axis.Y)) - 1; - int l = MathHelper.ceil(p_212391_1_.getEnd(EnumFacing.Axis.Y)) + 1; - int i1 = MathHelper.floor(p_212391_1_.getStart(EnumFacing.Axis.Z)) - 1; - int j1 = MathHelper.ceil(p_212391_1_.getEnd(EnumFacing.Axis.Z)) + 1; + default Stream getCollisionBoxes(VoxelShape area, VoxelShape entityShape, boolean isEntityInsideWorldBorder) { + int i = MathHelper.floor(area.getStart(EnumFacing.Axis.X)) - 1; + int j = MathHelper.ceil(area.getEnd(EnumFacing.Axis.X)) + 1; + int k = MathHelper.floor(area.getStart(EnumFacing.Axis.Y)) - 1; + int l = MathHelper.ceil(area.getEnd(EnumFacing.Axis.Y)) + 1; + int i1 = MathHelper.floor(area.getStart(EnumFacing.Axis.Z)) - 1; + int j1 = MathHelper.ceil(area.getEnd(EnumFacing.Axis.Z)) + 1; WorldBorder worldborder = this.getWorldBorder(); boolean flag = worldborder.minX() < (double)i && (double)j < worldborder.maxX() && worldborder.minZ() < (double)i1 && (double)j1 < worldborder.maxZ(); VoxelShapePart voxelshapepart = new VoxelShapePartBitSet(j - i, l - k, j1 - i1); Predicate predicate = (p_212393_1_) -> { - return !p_212393_1_.isEmpty() && VoxelShapes.compare(p_212391_1_, p_212393_1_, IBooleanFunction.AND); + return !p_212393_1_.isEmpty() && VoxelShapes.compare(area, p_212393_1_, IBooleanFunction.AND); }; - // NoCubes Start - if(io.github.cadiboo.nocubes.config.Config.terrainCollisions && io.github.cadiboo.nocubes.NoCubes.isEnabled()) - return io.github.cadiboo.nocubes.hooks.Hooks.getCollisionBoxes(this, p_212391_1_, p_212391_2_, p_212391_3_, i, j, k, l, i1, j1, worldborder, flag, voxelshapepart, predicate); - // NoCubes End Stream stream = StreamSupport.stream(BlockPos.MutableBlockPos.getAllInBoxMutable(i, k, i1, j - 1, l - 1, j1 - 1).spliterator(), false).map((p_212390_12_) -> { int k1 = p_212390_12_.getX(); int l1 = p_212390_12_.getY(); @@ -144,13 +139,13 @@ default Stream func_212391_a(VoxelShape p_212391_1_, VoxelShape p_21 boolean flag3 = i2 == i1 || i2 == j1 - 1; if ((!flag1 || !flag2) && (!flag2 || !flag3) && (!flag3 || !flag1) && this.isBlockLoaded(p_212390_12_)) { VoxelShape voxelshape; - if (p_212391_3_ && !flag && !worldborder.contains(p_212390_12_)) { + if (isEntityInsideWorldBorder && !flag && !worldborder.contains(p_212390_12_)) { voxelshape = VoxelShapes.fullCube(); } else { voxelshape = this.getBlockState(p_212390_12_).getCollisionShape(this, p_212390_12_); } - VoxelShape voxelshape1 = p_212391_2_.withOffset((double)(-k1), (double)(-l1), (double)(-i2)); + VoxelShape voxelshape1 = entityShape.withOffset((double)(-k1), (double)(-l1), (double)(-i2)); if (VoxelShapes.compare(voxelshape1, voxelshape, IBooleanFunction.AND)) { return VoxelShapes.empty(); } else if (voxelshape == VoxelShapes.fullCube()) { @@ -168,16 +163,16 @@ default Stream func_212391_a(VoxelShape p_212391_1_, VoxelShape p_21 }).limit(1L).filter(predicate)); } - default Stream getCollisionBoxes(@Nullable Entity p_199406_1_, AxisAlignedBB entityBB, double x, double y, double z) { - return this.func_212389_a(p_199406_1_, entityBB, Collections.emptySet(), x, y, z); + default Stream getCollisionBoxes(@Nullable Entity entityIn, AxisAlignedBB entityBB, double x, double y, double z) { + return this.getCollisionBoxes(entityIn, entityBB, Collections.emptySet(), x, y, z); } - default Stream func_212389_a(@Nullable Entity p_212389_1_, AxisAlignedBB p_212389_2_, Set entitiesToIgnore, double dx, double dy, double dz) { + default Stream getCollisionBoxes(@Nullable Entity entityIn, AxisAlignedBB entityBB, Set entitiesToIgnore, double dx, double dy, double dz) { double d0 = 1.0E-7D; - VoxelShape voxelshape = VoxelShapes.create(p_212389_2_); - VoxelShape voxelshape1 = VoxelShapes.create(p_212389_2_.offset(dx > 0.0D ? -1.0E-7D : 1.0E-7D, dy > 0.0D ? -1.0E-7D : 1.0E-7D, dz > 0.0D ? -1.0E-7D : 1.0E-7D)); - VoxelShape voxelshape2 = VoxelShapes.combine(VoxelShapes.create(p_212389_2_.expand(dx, dy, dz).grow(1.0E-7D)), voxelshape1, IBooleanFunction.ONLY_FIRST); - return this.getCollisionBoxes(p_212389_1_, voxelshape2, voxelshape, entitiesToIgnore); + VoxelShape voxelshape = VoxelShapes.create(entityBB); + VoxelShape voxelshape1 = VoxelShapes.create(entityBB.offset(dx > 0.0D ? -1.0E-7D : 1.0E-7D, dy > 0.0D ? -1.0E-7D : 1.0E-7D, dz > 0.0D ? -1.0E-7D : 1.0E-7D)); + VoxelShape voxelshape2 = VoxelShapes.combine(VoxelShapes.create(entityBB.expand(dx, dy, dz).grow(1.0E-7D)), voxelshape1, IBooleanFunction.ONLY_FIRST); + return this.getCollisionBoxes(entityIn, voxelshape2, voxelshape, entitiesToIgnore); } /** @@ -196,8 +191,13 @@ default Stream getCollisionBoxes(@Nullable Entity movingEntity, Voxe if (movingEntity != null && flag == flag1) { movingEntity.setOutsideBorder(!flag1); } + // NoCubes Start + if(io.github.cadiboo.nocubes.config.Config.terrainCollisions && io.github.cadiboo.nocubes.NoCubes.isEnabled()) { + return io.github.cadiboo.nocubes.hooks.Hooks.getCollisionShapes(this, movingEntity, area, p_212392_3_, flag1); + } + // NoCubes End - return this.func_212391_a(area, p_212392_3_, flag1); + return this.getCollisionBoxes(area, p_212392_3_, flag1); } default boolean isInsideWorldBorder(Entity entityToCheck) { diff --git a/src/main/resources/block-fluid-renderer-transformer.js b/src/main/resources/block-fluid-renderer-transformer.js index c2d25e34..05241f6c 100755 --- a/src/main/resources/block-fluid-renderer-transformer.js +++ b/src/main/resources/block-fluid-renderer-transformer.js @@ -31,246 +31,21 @@ function initializeCoreMod() { isSRG = srgNameEquals; - var instructions = method.instructions; - log("Modifying logic..."); - start("modify isAdjacentFluidSameAs") - { - var first_INVOKEVIRTUAL_offset; - var arrayLength = instructions.size(); - for (var i = 0; i < arrayLength; ++i) { - var instruction = instructions.get(i); - if (instruction.getOpcode() == INVOKEVIRTUAL) { - if (instruction.owner == "net/minecraft/util/math/BlockPos") { - //CPW PLS GIVE ME A WAY TO REMAP SRG TO NAMES FOR DEV - if (instruction.name == "func_177972_a" || instruction.name == "offset") { - if (instruction.desc == "(Lnet/minecraft/util/EnumFacing;)Lnet/minecraft/util/math/BlockPos;") { - if (instruction.itf == false) { - first_INVOKEVIRTUAL_offset = instruction; - log("Found injection point " + instruction); - break; - } - } - } - } - } - } - if (!first_INVOKEVIRTUAL_offset) { - throw "Error: Couldn't find injection point!"; - } - - var firstLabelAfter_first_INVOKEVIRTUAL_offset; - for (i = instructions.indexOf(first_INVOKEVIRTUAL_offset); i < arrayLength; ++i) { - var instruction = instructions.get(i); - if (instruction.getType() == AbstractInsnNode.LABEL) { - firstLabelAfter_first_INVOKEVIRTUAL_offset = instruction; - log("Found label " + instruction); - break; - } + var hasFinished = false; + try { + start("modify_isAdjacentFluidSameAs") + modify_isAdjacentFluidSameAs(method.instructions); + finish(); + hasFinished = true; + } finally { + // Hacks because rethrowing an exception sets the linenumber to where it was re-thrown + if(!hasFinished) { + var name = currentlyRunning; + currentlyRunning = undefined; + log("Caught exception from " + name); } - if (!firstLabelAfter_first_INVOKEVIRTUAL_offset) { - throw "Error: Couldn't find label!"; - } - - //FFS why - var toInject = ASMAPI.getMethodNode().instructions; - - // Labels n stuff - var originalInstructionsLabel = new LabelNode(); - var executeOverrideLabel = new LabelNode(); - -// BlockPos blockpos = pos.offset(side); -// IFluidState ifluidstate = worldIn.getFluidState(blockpos); -// -// BlockPos blockpos = pos.offset(side); -// if (NoCubes.isEnabled()) { -// final IBlockState blockState = worldIn.getBlockState(blockpos); -// if (blockState.nocubes_isTerrainSmoothable() || blockState.nocubes_isLeavesSmoothable()) { -// return !worldIn.getBlockState(blockpos.up()).isSolid(); -// } -// } -// IFluidState ifluidstate = worldIn.getFluidState(blockpos); - - -// L0 -// LINENUMBER 47 L0 -// ALOAD 1 -// ALOAD 2 -// INVOKEVIRTUAL net/minecraft/util/math/BlockPos.offset (Lnet/minecraft/util/EnumFacing;)Lnet/minecraft/util/math/BlockPos; -// ASTORE 4 -// L1 -// LINENUMBER 48 L1 -// ALOAD 0 -// ALOAD 4 -// INVOKEINTERFACE net/minecraft/world/IBlockReader.getFluidState (Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/fluid/IFluidState; (itf) -// ASTORE 5 - -// L0 -// LINENUMBER 46 L0 -// ALOAD 1 -// ALOAD 2 -// INVOKEVIRTUAL net/minecraft/util/math/BlockPos.offset (Lnet/minecraft/util/EnumFacing;)Lnet/minecraft/util/math/BlockPos; -// ASTORE 4 -// L1 -// LINENUMBER 48 L1 -// INVOKESTATIC io/github/cadiboo/nocubes/NoCubes.isEnabled ()Z -// IFEQ L2 -// L3 -// LINENUMBER 49 L3 -// ALOAD 0 -// ALOAD 4 -// INVOKEINTERFACE net/minecraft/world/IBlockReader.getBlockState (Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState; (itf) -// ASTORE 5 -// L4 -// LINENUMBER 50 L4 -// ALOAD 5 -// INVOKEINTERFACE net/minecraft/block/state/IBlockState.nocubes_isTerrainSmoothable ()Z (itf) -// IFNE L5 -// ALOAD 5 -// INVOKEINTERFACE net/minecraft/block/state/IBlockState.nocubes_isLeavesSmoothable ()Z (itf) -// IFEQ L2 -// L5 -// LINENUMBER 51 L5 -// FRAME APPEND [net/minecraft/util/math/BlockPos net/minecraft/block/state/IBlockState] -// ALOAD 0 -// ALOAD 4 -// INVOKEVIRTUAL net/minecraft/util/math/BlockPos.up ()Lnet/minecraft/util/math/BlockPos; -// INVOKEINTERFACE net/minecraft/world/IBlockReader.getBlockState (Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState; (itf) -// INVOKEINTERFACE net/minecraft/block/state/IBlockState.isSolid ()Z (itf) -// IFNE L6 -// ICONST_1 -// GOTO L7 -// L6 -// FRAME SAME1 I -// IRETURN -// L2 -// LINENUMBER 55 L2 -// FRAME CHOP 1 -// ALOAD 0 -// ALOAD 4 -// INVOKEINTERFACE net/minecraft/world/IBlockReader.getFluidState (Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/fluid/IFluidState; (itf) -// ASTORE 5 - - // Make list of instructions to inject - toInject.add(new MethodInsnNode( - //int opcode - INVOKESTATIC, - //String owner - "io/github/cadiboo/nocubes/NoCubes", - //String name - "isEnabled", - //String descriptor - "()Z", - //boolean isInterface - false - )); - toInject.add(new JumpInsnNode(IFEQ, originalInstructionsLabel)); - - toInject.add(new LabelNode()); - toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_this)); - toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_blockpos)); - toInject.add(new MethodInsnNode( - //int opcode - INVOKEINTERFACE, - //String owner - "net/minecraft/world/IBlockReader", - //String name - isSRG ? "func_180495_p" : "getBlockState", - //String descriptor - "(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;", - //boolean isInterface - true - )); - toInject.add(new VarInsnNode(ASTORE, ALOCALVARIABLE_blockstate)); - - toInject.add(new LabelNode()); - toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_blockstate)); - toInject.add(new MethodInsnNode( - //int opcode - INVOKEINTERFACE, - //String owner - "net/minecraft/block/state/IBlockState", - //String name - "nocubes_isTerrainSmoothable", - //String descriptor - "()Z", - //boolean isInterface - true - )); - toInject.add(new JumpInsnNode(IFNE, executeOverrideLabel)); - - toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_blockstate)); - toInject.add(new MethodInsnNode( - //int opcode - INVOKEINTERFACE, - //String owner - "net/minecraft/block/state/IBlockState", - //String name - "nocubes_isLeavesSmoothable", - //String descriptor - "()Z", - //boolean isInterface - true - )); - toInject.add(new JumpInsnNode(IFEQ, originalInstructionsLabel)); - - toInject.add(executeOverrideLabel); - toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_this)); - toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_blockpos)); - toInject.add(new MethodInsnNode( - //int opcode - INVOKEVIRTUAL, - //String owner - "net/minecraft/util/math/BlockPos", - //String name - isSRG ? "func_177984_a" : "up", - //String descriptor - "()Lnet/minecraft/util/math/BlockPos;", - //boolean isInterface - false - )); - toInject.add(new MethodInsnNode( - //int opcode - INVOKEINTERFACE, - //String owner - "net/minecraft/world/IBlockReader", - //String name - isSRG ? "func_180495_p" : "getBlockState", - //String descriptor - "(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;", - //boolean isInterface - true - )); - toInject.add(new MethodInsnNode( - //int opcode - INVOKEINTERFACE, - //String owner - "net/minecraft/block/state/IBlockState", - //String name - isSRG ? "func_200132_m" : "isSolid", - //String descriptor - "()Z", - //boolean isInterface - true - )); - var returnTrueLabel = new LabelNode(); - toInject.add(new JumpInsnNode(IFEQ, returnTrueLabel)); - - toInject.add(new LabelNode()); - toInject.add(new InsnNode(ICONST_0)); - toInject.add(new InsnNode(IRETURN)); - - toInject.add(returnTrueLabel); - toInject.add(new InsnNode(ICONST_1)); - toInject.add(new InsnNode(IRETURN)); - - toInject.add(originalInstructionsLabel); - - // Inject instructions - instructions.insertBefore(firstLabelAfter_first_INVOKEVIRTUAL_offset, toInject); - } - finish(); log("Successfully modified logic!"); break; @@ -605,3 +380,248 @@ var ALOCALVARIABLE_blockpos = 4; var ALOCALVARIABLE_fluidstate = 5; var ALOCALVARIABLE_blockstate = 6; + + + + + + + + + +function modify_isAdjacentFluidSameAs(instructions) { + + var first_INVOKEVIRTUAL_offset; + var arrayLength = instructions.size(); + for (var i = 0; i < arrayLength; ++i) { + var instruction = instructions.get(i); + if (instruction.getOpcode() == INVOKEVIRTUAL) { + if (instruction.owner == "net/minecraft/util/math/BlockPos") { + //CPW PLS GIVE ME A WAY TO REMAP SRG TO NAMES FOR DEV + if (instruction.name == "func_177972_a" || instruction.name == "offset") { + if (instruction.desc == "(Lnet/minecraft/util/EnumFacing;)Lnet/minecraft/util/math/BlockPos;") { + if (instruction.itf == false) { + first_INVOKEVIRTUAL_offset = instruction; + log("Found injection point " + instruction); + break; + } + } + } + } + } + } + if (!first_INVOKEVIRTUAL_offset) { + throw "Error: Couldn't find injection point!"; + } + + var firstLabelAfter_first_INVOKEVIRTUAL_offset; + for (i = instructions.indexOf(first_INVOKEVIRTUAL_offset); i < arrayLength; ++i) { + var instruction = instructions.get(i); + if (instruction.getType() == AbstractInsnNode.LABEL) { + firstLabelAfter_first_INVOKEVIRTUAL_offset = instruction; + log("Found label " + instruction); + break; + } + } + if (!firstLabelAfter_first_INVOKEVIRTUAL_offset) { + throw "Error: Couldn't find label!"; + } + + //FFS why + var toInject = ASMAPI.getMethodNode().instructions; + + // Labels n stuff + var originalInstructionsLabel = new LabelNode(); + var executeOverrideLabel = new LabelNode(); + +// BlockPos blockpos = pos.offset(side); +// IFluidState ifluidstate = worldIn.getFluidState(blockpos); +// +// BlockPos blockpos = pos.offset(side); +// if (NoCubes.isEnabled()) { +// final IBlockState blockState = worldIn.getBlockState(blockpos); +// if (blockState.nocubes_isTerrainSmoothable() || blockState.nocubes_isLeavesSmoothable()) { +// return !worldIn.getBlockState(blockpos.up()).isSolid(); +// } +// } +// IFluidState ifluidstate = worldIn.getFluidState(blockpos); + + +// L0 +// LINENUMBER 47 L0 +// ALOAD 1 +// ALOAD 2 +// INVOKEVIRTUAL net/minecraft/util/math/BlockPos.offset (Lnet/minecraft/util/EnumFacing;)Lnet/minecraft/util/math/BlockPos; +// ASTORE 4 +// L1 +// LINENUMBER 48 L1 +// ALOAD 0 +// ALOAD 4 +// INVOKEINTERFACE net/minecraft/world/IBlockReader.getFluidState (Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/fluid/IFluidState; (itf) +// ASTORE 5 + +// L0 +// LINENUMBER 46 L0 +// ALOAD 1 +// ALOAD 2 +// INVOKEVIRTUAL net/minecraft/util/math/BlockPos.offset (Lnet/minecraft/util/EnumFacing;)Lnet/minecraft/util/math/BlockPos; +// ASTORE 4 +// L1 +// LINENUMBER 48 L1 +// INVOKESTATIC io/github/cadiboo/nocubes/NoCubes.isEnabled ()Z +// IFEQ L2 +// L3 +// LINENUMBER 49 L3 +// ALOAD 0 +// ALOAD 4 +// INVOKEINTERFACE net/minecraft/world/IBlockReader.getBlockState (Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState; (itf) +// ASTORE 5 +// L4 +// LINENUMBER 50 L4 +// ALOAD 5 +// INVOKEINTERFACE net/minecraft/block/state/IBlockState.nocubes_isTerrainSmoothable ()Z (itf) +// IFNE L5 +// ALOAD 5 +// INVOKEINTERFACE net/minecraft/block/state/IBlockState.nocubes_isLeavesSmoothable ()Z (itf) +// IFEQ L2 +// L5 +// LINENUMBER 51 L5 +// FRAME APPEND [net/minecraft/util/math/BlockPos net/minecraft/block/state/IBlockState] +// ALOAD 0 +// ALOAD 4 +// INVOKEVIRTUAL net/minecraft/util/math/BlockPos.up ()Lnet/minecraft/util/math/BlockPos; +// INVOKEINTERFACE net/minecraft/world/IBlockReader.getBlockState (Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState; (itf) +// INVOKEINTERFACE net/minecraft/block/state/IBlockState.isSolid ()Z (itf) +// IFNE L6 +// ICONST_1 +// GOTO L7 +// L6 +// FRAME SAME1 I +// IRETURN +// L2 +// LINENUMBER 55 L2 +// FRAME CHOP 1 +// ALOAD 0 +// ALOAD 4 +// INVOKEINTERFACE net/minecraft/world/IBlockReader.getFluidState (Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/fluid/IFluidState; (itf) +// ASTORE 5 + + // Make list of instructions to inject + toInject.add(new MethodInsnNode( + //int opcode + INVOKESTATIC, + //String owner + "io/github/cadiboo/nocubes/NoCubes", + //String name + "isEnabled", + //String descriptor + "()Z", + //boolean isInterface + false + )); + toInject.add(new JumpInsnNode(IFEQ, originalInstructionsLabel)); + + toInject.add(new LabelNode()); + toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_this)); + toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_blockpos)); + toInject.add(new MethodInsnNode( + //int opcode + INVOKEINTERFACE, + //String owner + "net/minecraft/world/IBlockReader", + //String name + isSRG ? "func_180495_p" : "getBlockState", + //String descriptor + "(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;", + //boolean isInterface + true + )); + toInject.add(new VarInsnNode(ASTORE, ALOCALVARIABLE_blockstate)); + + toInject.add(new LabelNode()); + toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_blockstate)); + toInject.add(new MethodInsnNode( + //int opcode + INVOKEINTERFACE, + //String owner + "net/minecraft/block/state/IBlockState", + //String name + "nocubes_isTerrainSmoothable", + //String descriptor + "()Z", + //boolean isInterface + true + )); + toInject.add(new JumpInsnNode(IFNE, executeOverrideLabel)); + + toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_blockstate)); + toInject.add(new MethodInsnNode( + //int opcode + INVOKEINTERFACE, + //String owner + "net/minecraft/block/state/IBlockState", + //String name + "nocubes_isLeavesSmoothable", + //String descriptor + "()Z", + //boolean isInterface + true + )); + toInject.add(new JumpInsnNode(IFEQ, originalInstructionsLabel)); + + toInject.add(executeOverrideLabel); + toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_this)); + toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_blockpos)); + toInject.add(new MethodInsnNode( + //int opcode + INVOKEVIRTUAL, + //String owner + "net/minecraft/util/math/BlockPos", + //String name + isSRG ? "func_177984_a" : "up", + //String descriptor + "()Lnet/minecraft/util/math/BlockPos;", + //boolean isInterface + false + )); + toInject.add(new MethodInsnNode( + //int opcode + INVOKEINTERFACE, + //String owner + "net/minecraft/world/IBlockReader", + //String name + isSRG ? "func_180495_p" : "getBlockState", + //String descriptor + "(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;", + //boolean isInterface + true + )); + toInject.add(new MethodInsnNode( + //int opcode + INVOKEINTERFACE, + //String owner + "net/minecraft/block/state/IBlockState", + //String name + isSRG ? "func_200132_m" : "isSolid", + //String descriptor + "()Z", + //boolean isInterface + true + )); + var returnTrueLabel = new LabelNode(); + toInject.add(new JumpInsnNode(IFEQ, returnTrueLabel)); + + toInject.add(new LabelNode()); + toInject.add(new InsnNode(ICONST_0)); + toInject.add(new InsnNode(IRETURN)); + + toInject.add(returnTrueLabel); + toInject.add(new InsnNode(ICONST_1)); + toInject.add(new InsnNode(IRETURN)); + + toInject.add(originalInstructionsLabel); + + // Inject instructions + instructions.insertBefore(firstLabelAfter_first_INVOKEVIRTUAL_offset, toInject); + +} diff --git a/src/main/resources/i-block-state-transformer.js b/src/main/resources/i-block-state-transformer.js index 0c93ab75..f413788e 100755 --- a/src/main/resources/i-block-state-transformer.js +++ b/src/main/resources/i-block-state-transformer.js @@ -11,6 +11,7 @@ function initializeCoreMod() { var methods = classNode.methods; + start("find isSolid"); for (var i in methods) { var method = methods[i]; var methodName = method.name; @@ -27,97 +28,59 @@ function initializeCoreMod() { log(deobfNameEquals ? "Matched a deobfuscated name - we are in a DEOBFUSCATED/MCP-NAMED DEVELOPER Environment" : "Matched an SRG name - We are in an SRG-NAMED PRODUCTION Environment") - var instructions = method.instructions; - - log("Injecting hook..."); - start("isSolidHook") - { - - var firstLabel; - var arrayLength = instructions.size(); - for (var i = 0; i < arrayLength; ++i) { - var instruction = instructions.get(i); - if (instruction.getType() == AbstractInsnNode.LABEL) { - firstLabel = instruction; - log("Found injection point " + instruction); - break; - } - } - if (!firstLabel) { - throw "Error: Couldn't find injection point!"; + finish(); + + var hasFinished = false; + try { + start("injectIsSolidHook") + injectIsSolidHook(method.instructions); + finish(); + hasFinished = true; + } finally { + // Hacks because rethrowing an exception sets the linenumber to where it was re-thrown + if(!hasFinished) { + var name = currentlyRunning; + currentlyRunning = undefined; + log("Caught exception from " + name); } + } + break; - //FFS why - var toInject = ASMAPI.getMethodNode().instructions; + } - // Labels n stuff - var originalInstructionsLabel = new LabelNode(); + start("find causesSuffocation"); + for (var i in methods) { + var method = methods[i]; + var methodName = method.name; -// return this.getBlock().isSolid(this); -// -// if (nocubes_isTerrainSmoothable() && NoCubes.isEnabled()) return false; -// return this.getBlock().isSolid(this); + var deobfNameEquals = "causesSuffocation".equals(methodName); + var srgNameEquals = "func_191058_s".equals(methodName); -// public default isSolid()Z -// L0 -// LINENUMBER 220 L0 -// ALOAD 0 -// INVOKEINTERFACE net/minecraft/block/state/IBlockState.nocubes_isTerrainSmoothable ()Z (itf) -// IFEQ L1 -// INVOKESTATIC io/github/cadiboo/nocubes/NoCubes.isEnabled ()Z -// IFEQ L1 -// ICONST_0 -// IRETURN -// L1 -// LINENUMBER 221 L1 -// FRAME SAME -// ALOAD 0 -// INVOKEINTERFACE net/minecraft/block/state/IBlockState.getBlock ()Lnet/minecraft/block/Block; (itf) -// ALOAD 0 -// INVOKEVIRTUAL net/minecraft/block/Block.isSolid (Lnet/minecraft/block/state/IBlockState;)Z -// IRETURN + if (!deobfNameEquals && !srgNameEquals) { + log("Did not match method " + methodName); + continue; + } - // Make list of instructions to inject - toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_this)); - toInject.add(new MethodInsnNode( - //int opcode - INVOKEINTERFACE, - //String owner - "net/minecraft/block/state/IBlockState", - //String name - "nocubes_isTerrainSmoothable", - //String descriptor - "()Z", - //boolean isInterface - true - )); - toInject.add(new JumpInsnNode(IFEQ, originalInstructionsLabel)); - toInject.add(new MethodInsnNode( - //int opcode - INVOKESTATIC, - //String owner - "io/github/cadiboo/nocubes/NoCubes", - //String name - "isEnabled", - //String descriptor - "()Z", - //boolean isInterface - false - )); - toInject.add(new JumpInsnNode(IFEQ, originalInstructionsLabel)); - - toInject.add(new LabelNode()); - toInject.add(new InsnNode(ICONST_0)); - toInject.add(new InsnNode(IRETURN)); - - toInject.add(originalInstructionsLabel); - - // Inject instructions - instructions.insert(firstLabel, toInject); + log("Matched method " + methodName); + + log(deobfNameEquals ? "Matched a deobfuscated name - we are in a DEOBFUSCATED/MCP-NAMED DEVELOPER Environment" : "Matched an SRG name - We are in an SRG-NAMED PRODUCTION Environment") - } finish(); - log("Successfully injected hook!"); + + var hasFinished = false; + try { + start("injectCausesSuffocationHook") + injectCausesSuffocationHook(method.instructions); + finish(); + hasFinished = true; + } finally { + // Hacks because rethrowing an exception sets the linenumber to where it was re-thrown + if(!hasFinished) { + var name = currentlyRunning; + currentlyRunning = undefined; + log("Caught exception from " + name); + } + } break; } @@ -608,3 +571,192 @@ var/*Class*/ ASMAPI = Java.type('net.minecraftforge.coremod.api.ASMAPI'); // Local variable indexes var ALOCALVARIABLE_this = 0; + + + + + + + +function injectIsSolidHook(instructions) { + + var firstLabel; + var arrayLength = instructions.size(); + for (var i = 0; i < arrayLength; ++i) { + var instruction = instructions.get(i); + if (instruction.getType() == AbstractInsnNode.LABEL) { + firstLabel = instruction; + log("Found injection point " + instruction); + break; + } + } + if (!firstLabel) { + throw "Error: Couldn't find injection point!"; + } + + //FFS why + var toInject = ASMAPI.getMethodNode().instructions; + + // Labels n stuff + var originalInstructionsLabel = new LabelNode(); + +// return this.getBlock().isSolid(this); +// +// if (nocubes_isTerrainSmoothable() && NoCubes.isEnabled()) return false; +// return this.getBlock().isSolid(this); + +// public default isSolid()Z +// L0 +// LINENUMBER 220 L0 +// ALOAD 0 +// INVOKEINTERFACE net/minecraft/block/state/IBlockState.nocubes_isTerrainSmoothable ()Z (itf) +// IFEQ L1 +// INVOKESTATIC io/github/cadiboo/nocubes/NoCubes.isEnabled ()Z +// IFEQ L1 +// ICONST_0 +// IRETURN +// L1 +// LINENUMBER 221 L1 +// FRAME SAME +// ALOAD 0 +// INVOKEINTERFACE net/minecraft/block/state/IBlockState.getBlock ()Lnet/minecraft/block/Block; (itf) +// ALOAD 0 +// INVOKEVIRTUAL net/minecraft/block/Block.isSolid (Lnet/minecraft/block/state/IBlockState;)Z +// IRETURN + + // Make list of instructions to inject + toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_this)); + toInject.add(new MethodInsnNode( + //int opcode + INVOKEINTERFACE, + //String owner + "net/minecraft/block/state/IBlockState", + //String name + "nocubes_isTerrainSmoothable", + //String descriptor + "()Z", + //boolean isInterface + true + )); + toInject.add(new JumpInsnNode(IFEQ, originalInstructionsLabel)); + toInject.add(new MethodInsnNode( + //int opcode + INVOKESTATIC, + //String owner + "io/github/cadiboo/nocubes/NoCubes", + //String name + "isEnabled", + //String descriptor + "()Z", + //boolean isInterface + false + )); + toInject.add(new JumpInsnNode(IFEQ, originalInstructionsLabel)); + + toInject.add(new LabelNode()); + toInject.add(new InsnNode(ICONST_0)); + toInject.add(new InsnNode(IRETURN)); + + toInject.add(originalInstructionsLabel); + + // Inject instructions + instructions.insert(firstLabel, toInject); + +} + +function injectCausesSuffocationHook(instructions) { + + var firstLabel; + var arrayLength = instructions.size(); + for (var i = 0; i < arrayLength; ++i) { + var instruction = instructions.get(i); + if (instruction.getType() == AbstractInsnNode.LABEL) { + firstLabel = instruction; + log("Found injection point " + instruction); + break; + } + } + if (!firstLabel) { + throw "Error: Couldn't find injection point!"; + } + + //FFS why + var toInject = ASMAPI.getMethodNode().instructions; + + // Labels n stuff + var originalInstructionsLabel = new LabelNode(); + +// return this.getBlock().causesSuffocation(this); + +// return !this.nocubes_isTerrainSmoothable() && this.getBlock().causesSuffocation(this); + + +// public default causesSuffocation()Z +// L0 +// LINENUMBER 321 L0 +// ALOAD 0 +// INVOKEINTERFACE net/minecraft/block/state/IBlockState.getBlock ()Lnet/minecraft/block/Block; (itf) +// ALOAD 0 +// INVOKEVIRTUAL net/minecraft/block/Block.causesSuffocation (Lnet/minecraft/block/state/IBlockState;)Z +// IRETURN + +// public default causesSuffocation()Z +// L0 +// LINENUMBER 330 L0 +// ALOAD 0 +// INVOKEINTERFACE net/minecraft/block/state/IBlockState.nocubes_isTerrainSmoothable ()Z (itf) +// IFNE L1 +// ALOAD 0 +// INVOKEINTERFACE net/minecraft/block/state/IBlockState.getBlock ()Lnet/minecraft/block/Block; (itf) +// ALOAD 0 +// INVOKEVIRTUAL net/minecraft/block/Block.causesSuffocation (Lnet/minecraft/block/state/IBlockState;)Z +// IFEQ L1 +// ICONST_1 +// GOTO L2 +// L1 +// FRAME SAME +// ICONST_0 +// L2 +// FRAME SAME1 I +// IRETURN + + + // Make list of instructions to inject + toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_this)); + toInject.add(new MethodInsnNode( + //int opcode + INVOKEINTERFACE, + //String owner + "net/minecraft/block/state/IBlockState", + //String name + "nocubes_isTerrainSmoothable", + //String descriptor + "()Z", + //boolean isInterface + true + )); + toInject.add(new JumpInsnNode(IFEQ, originalInstructionsLabel)); + toInject.add(new MethodInsnNode( + //int opcode + INVOKESTATIC, + //String owner + "io/github/cadiboo/nocubes/NoCubes", + //String name + "isEnabled", + //String descriptor + "()Z", + //boolean isInterface + false + )); + toInject.add(new JumpInsnNode(IFEQ, originalInstructionsLabel)); + + toInject.add(new LabelNode()); + toInject.add(new InsnNode(ICONST_0)); + toInject.add(new InsnNode(IRETURN)); + + toInject.add(originalInstructionsLabel); + + // Inject instructions + instructions.insert(firstLabel, toInject); + +} diff --git a/src/main/resources/i-world-reader-base-transformer.js b/src/main/resources/i-world-reader-base-transformer.js index 5337e94a..d15563c7 100755 --- a/src/main/resources/i-world-reader-base-transformer.js +++ b/src/main/resources/i-world-reader-base-transformer.js @@ -16,14 +16,14 @@ function initializeCoreMod() { var methodName = method.name; var deobfNameEquals = "getCollisionBoxes".equals(methodName); - var srgNameEquals = "func_212391_a".equals(methodName); + var srgNameEquals = "func_212392_a".equals(methodName); if (!deobfNameEquals && !srgNameEquals) { log("Did not match method " + methodName); continue; } - if (!method.desc.equals("(Lnet/minecraft/util/math/shapes/VoxelShape;Lnet/minecraft/util/math/shapes/VoxelShape;Z)Ljava/util/stream/Stream;")) { + if (!method.desc.equals("(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/shapes/VoxelShape;Lnet/minecraft/util/math/shapes/VoxelShape;Ljava/util/Set;)Ljava/util/stream/Stream;")) { log("Did not match method description " + method.desc); continue; } @@ -45,7 +45,7 @@ function initializeCoreMod() { // Hacks because rethrowing an exception sets the linenumber to where it was re-thrown if(!hasFinished) { var name = currentlyRunning; - finish(); + currentlyRunning = undefined; log("Caught exception from " + name); } } @@ -380,19 +380,10 @@ var/*Class*/ ASMAPI = Java.type('net.minecraftforge.coremod.api.ASMAPI'); // Local variable indexes var ALOCALVARIABLE_this = 0; -var ALOCALVARIABLE_area = 1; -var ALOCALVARIABLE_entityShape = 2; -var ILOCALVARIABLE_isEntityInsideWorldBorder = 3; -var ILOCALVARIABLE_i_minXm1 = 4; -var ILOCALVARIABLE_j_maxXp1 = 5; -var ILOCALVARIABLE_k_minYm1 = 6; -var ILOCALVARIABLE_l_maxYp1 = 7; -var ILOCALVARIABLE_i1_minZm1 = 8; -var ILOCALVARIABLE_j1_maxZp1 = 9; -var ALOCALVARIABLE_worldborder = 10; -var ILOCALVARIABLE_flag_isAreaInsideWorldBorder = 11; -var ALOCALVARIABLE_voxelshapepart = 12; -var ALOCALVARIABLE_predicate = 13; +var ALOCALVARIABLE_movingEntity = 1; +var ALOCALVARIABLE_area = 2; +var ALOCALVARIABLE_entityShape = 3; +var ILOCALVARIABLE_flag1 = 6; @@ -403,125 +394,84 @@ var ALOCALVARIABLE_predicate = 13; -// Finds the first instruction INVOKESTATIC StreamSupport.stream -// then finds the previous label -// and inserts after the label and before the label's instructions. +// Finds the first instruction INVOKEVIRTUAL Entity.setOutsideBorder +// then finds the next label +// and inserts after that label and before the label's instructions. function injectGetCollisionBoxesHook(instructions) { -// Predicate predicate = (p_212393_1_) -> { -// return !p_212393_1_.isEmpty() && VoxelShapes.compare(p_212391_1_, p_212393_1_, IBooleanFunction.AND); -// }; -// Stream stream = StreamSupport.stream(BlockPos.MutableBlockPos.getAllInBoxMutable(i, k, i1, j - 1, l - 1, j1 - 1).spliterator(), false).map((p_212390_12_) -> { +// if (movingEntity != null && flag == flag1) { +// movingEntity.setOutsideBorder(!flag1); +// } +// +// return this.func_212391_a(area, p_212392_3_, flag1) -// Predicate predicate = (p_212393_1_) -> { -// return !p_212393_1_.isEmpty() && VoxelShapes.compare(p_212391_1_, p_212393_1_, IBooleanFunction.AND); -// }; +// if (movingEntity != null && flag == flag1) { +// movingEntity.setOutsideBorder(!flag1); +// } // // NoCubes Start -// if(io.github.cadiboo.nocubes.config.Config.terrainCollisions && io.github.cadiboo.nocubes.NoCubes.isEnabled()) -// return io.github.cadiboo.nocubes.hooks.Hooks.getCollisionBoxes(this, p_212391_1_, p_212391_2_, p_212391_3_, i, j, k, l, i1, j1, worldborder, flag, voxelshapepart, predicate); +// if (io.github.cadiboo.nocubes.config.Config.terrainCollisions && io.github.cadiboo.nocubes.NoCubes.isEnabled()) { +// return io.github.cadiboo.nocubes.hooks.Hooks.getCollisionShapes(this, movingEntity, area, p_212392_3_, flag1); +// } // // NoCubes End -// Stream stream = StreamSupport.stream(BlockPos.MutableBlockPos.getAllInBoxMutable(i, k, i1, j - 1, l - 1, j1 - 1).spliterator(), false).map((p_212390_12_) -> { +// +// return this.func_212391_a(area, p_212392_3_, flag1) -// L11 -// LINENUMBER 131 L11 -// ALOAD 1 -// INVOKEDYNAMIC test(Lnet/minecraft/util/math/shapes/VoxelShape;)Ljava/util/function/Predicate; [ -// // handle kind 0x6 : INVOKESTATIC -// java/lang/invoke/LambdaMetafactory.metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; -// // arguments: -// (Ljava/lang/Object;)Z, -// // handle kind 0x6 : INVOKESTATIC -// net/minecraft/world/IWorldReaderBase.lambda$func_212391_a$0(Lnet/minecraft/util/math/shapes/VoxelShape;Lnet/minecraft/util/math/shapes/VoxelShape;)Z itf, -// (Lnet/minecraft/util/math/shapes/VoxelShape;)Z -// ] -// ASTORE 13 -// L12 -// LINENUMBER 134 L12 -// ILOAD 4 +// L10 +// FRAME FULL [net/minecraft/world/IWorldReaderBase net/minecraft/entity/Entity net/minecraft/util/math/shapes/VoxelShape net/minecraft/util/math/shapes/VoxelShape java/util/Set I I] [net/minecraft/entity/Entity I] +// INVOKEVIRTUAL net/minecraft/entity/Entity.setOutsideBorder (Z)V +// L7 +// LINENUMBER 195 L7 +// FRAME SAME +// ALOAD 0 +// ALOAD 2 +// ALOAD 3 // ILOAD 6 -// ILOAD 8 -// ILOAD 5 -// ICONST_1 -// ISUB -// ILOAD 7 -// ICONST_1 -// ISUB -// ILOAD 9 -// ICONST_1 -// ISUB -// INVOKESTATIC net/minecraft/util/math/BlockPos$MutableBlockPos.getAllInBoxMutable (IIIIII)Ljava/lang/Iterable; -// INVOKEINTERFACE java/lang/Iterable.spliterator ()Ljava/util/Spliterator; (itf) -// ICONST_0 -// INVOKESTATIC java/util/stream/StreamSupport.stream (Ljava/util/Spliterator;Z)Ljava/util/stream/Stream; +// INVOKEINTERFACE net/minecraft/world/IWorldReaderBase.getCollisionBoxes (Lnet/minecraft/util/math/shapes/VoxelShape;Lnet/minecraft/util/math/shapes/VoxelShape;Z)Ljava/util/stream/Stream; (itf) +// ARETURN -// L11 -// LINENUMBER 131 L11 -// ALOAD 1 -// INVOKEDYNAMIC test(Lnet/minecraft/util/math/shapes/VoxelShape;)Ljava/util/function/Predicate; [ -// // handle kind 0x6 : INVOKESTATIC -// java/lang/invoke/LambdaMetafactory.metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; -// // arguments: -// (Ljava/lang/Object;)Z, -// // handle kind 0x6 : INVOKESTATIC -// net/minecraft/world/IWorldReaderBase.lambda$func_212391_a$0(Lnet/minecraft/util/math/shapes/VoxelShape;Lnet/minecraft/util/math/shapes/VoxelShape;)Z itf, -// (Lnet/minecraft/util/math/shapes/VoxelShape;)Z -// ] -// ASTORE 13 -// L12 -// LINENUMBER 135 L12 +// L10 +// FRAME FULL [net/minecraft/world/IWorldReaderBase net/minecraft/entity/Entity net/minecraft/util/math/shapes/VoxelShape net/minecraft/util/math/shapes/VoxelShape java/util/Set I I] [net/minecraft/entity/Entity I] +// INVOKEVIRTUAL net/minecraft/entity/Entity.setOutsideBorder (Z)V +// L7 +// LINENUMBER 196 L7 +// FRAME SAME // GETSTATIC io/github/cadiboo/nocubes/config/Config.terrainCollisions : Z -// IFEQ L13 +// IFEQ L11 // INVOKESTATIC io/github/cadiboo/nocubes/NoCubes.isEnabled ()Z -// IFEQ L13 -// L14 -// LINENUMBER 136 L14 +// IFEQ L11 +// L12 +// LINENUMBER 197 L12 // ALOAD 0 // ALOAD 1 // ALOAD 2 -// ILOAD 3 -// ILOAD 4 -// ILOAD 5 +// ALOAD 3 // ILOAD 6 -// ILOAD 7 -// ILOAD 8 -// ILOAD 9 -// ALOAD 10 -// ILOAD 11 -// ALOAD 12 -// ALOAD 13 -// INVOKESTATIC io/github/cadiboo/nocubes/hooks/Hooks.getCollisionBoxes (Lnet/minecraft/world/IWorldReaderBase;Lnet/minecraft/util/math/shapes/VoxelShape;Lnet/minecraft/util/math/shapes/VoxelShape;ZIIIIIILnet/minecraft/world/border/WorldBorder;ZLnet/minecraft/util/math/shapes/VoxelShapePart;Ljava/util/function/Predicate;)Ljava/util/stream/Stream; +// INVOKESTATIC io/github/cadiboo/nocubes/hooks/Hooks.getCollisionShapes (Lnet/minecraft/world/IWorldReaderBase;Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/shapes/VoxelShape;Lnet/minecraft/util/math/shapes/VoxelShape;Z)Ljava/util/stream/Stream; // ARETURN -// L13 -// LINENUMBER 138 L13 -// FRAME APPEND [I net/minecraft/util/math/shapes/VoxelShapePart java/util/function/Predicate] -// ILOAD 4 +// L11 +// LINENUMBER 201 L11 +// FRAME SAME +// ALOAD 0 +// ALOAD 2 +// ALOAD 3 // ILOAD 6 -// ILOAD 8 -// ILOAD 5 -// ICONST_1 -// ISUB -// ILOAD 7 -// ICONST_1 -// ISUB -// ILOAD 9 -// ICONST_1 -// ISUB -// INVOKESTATIC net/minecraft/util/math/BlockPos$MutableBlockPos.getAllInBoxMutable (IIIIII)Ljava/lang/Iterable; -// INVOKEINTERFACE java/lang/Iterable.spliterator ()Ljava/util/Spliterator; (itf) -// ICONST_0 -// INVOKESTATIC java/util/stream/StreamSupport.stream (Ljava/util/Spliterator;Z)Ljava/util/stream/Stream; - - var first_INVOKESTATIC_StreamSupport_stream; +// INVOKEINTERFACE net/minecraft/world/IWorldReaderBase.func_212391_a (Lnet/minecraft/util/math/shapes/VoxelShape;Lnet/minecraft/util/math/shapes/VoxelShape;Z)Ljava/util/stream/Stream; (itf) +// ARETURN + + +// INVOKEVIRTUAL net/minecraft/entity/Entity.setOutsideBorder (Z)V + var first_INVOKEVIRTUAL_Entity_setOutsideBorder; var arrayLength = instructions.size(); for (var i = 0; i < arrayLength; ++i) { var instruction = instructions.get(i); - if (instruction.getOpcode() == INVOKESTATIC) { - if (instruction.owner == "java/util/stream/StreamSupport") { - if (instruction.name == "stream") { - if (instruction.desc == "(Ljava/util/Spliterator;Z)Ljava/util/stream/Stream;") { + if (instruction.getOpcode() == INVOKEVIRTUAL) { + if (instruction.owner == "net/minecraft/entity/Entity") { + //CPW PLS GIVE ME A WAY TO REMAP SRG TO NAMES FOR DEV + if (instruction.name == "func_174821_h" || instruction.name == "setOutsideBorder") { + if (instruction.desc == "(Z)V") { if (instruction.itf == false) { - first_INVOKESTATIC_StreamSupport_stream = instruction; + first_INVOKEVIRTUAL_Entity_setOutsideBorder = instruction; log("Found injection point " + instruction); break; } @@ -530,20 +480,23 @@ function injectGetCollisionBoxesHook(instructions) { } } } - if (!first_INVOKESTATIC_StreamSupport_stream) { + if (!first_INVOKEVIRTUAL_Entity_setOutsideBorder) { throw "Error: Couldn't find injection point!"; } - var firstLabelBefore_first_INVOKESTATIC_StreamSupport_stream; - for (i = instructions.indexOf(first_INVOKESTATIC_StreamSupport_stream); i >=0; --i) { + var firstLabelAfter_first_INVOKEVIRTUAL_Entity_setOutsideBorder; + var startLook = instructions.indexOf(first_INVOKEVIRTUAL_Entity_setOutsideBorder); + var maxLook = startLook + 10; + + for (i = startLook; i < maxLook; ++i) { var instruction = instructions.get(i); if (instruction.getType() == AbstractInsnNode.LABEL) { - firstLabelBefore_first_INVOKESTATIC_StreamSupport_stream = instruction; + firstLabelAfter_first_INVOKEVIRTUAL_Entity_setOutsideBorder = instruction; log("Found label " + instruction); break; } } - if (!firstLabelBefore_first_INVOKESTATIC_StreamSupport_stream) { + if (!firstLabelAfter_first_INVOKEVIRTUAL_Entity_setOutsideBorder) { throw "Error: Couldn't find label!"; } @@ -572,28 +525,19 @@ function injectGetCollisionBoxesHook(instructions) { toInject.add(new LabelNode()); toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_this)); + toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_movingEntity)); toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_area)); toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_entityShape)); - toInject.add(new VarInsnNode(ILOAD, ILOCALVARIABLE_isEntityInsideWorldBorder)); - toInject.add(new VarInsnNode(ILOAD, ILOCALVARIABLE_i_minXm1)); - toInject.add(new VarInsnNode(ILOAD, ILOCALVARIABLE_j_maxXp1)); - toInject.add(new VarInsnNode(ILOAD, ILOCALVARIABLE_k_minYm1)); - toInject.add(new VarInsnNode(ILOAD, ILOCALVARIABLE_l_maxYp1)); - toInject.add(new VarInsnNode(ILOAD, ILOCALVARIABLE_i1_minZm1)); - toInject.add(new VarInsnNode(ILOAD, ILOCALVARIABLE_j1_maxZp1)); - toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_worldborder)); - toInject.add(new VarInsnNode(ILOAD, ILOCALVARIABLE_flag_isAreaInsideWorldBorder)); - toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_voxelshapepart)); - toInject.add(new VarInsnNode(ALOAD, ALOCALVARIABLE_predicate)); + toInject.add(new VarInsnNode(ILOAD, ILOCALVARIABLE_flag1)); toInject.add(new MethodInsnNode( //int opcode INVOKESTATIC, //String owner "io/github/cadiboo/nocubes/hooks/Hooks", //String name - "getCollisionBoxes", + "getCollisionShapes", //String descriptor - "(Lnet/minecraft/world/IWorldReaderBase;Lnet/minecraft/util/math/shapes/VoxelShape;Lnet/minecraft/util/math/shapes/VoxelShape;ZIIIIIILnet/minecraft/world/border/WorldBorder;ZLnet/minecraft/util/math/shapes/VoxelShapePart;Ljava/util/function/Predicate;)Ljava/util/stream/Stream;", + "(Lnet/minecraft/world/IWorldReaderBase;Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/shapes/VoxelShape;Lnet/minecraft/util/math/shapes/VoxelShape;Z)Ljava/util/stream/Stream;", //boolean isInterface false )); @@ -602,6 +546,6 @@ function injectGetCollisionBoxesHook(instructions) { toInject.add(originalInstructionsLabel); // Inject instructions - instructions.insert(firstLabelBefore_first_INVOKESTATIC_StreamSupport_stream, toInject); + instructions.insert(firstLabelAfter_first_INVOKEVIRTUAL_Entity_setOutsideBorder, toInject); } diff --git a/src/main/resources/render-chunk-transformer.js b/src/main/resources/render-chunk-transformer.js index 36dd2ec5..6040f5b4 100755 --- a/src/main/resources/render-chunk-transformer.js +++ b/src/main/resources/render-chunk-transformer.js @@ -43,7 +43,7 @@ function initializeCoreMod() { // Hacks because rethrowing an exception sets the linenumber to where it was re-thrown if(!hasFinished) { var name = currentlyRunning; - finish(); + currentlyRunning = undefined; log("Caught exception from " + name); } } diff --git a/src/main/resources/world-renderer-transformer.js b/src/main/resources/world-renderer-transformer.js index d6022e54..d8fe49c4 100755 --- a/src/main/resources/world-renderer-transformer.js +++ b/src/main/resources/world-renderer-transformer.js @@ -44,7 +44,7 @@ function initializeCoreMod() { // Hacks because rethrowing an exception sets the linenumber to where it was re-thrown if(!hasFinished) { var name = currentlyRunning; - finish(); + currentlyRunning = undefined; log("Caught exception from " + name); } }