Skip to content

Commit

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

# The modid of our mod
modId = nocubes
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/io/github/cadiboo/nocubes/ForgeEventSubscriber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.github.cadiboo.nocubes;

import io.github.cadiboo.nocubes.world.ModWorldEventListener;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import static net.minecraftforge.fml.common.Mod.EventBusSubscriber;

/**
* @author Cadiboo
*/
@EventBusSubscriber(modid = NoCubes.MOD_ID)
public final class ForgeEventSubscriber {

private static final Logger LOGGER = LogManager.getLogger();

@SubscribeEvent
public static void onWorldLoadEvent(final WorldEvent.Load event) {

final IWorld world = event.getWorld();
if (world instanceof World) {
((World) world).addEventListener(new ModWorldEventListener());
} else {
LOGGER.error("Failed to attach event listener to world. world is not a World!");
}

}

}
13 changes: 7 additions & 6 deletions src/main/java/io/github/cadiboo/nocubes/NoCubes.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.cadiboo.nocubes.client.ClientProxy;
import io.github.cadiboo.nocubes.config.Config;
import io.github.cadiboo.nocubes.config.ConfigHolder;
import io.github.cadiboo.nocubes.server.ServerProxy;
import io.github.cadiboo.nocubes.util.IProxy;
import io.github.cadiboo.nocubes.util.ModUtil;
Expand Down Expand Up @@ -53,8 +54,8 @@ public NoCubes() {
modEventBus.addListener(this::onLoadComplete);
modEventBus.addListener(this::onModConfigEvent);

ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, Config.ConfigHolder.CLIENT_SPEC);
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, Config.ConfigHolder.SERVER_SPEC);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ConfigHolder.CLIENT_SPEC);
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ConfigHolder.SERVER_SPEC);

}

Expand Down Expand Up @@ -82,10 +83,10 @@ public void onFMLCommonSetupEvent(final FMLCommonSetupEvent event) {
}

