Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexIIL committed Jan 11, 2017
1 parent b46c9db commit 1a9e4c3
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import buildcraft.factory.tile.TileFloodGate;
import buildcraft.lib.client.render.DetatchedRenderer.IDetachedRenderer;
import buildcraft.lib.debug.BCAdvDebugging;
import buildcraft.lib.debug.DebugRenderHelper;

public class AdvDebuggerFloodGate implements IDetachedRenderer {
public final TileFloodGate target;
Expand All @@ -37,7 +37,7 @@ public void render(EntityPlayer player, float partialTicks) {
Deque<BlockPos> positions = entry.getValue();
for (BlockPos p : positions) {
int colour = 0xFF_00_00_00 | (r << 16) | (g << 8) | b;
BCAdvDebugging.renderSmallCuboid(vb, p, colour);
DebugRenderHelper.renderSmallCuboid(vb, p, colour);
r -= 16;
if (r < 0) {
r = 256;
Expand Down
4 changes: 2 additions & 2 deletions common/buildcraft/lib/BCLibProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import buildcraft.lib.client.render.DetatchedRenderer.RenderMatrixType;
import buildcraft.lib.client.render.MarkerRenderer;
import buildcraft.lib.client.resource.ResourceRegistry;
import buildcraft.lib.debug.BCAdvDebugging;
import buildcraft.lib.debug.DebugRenderHelper;
import buildcraft.lib.fluid.BCFluid;
import buildcraft.lib.fluid.FluidManager;
import buildcraft.lib.item.IItemBuildCraft;
Expand Down Expand Up @@ -112,7 +112,7 @@ public void postRegisterFluid(BCFluid fluid) {
void fmlPreInit() {
super.fmlPreInit();
DetatchedRenderer.INSTANCE.addRenderer(RenderMatrixType.FROM_WORLD_ORIGIN, MarkerRenderer.INSTANCE);
DetatchedRenderer.INSTANCE.addRenderer(RenderMatrixType.FROM_WORLD_ORIGIN, BCAdvDebugging.INSTANCE);
DetatchedRenderer.INSTANCE.addRenderer(RenderMatrixType.FROM_WORLD_ORIGIN, DebugRenderHelper.INSTANCE);
// various sprite registers
BCLibSprites.fmlPreInitClient();
}
Expand Down
61 changes: 4 additions & 57 deletions common/buildcraft/lib/debug/BCAdvDebugging.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
package buildcraft.lib.debug;

import javax.vecmath.Point3f;
import javax.vecmath.Tuple3f;

import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;

import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import buildcraft.lib.client.model.ModelUtil;
import buildcraft.lib.client.model.MutableQuad;
import buildcraft.lib.client.render.DetatchedRenderer.IDetachedRenderer;

public enum BCAdvDebugging implements IDetachedRenderer {
/** Holds the current {@link IAdvDebugTarget}. Use {@link DebugRenderHelper} for helpers when rendering
* debuggables. */
public enum BCAdvDebugging {
INSTANCE;

private static final MutableQuad[] smallCuboid;

private IAdvDebugTarget target = null;
private IAdvDebugTarget targetClient = null;

static {
smallCuboid = new MutableQuad[6];
Tuple3f center = new Point3f(0.5f, 0.5f, 0.5f);
Tuple3f radius = new Point3f(0.25f, 0.25f, 0.25f);

for (EnumFacing face : EnumFacing.VALUES) {
MutableQuad quad = ModelUtil.createFace(face, center, radius, null);
quad.lightf(1, 1);
smallCuboid[face.ordinal()] = quad;
}
}
IAdvDebugTarget targetClient = null;

public static boolean isBeingDebugged(IAdvDebugTarget target) {
return INSTANCE.target == target;
Expand All @@ -61,29 +33,4 @@ public void onServerPostTick() {
}
}
}

@Override
@SideOnly(Side.CLIENT)
public void render(EntityPlayer player, float partialTicks) {
if (targetClient == null) {
return;
} else if (!targetClient.doesExistInWorld()) {
// targetClient = null;
// return;
}
IDetachedRenderer renderer = targetClient.getDebugRenderer();
if (renderer != null) {
renderer.render(player, partialTicks);
}
}

public static void renderSmallCuboid(VertexBuffer vb, BlockPos pos, int colour) {
vb.setTranslation(pos.getX(), pos.getY(), pos.getZ());
for (MutableQuad q : smallCuboid) {
q.texFromSprite(ModelLoader.White.INSTANCE);
q.colouri(colour);
q.render(vb);
}
vb.setTranslation(0, 0, 0);
}
}
61 changes: 61 additions & 0 deletions common/buildcraft/lib/debug/DebugRenderHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package buildcraft.lib.debug;

import javax.vecmath.Point3f;
import javax.vecmath.Tuple3f;

import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;

import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import buildcraft.lib.client.model.ModelUtil;
import buildcraft.lib.client.model.MutableQuad;
import buildcraft.lib.client.render.DetatchedRenderer.IDetachedRenderer;

public enum DebugRenderHelper implements IDetachedRenderer {
INSTANCE;

private static final MutableQuad[] smallCuboid;

static {
smallCuboid = new MutableQuad[6];
Tuple3f center = new Point3f(0.5f, 0.5f, 0.5f);
Tuple3f radius = new Point3f(0.25f, 0.25f, 0.25f);

for (EnumFacing face : EnumFacing.VALUES) {
MutableQuad quad = ModelUtil.createFace(face, center, radius, null);
quad.lightf(1, 1);
smallCuboid[face.ordinal()] = quad;
}
}

@Override
@SideOnly(Side.CLIENT)
public void render(EntityPlayer player, float partialTicks) {
IAdvDebugTarget target = BCAdvDebugging.INSTANCE.targetClient;
if (target == null) {
return;
} else if (!target.doesExistInWorld()) {
// targetClient = null;
// return;
}
IDetachedRenderer renderer = target.getDebugRenderer();
if (renderer != null) {
renderer.render(player, partialTicks);
}
}

public static void renderSmallCuboid(VertexBuffer vb, BlockPos pos, int colour) {
vb.setTranslation(pos.getX(), pos.getY(), pos.getZ());
for (MutableQuad q : smallCuboid) {
q.texFromSprite(ModelLoader.White.INSTANCE);
q.colouri(colour);
q.render(vb);
}
vb.setTranslation(0, 0, 0);
}
}
10 changes: 10 additions & 0 deletions common/buildcraft/lib/debug/IAdvDebugTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@

import buildcraft.lib.client.render.DetatchedRenderer.IDetachedRenderer;

/** Something that can be put into an "advanced debug" state - every tick {@link #sendDebugState()} will be called on
* the server, to allow the client to render all of the details normally hidden on the server. */
public interface IAdvDebugTarget {
/** Called when the current debug target changes from this to something else (or to nothing). This should inform the
* client that it is no longer being debugged. */
void disableDebugging();

/** Called every tick on the server to see if this still exists in the world. If this returns false then
* {@link #disableDebugging()} will be called, and the current debug target will be removed. */
boolean doesExistInWorld();

/** Called every tick on the server to send all the debug information to the client. */
void sendDebugState();

/** Called on the client to actually render off the target. Note that this might not be called every frame this this
* is rendered, so the returned render should always correctly render the current debug target, provided that
* {@link #doesExistInWorld()} returns true. */
@SideOnly(Side.CLIENT)
IDetachedRenderer getDebugRenderer();
}

0 comments on commit 1a9e4c3

Please sign in to comment.