public void onModConfigEvent(ModConfig.ModConfigEvent event) {
if (event.getConfig().getSpec() == Config.ConfigHolder.CLIENT_SPEC) {
Config.bakeClient();
} else if (event.getConfig().getSpec() == Config.ConfigHolder.SERVER_SPEC) {
Config.bakeServer();
if (event.getConfig().getSpec() == ConfigHolder.CLIENT_SPEC) {
Config.bakeClient(event.getConfig());
} else if (event.getConfig().getSpec() == ConfigHolder.SERVER_SPEC) {
Config.bakeServer(event.getConfig());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,42 @@ public static void onClientTickEvent(final ClientTickEvent event) {

final BlockStateToast toast;
if (!state.nocubes_isTerrainSmoothable()) {
state.nocubes_setTerrainSmoothable(true);
Config.addTerrainSmoothable(state);
toast = new BlockStateToast.Add(state, blockPos, objectMouseOver);
} else {
state.nocubes_setTerrainSmoothable(false);
Config.removeTerrainSmoothable(state);
toast = new BlockStateToast.Remove(state, blockPos, objectMouseOver);
}
minecraft.getToastGui().add(toast);

if (NoCubes.isEnabled()) {
ClientUtil.tryReloadRenderers();
}
// fireConfigChangedEvent();
return;
}

}
if (toggleLeavesSmoothableBlockStatePressed) {
// synchronized (ModConfig.getLeavesSmoothableBlockStatesCache()) {
// if (addBlockStateToSmoothable(ModConfig.getLeavesSmoothableBlockStatesCache(), false)) {
// if (NoCubes.isEnabled()) {
// ClientUtil.tryReloadRenderers();
// }
// fireConfigChangedEvent();
// return;
// }
// }
final Minecraft minecraft = Minecraft.getInstance();
final RayTraceResult objectMouseOver = minecraft.objectMouseOver;
if (objectMouseOver.type == BLOCK) {
BlockPos blockPos = objectMouseOver.getBlockPos();
final IBlockState state = minecraft.world.getBlockState(blockPos);

final BlockStateToast toast;
if (!state.nocubes_isLeavesSmoothable()) {
Config.addLeavesSmoothable(state);
toast = new BlockStateToast.Add(state, blockPos, objectMouseOver);
} else {
Config.removeLeavesSmoothable(state);
toast = new BlockStateToast.Remove(state, blockPos, objectMouseOver);
}
minecraft.getToastGui().add(toast);

if (NoCubes.isEnabled()) {
ClientUtil.tryReloadRenderers();
}
return;
}
}
if (toggleProfilersPressed) {
synchronized (ModProfiler.PROFILERS) {
Expand Down
36 changes: 2 additions & 34 deletions src/main/java/io/github/cadiboo/nocubes/client/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.ReportedException;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;

import static io.github.cadiboo.nocubes.NoCubes.MOD_ID;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_C;
Expand All @@ -36,8 +30,6 @@ public final class ClientProxy implements IProxy {

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

private static final MethodHandle WorldRenderer_markBlocksForUpdate;

public static SmoothLightingBlockFluidRenderer fluidRenderer;

static {
Expand All @@ -47,37 +39,13 @@ public final class ClientProxy implements IProxy {
ClientRegistry.registerKeyBinding(toggleProfilers);
}

static {
try {
WorldRenderer_markBlocksForUpdate = MethodHandles.publicLookup().unreflect(
ObfuscationReflectionHelper.findMethod(WorldRenderer.class, "func_184385_a",
int.class, int.class, int.class, int.class, int.class, int.class, boolean.class
)
);
} catch (Exception e) {
final CrashReport crashReport = new CrashReport("Unable to find method WorldRenderer.markBlocksForUpdate!", e);
crashReport.makeCategory("Finding Method");
throw new ReportedException(crashReport);
}
}

@Override
public void markBlocksForUpdate(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, boolean updateImmediately) {

final WorldRenderer worldRenderer = Minecraft.getInstance().worldRenderer;

if (worldRenderer.world == null || worldRenderer.viewFrustum == null) {
return;
}

try {
WorldRenderer_markBlocksForUpdate.invokeExact(worldRenderer, minX, minY, minZ, maxX, maxY, maxZ, updateImmediately);
} catch (ReportedException e) {
throw e;
} catch (Throwable throwable) {
final CrashReport crashReport = new CrashReport("Exception invoking method WorldRenderer.markBlocksForUpdate", throwable);
crashReport.makeCategory("Reflectively Invoking Method");
throw new ReportedException(crashReport);
if (worldRenderer != null && worldRenderer.world != null && worldRenderer.viewFrustum != null) {
worldRenderer.markBlocksForUpdate(minX, minY, minZ, maxX, maxY, maxZ, updateImmediately);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import io.github.cadiboo.nocubes.util.pooled.cache.XYZCache;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos.MutableBlockPos;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.IWorldReaderBase;
import net.minecraft.world.biome.BiomeColors;
import net.minecraft.world.biome.BiomeColors.ColorResolver;
import org.apache.logging.log4j.LogManager;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.cadiboo.nocubes.client.render;

import io.github.cadiboo.nocubes.client.ClientProxy;
import io.github.cadiboo.nocubes.client.LazyPackedLightCache;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.BufferBuilder;
Expand Down Expand Up @@ -28,10 +29,12 @@ public static boolean renderExtendedLiquid(
final double x, final double y, final double z,
@Nonnull final BlockPos fluidPos,
@Nonnull final IWorldReader worldIn,
//TODO: eventually do better liquid rendering for 0.3.0
//TODO: eventually do better fluid rendering for 0.3.0
@Nonnull final IBlockState smoothableState,
@Nonnull final IFluidState state,
@Nonnull final BufferBuilder buffer
@Nonnull final BufferBuilder buffer,
//TODO: eventually do better lighting for 0.3.0
@Nonnull final LazyPackedLightCache packedLightCache
) {

final SmoothLightingBlockFluidRenderer fluidRenderer = ClientProxy.fluidRenderer;
Expand All @@ -56,12 +59,12 @@ public static boolean renderExtendedLiquid(
blue = (float) (waterColor & 0xFF) / 255.0F;
}

final boolean shouldRenderUp = !isAdjacentFluidSameAs(worldIn, fluidPos, EnumFacing.UP, state);
final boolean shouldRenderDown = !isAdjacentFluidSameAs(worldIn, fluidPos, EnumFacing.DOWN, state) && !func_209556_a(worldIn, fluidPos, EnumFacing.DOWN, 0.8888889F);
final boolean shouldRenderNorth = !isAdjacentFluidSameAs(worldIn, fluidPos, EnumFacing.NORTH, state);
final boolean shouldRenderSouth = !isAdjacentFluidSameAs(worldIn, fluidPos, EnumFacing.SOUTH, state);
final boolean shouldRenderWest = !isAdjacentFluidSameAs(worldIn, fluidPos, EnumFacing.WEST, state);
final boolean shouldRenderEast = !isAdjacentFluidSameAs(worldIn, fluidPos, EnumFacing.EAST, state);
final boolean shouldRenderUp = !isAdjacentFluidSameAs(worldIn, renderPos, EnumFacing.UP, state);
final boolean shouldRenderDown = !isAdjacentFluidSameAs(worldIn, renderPos, EnumFacing.DOWN, state) && !func_209556_a(worldIn, renderPos, EnumFacing.DOWN, 0.8888889F);
final boolean shouldRenderNorth = !isAdjacentFluidSameAs(worldIn, renderPos, EnumFacing.NORTH, state);
final boolean shouldRenderSouth = !isAdjacentFluidSameAs(worldIn, renderPos, EnumFacing.SOUTH, state);
final boolean shouldRenderWest = !isAdjacentFluidSameAs(worldIn, renderPos, EnumFacing.WEST, state);
final boolean shouldRenderEast = !isAdjacentFluidSameAs(worldIn, renderPos, EnumFacing.EAST, state);

if (!shouldRenderUp && !shouldRenderDown && !shouldRenderEast && !shouldRenderWest && !shouldRenderNorth && !shouldRenderSouth) {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.cadiboo.nocubes.client.render;

import io.github.cadiboo.nocubes.client.ClientUtil;
import io.github.cadiboo.nocubes.client.LazyPackedLightCache;
import io.github.cadiboo.nocubes.config.Config;
import io.github.cadiboo.nocubes.util.ModProfiler;
import io.github.cadiboo.nocubes.util.pooled.cache.SmoothableCache;
Expand Down Expand Up @@ -34,7 +35,8 @@ public static void renderChunk(
@Nonnull final boolean[] usedBlockRenderLayers,
@Nonnull final BlockRendererDispatcher blockRendererDispatcher,
@Nonnull final StateCache stateCache,
@Nonnull final SmoothableCache smoothableCache
@Nonnull final SmoothableCache smoothableCache,
@Nonnull final LazyPackedLightCache packedLightCache
) {

try (final ModProfiler ignored = ModProfiler.get().start("render extended fluid chunk")) {
Expand Down Expand Up @@ -114,7 +116,8 @@ public static void renderChunk(
blockAccess,
blockCacheArray[stateCache.getIndex(x + xOffset + cacheAddX, y + cacheAddY, z + zOffset + cacheAddZ)],
fluidState,
bufferBuilder
bufferBuilder,
packedLightCache
);
// OptiFineCompatibility.popShaderThing(bufferBuilder);

Expand Down
Loading

0 comments on commit 0796136

Please sign in to comment.