Merge branch 'master' into 1.6.4

This commit is contained in:
CrazyPants committed 2013-09-27 14:14:19 +08:00
commit 370e82f9f3
10 files changed
+237 -52

No files matched your search

@@ -11,8 +11,10 @@ public interface ILiquidConduit extends IConduit, IFluidHandler {
static final int VOLUME_PER_CONNECTION = FluidContainerRegistry.BUCKET_VOLUME / 4;
public static final String ICON_KEY = "enderio:liquidConduit";
public static final String ICON_EMPTY_KEY = "enderio:emptyLiquidConduit";
public static final String ICON_CORE_KEY = "enderio:liquidConduitCore";
public static final String ICON_EXTRACT_KEY = "enderio:liquidConduitExtract";
public static final String ICON_EMPTY_EXTRACT_KEY = "enderio:emptyLiquidConduitExtract";
void setFluidType(FluidStack fluidType);
@@ -49,8 +49,10 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
@Override
public void registerIcons(IconRegister register) {
ICONS.put(ICON_KEY, register.registerIcon(ICON_KEY));
ICONS.put(ICON_EMPTY_KEY, register.registerIcon(ICON_EMPTY_KEY));
ICONS.put(ICON_CORE_KEY, register.registerIcon(ICON_CORE_KEY));
ICONS.put(ICON_EXTRACT_KEY, register.registerIcon(ICON_EXTRACT_KEY));
ICONS.put(ICON_EMPTY_EXTRACT_KEY, register.registerIcon(ICON_EMPTY_EXTRACT_KEY));
}
@Override
@@ -287,6 +289,7 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
liquidType = liquidType.copy();
}
tank.setLiquid(liquidType);
stateDirty = true;
}
@Override
@@ -447,6 +450,10 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
super.writeToNBT(nbtRoot);
if(tank.containsValidLiquid()) {
nbtRoot.setTag("tank", tank.getFluid().writeToNBT(new NBTTagCompound()));
} else if(getFluidType() != null) {
FluidStack ft = getFluidType().copy();
ft.amount = 0;
nbtRoot.setTag("tank", ft.writeToNBT(new NBTTagCompound()));
}
}
@@ -543,7 +550,10 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
return ICONS.get(ICON_CORE_KEY);
}
if(isExtractingFromDir(component.dir)) {
return ICONS.get(ICON_EXTRACT_KEY);
return ICONS.get(getFluidType() == null ? ICON_EMPTY_EXTRACT_KEY : ICON_EXTRACT_KEY);
}
if(getFluidType() == null) {
return ICONS.get(ICON_EMPTY_KEY);
}
return ICONS.get(ICON_KEY);
}
@@ -1,15 +1,23 @@
package crazypants.enderio.conduit.liquid;
import static crazypants.render.CubeRenderer.setupVertices;
import java.util.List;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.Icon;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import crazypants.enderio.conduit.IConduit;
import crazypants.enderio.conduit.IConduitBundle;
import crazypants.enderio.conduit.geom.CollidableComponent;
import crazypants.enderio.conduit.render.ConduitBundleRenderer;
import crazypants.enderio.conduit.render.DefaultConduitRenderer;
import crazypants.render.BoundingBox;
import crazypants.render.RenderUtil;
import crazypants.vecmath.Vector2d;
import crazypants.vecmath.Vector3d;
import crazypants.vecmath.Vector3f;
public class LiquidConduitRenderer extends DefaultConduitRenderer {
@@ -21,7 +29,7 @@ public class LiquidConduitRenderer extends DefaultConduitRenderer {
@Override
public boolean isRendererForConduit(IConduit conduit) {
if (conduit instanceof ILiquidConduit) {
if(conduit instanceof ILiquidConduit) {
return true;
}
return false;
@@ -35,19 +43,65 @@ public class LiquidConduitRenderer extends DefaultConduitRenderer {
}
@Override
protected void renderConduit(Icon tex, CollidableComponent component) {
if (isNSEWUP(component.dir)) {
protected void renderConduit(Icon tex, IConduit conduit, CollidableComponent component, float brightness) {
if(isNSEWUP(component.dir)) {
ILiquidConduit lc = (ILiquidConduit) conduit;
FluidStack fluid = lc.getFluidType();
if(fluid != null) {
renderFluidOutline(component, fluid);
}
BoundingBox[] cubes = toCubes(component.bound);
for (BoundingBox cube : cubes) {
drawSection(cube, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV(), component.dir, false);
}
} else {
drawSection(component.bound, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV(), component.dir, true);
}
}
private void renderFluidOutline(CollidableComponent component, FluidStack fluid) {
//TODO: Should cache these vertices as relatively heavy weight to calc each frame
Icon texture = fluid.getFluid().getStillIcon();
BoundingBox bbb = component.bound;
for (ForgeDirection face : ForgeDirection.VALID_DIRECTIONS) {
if(face != component.dir && face != component.dir.getOpposite()) {
Tessellator tes = Tessellator.instance;
tes.setNormal(face.offsetX, face.offsetY, face.offsetZ);
float scaleFactor = 14f / 16f;
Vector2d uv = new Vector2d();
List<ForgeDirection> edges = RenderUtil.getEdgesForFace(face);
for (ForgeDirection edge : edges) {
if(edge != component.dir && edge != component.dir.getOpposite()) {
float xLen = 1 - Math.abs(edge.offsetX) * scaleFactor;
float yLen = 1 - Math.abs(edge.offsetY) * scaleFactor;
float zLen = 1 - Math.abs(edge.offsetZ) * scaleFactor;
BoundingBox bb = bbb.scale(xLen, yLen, zLen);
List<Vector3f> corners = bb.getCornersForFace(face);
for (Vector3f unitCorn : corners) {
Vector3d corner = new Vector3d(unitCorn);
corner.x += (float) (edge.offsetX * 0.5 * bbb.sizeX()) - (Math.signum(edge.offsetX) * xLen / 2f * bbb.sizeX()) * 2f;
corner.y += (float) (edge.offsetY * 0.5 * bbb.sizeY()) - (Math.signum(edge.offsetY) * yLen / 2f * bbb.sizeY()) * 2f;
corner.z += (float) (edge.offsetZ * 0.5 * bbb.sizeZ()) - (Math.signum(edge.offsetZ) * zLen / 2f * bbb.sizeZ()) * 2f;
RenderUtil.getUvForCorner(uv, corner, 0, 0, 0, face, texture);
tes.addVertexWithUV(corner.x, corner.y, corner.z, uv.x, uv.y);
}
}
}
}
}
}
@Override
protected void renderTransmission(Icon tex, CollidableComponent component) {
protected void renderTransmission(Icon tex, CollidableComponent component, float brightness) {
BoundingBox[] cubes = toCubes(component.bound);
for (BoundingBox cube : cubes) {
drawSection(cube, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV(), component.dir, true);
@@ -76,30 +130,30 @@ public class LiquidConduitRenderer extends DefaultConduitRenderer {
int totalAmount = tank.getFluidAmount();
int upCapacity = 0;
if (conduit.containsConduitConnection(ForgeDirection.UP) || conduit.containsExternalConnection(ForgeDirection.UP)) {
if(conduit.containsConduitConnection(ForgeDirection.UP) || conduit.containsExternalConnection(ForgeDirection.UP)) {
upCapacity = ILiquidConduit.VOLUME_PER_CONNECTION;
}
int downCapacity = 0;
if (conduit.containsConduitConnection(ForgeDirection.DOWN) || conduit.containsExternalConnection(ForgeDirection.DOWN)) {
if(conduit.containsConduitConnection(ForgeDirection.DOWN) || conduit.containsExternalConnection(ForgeDirection.DOWN)) {
downCapacity = ILiquidConduit.VOLUME_PER_CONNECTION;
}
int flatCapacity = tank.getCapacity() - upCapacity - downCapacity;
int usedCapacity = 0;
if (downCapacity > 0) {
if(downCapacity > 0) {
int inDown = Math.min(totalAmount, downCapacity);
usedCapacity += inDown;
downRatio = (float) inDown / downCapacity;
}
if (flatCapacity > 0 && usedCapacity < totalAmount) {
if(flatCapacity > 0 && usedCapacity < totalAmount) {
int inFlat = Math.min(flatCapacity, totalAmount - usedCapacity);
usedCapacity += inFlat;
flatRatio = (float) inFlat / flatCapacity;
} else {
flatRatio = 0;
}
if (upCapacity > 0 && usedCapacity < totalAmount) {
if(upCapacity > 0 && usedCapacity < totalAmount) {
int inUp = Math.min(upCapacity, totalAmount - usedCapacity);
upRatio = (float) inUp / upCapacity;
} else {
@@ -109,10 +163,10 @@ public class LiquidConduitRenderer extends DefaultConduitRenderer {
}
private float getRatioForConnection(ForgeDirection id) {
if (id == ForgeDirection.UP) {
if(id == ForgeDirection.UP) {
return upRatio;
}
if (id == ForgeDirection.DOWN) {
if(id == ForgeDirection.DOWN) {
return downRatio;
}
return flatRatio;
@@ -41,20 +41,20 @@ public class DefaultConduitRenderer implements ConduitRenderer {
Icon tex;
boolean active = conduit.isActive();
for (CollidableComponent component : components) {
if (renderComponent(component)) {
if(renderComponent(component)) {
float selfIllum = Math.max(worldLight, conduit.getSelfIlluminationForState(component));
if (active && isNSEWUP(component.dir) &&
if(active && isNSEWUP(component.dir) &&
conduit.getTransmitionTextureForState(component) != null) {
tessellator.setColorRGBA_F(selfIllum + 0.1f, selfIllum + 0.1f,
selfIllum + 0.1f, 0.75f);
tex = conduit.getTransmitionTextureForState(component);
renderTransmission(tex, component);
renderTransmission(tex, component, selfIllum);
}
tex = conduit.getTextureForState(component);
if(tex != null) {
tessellator.setColorOpaque_F(selfIllum, selfIllum, selfIllum);
renderConduit(tex, component);
renderConduit(tex, conduit, component, selfIllum);
}
}
@@ -62,15 +62,15 @@ public class DefaultConduitRenderer implements ConduitRenderer {
}
protected void renderConduit(Icon tex, CollidableComponent component) {
if (isNSEWUP(component.dir)) {
protected void renderConduit(Icon tex, IConduit conduit, CollidableComponent component, float selfIllum) {
if(isNSEWUP(component.dir)) {
RoundedSegmentRenderer.renderSegment(component.dir, component.bound, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV());
} else {
drawSection(component.bound, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV(), component.dir, true);
}
}
protected void renderTransmission(Icon tex, CollidableComponent component) {
protected void renderTransmission(Icon tex, CollidableComponent component, float selfIllum) {
RoundedSegmentRenderer.renderSegment(component.dir, component.bound, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV());
}
@@ -88,12 +88,12 @@ public class DefaultConduitRenderer implements ConduitRenderer {
Tessellator tessellator = Tessellator.instance;
if (isTransmission) {
if(isTransmission) {
setVerticesForTransmission(bound, dir);
}
if (dir == NORTH || dir == UP || dir == EAST) { // maintain consistent
// texture
if(dir == NORTH || dir == UP || dir == EAST) { // maintain consistent
// texture
// dir relative to the cneter
// of the conduit
float tmp = minU;
@@ -104,9 +104,9 @@ public class DefaultConduitRenderer implements ConduitRenderer {
boolean rotateSides = dir == UP || dir == DOWN;
boolean rotateTopBottom = dir == NORTH || dir == SOUTH;
if (dir != NORTH && dir != SOUTH) {
if(dir != NORTH && dir != SOUTH) {
tessellator.setNormal(0, 0, -1);
if (rotateSides) {
if(rotateSides) {
addVecWithUV(verts[1], maxU, maxV);
addVecWithUV(verts[0], maxU, minV);
addVecWithUV(verts[3], minU, minV);
@@ -117,13 +117,13 @@ public class DefaultConduitRenderer implements ConduitRenderer {
addVecWithUV(verts[3], maxU, maxV);
addVecWithUV(verts[2], minU, maxV);
}
if (dir == WEST || dir == EAST) {
if(dir == WEST || dir == EAST) {
float tmp = minU;
minU = maxU;
maxU = tmp;
}
tessellator.setNormal(0, 0, 1);
if (rotateSides) {
if(rotateSides) {
addVecWithUV(verts[4], maxU, maxV);
addVecWithUV(verts[5], maxU, minV);
addVecWithUV(verts[6], minU, minV);
@@ -134,17 +134,17 @@ public class DefaultConduitRenderer implements ConduitRenderer {
addVecWithUV(verts[6], maxU, maxV);
addVecWithUV(verts[7], minU, maxV);
}
if (dir == WEST || dir == EAST) {
if(dir == WEST || dir == EAST) {
float tmp = minU;
minU = maxU;
maxU = tmp;
}
}
if (dir != UP && dir != DOWN) {
if(dir != UP && dir != DOWN) {
tessellator.setNormal(0, 1, 0);
if (rotateTopBottom) {
if(rotateTopBottom) {
addVecWithUV(verts[6], maxU, maxV);
addVecWithUV(verts[2], minU, maxV);
addVecWithUV(verts[3], minU, minV);
@@ -157,7 +157,7 @@ public class DefaultConduitRenderer implements ConduitRenderer {
}
tessellator.setNormal(0, -1, 0);
if (rotateTopBottom) {
if(rotateTopBottom) {
addVecWithUV(verts[0], minU, minV);
addVecWithUV(verts[1], minU, maxV);
addVecWithUV(verts[5], maxU, maxV);
@@ -170,7 +170,7 @@ public class DefaultConduitRenderer implements ConduitRenderer {
}
}
if (dir != EAST && dir != WEST) {
if(dir != EAST && dir != WEST) {
// if(id == NORTH) {
// float tmp = minU;
@@ -179,7 +179,7 @@ public class DefaultConduitRenderer implements ConduitRenderer {
// }
tessellator.setNormal(1, 0, 0);
if (rotateSides) {
if(rotateSides) {
addVecWithUV(verts[2], minU, maxV);
addVecWithUV(verts[6], minU, minV);
addVecWithUV(verts[5], maxU, minV);
@@ -192,7 +192,7 @@ public class DefaultConduitRenderer implements ConduitRenderer {
}
tessellator.setNormal(-1, 0, 0);
if (rotateSides) {
if(rotateSides) {
addVecWithUV(verts[0], maxU, maxV);
addVecWithUV(verts[4], maxU, minV);
addVecWithUV(verts[7], minU, minV);
@@ -222,10 +222,10 @@ public class DefaultConduitRenderer implements ConduitRenderer {
float height = bb.maxY - bb.minY;
float depth = bb.maxZ - bb.minZ;
if (width > 0 && height > 0 && depth > 0) {
if (width / depth > 1.5f || depth / width > 1.5f) {
if(width > 0 && height > 0 && depth > 0) {
if(width / depth > 1.5f || depth / width > 1.5f) {
// split horizontally
if (width > depth) {
if(width > depth) {
int numSplits = Math.round(width / depth);
float newWidth = width / numSplits;
BoundingBox[] result = new BoundingBox[numSplits];
@@ -252,7 +252,7 @@ public class DefaultConduitRenderer implements ConduitRenderer {
}
} else if (height / width > 1.5) {
} else if(height / width > 1.5) {
int numSplits = Math.round(height / width);
float newWidth = height / numSplits;
+33 -15
View File
@@ -2,32 +2,51 @@ package crazypants.render;
import java.awt.Color;
import crazypants.vecmath.Vector3f;
import crazypants.vecmath.Vector4f;
public final class ColorUtil {
public static Vector4f toFloat(Color color) {
float[] rgba = color.getComponents(null);
return new Vector4f(rgba[0], rgba[1], rgba[2], rgba[3]);
}
public static Vector3f toFloat(int rgb) {
int r = rgb >> 16 & 255;
int g = rgb >> 8 & 255;
int b = rgb & 255;
return new Vector3f(r / 255F, g / 255F, b / 255F);
}
public static int getRGB(Color color) {
return getRGB(color.getRed(),color.getGreen(),color.getBlue());
return getRGB(color.getRed(), color.getGreen(), color.getBlue());
}
public static int getRGBA(Color color) {
return getRGBA(color.getRed(),color.getGreen(),color.getBlue(), color.getAlpha());
return getRGBA(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}
public static int getARGB(Color color) {
return getRGBA(color.getAlpha(), color.getRed(),color.getGreen(),color.getBlue());
return getRGBA(color.getAlpha(), color.getRed(), color.getGreen(), color.getBlue());
}
public static int getRGB(Vector3f rgb) {
return getRGB(rgb.x, rgb.y, rgb.z);
}
public static int getRGB(float r, float g, float b) {
return getRGB((int)(r * 255), (int)(g * 255),(int)(b * 255));
return getRGB((int) (r * 255), (int) (g * 255), (int) (b * 255));
}
public static int getRGBA(float r, float g, float b, float a) {
return getRGBA((int)(r * 255), (int)(g * 255),(int)(b * 255),(int)(a * 255));
return getRGBA((int) (r * 255), (int) (g * 255), (int) (b * 255), (int) (a * 255));
}
public static int getARGB(float r, float g, float b, float a) {
return getARGB((int)(a * 255), (int)(r * 255), (int)(g * 255),(int)(b * 255));
return getARGB((int) (a * 255), (int) (r * 255), (int) (g * 255), (int) (b * 255));
}
public static int getRGB(int r, int g, int b) {
return (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF);
}
@@ -40,8 +59,7 @@ public final class ColorUtil {
return (r & 0xFF) << 24 | (g & 0xFF) << 16 | (b & 0xFF) << 8 | (a & 0xFF);
}
private ColorUtil() {
private ColorUtil() {
}
}
+101
View File
@@ -0,0 +1,101 @@
package crazypants.vecmath;
public class Vector4f {
public float x;
public float y;
public float z;
public float w;
public Vector4f() {
x = 0;
y = 0;
z = 0;
w = 0;
}
public Vector4f(float x, float y, float z, float w) {
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
public Vector4f(double x, double y, double z, double w) {
this.x = (float) x;
this.y = (float) y;
this.z = (float) z;
this.w = (float) w;
}
public Vector4f(Vector4f other) {
this(other.x, other.y, other.z, other.w);
}
public void set(Vector4f vec) {
x = vec.x;
y = vec.y;
z = vec.z;
w = vec.w;
}
public void set(float x, float y, float z, float w) {
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
public void add(Vector4f vec) {
x += vec.x;
y += vec.y;
z += vec.z;
w += vec.w;
}
public void sub(Vector4f vec) {
x -= vec.x;
y -= vec.y;
z -= vec.z;
w -= vec.w;
}
public void negate() {
x = -x;
y = -y;
z = -z;
w = -w;
}
public void scale(double s) {
x *= s;
y *= s;
z *= s;
w *= s;
}
public void normalize() {
double scale = 1.0 / Math.sqrt(x * x + y * y + z * z + w * w);
scale(scale);
}
public double dot(Vector4f other) {
return x * other.x + y * other.y + z * other.z + w * other.w;
}
public double lengthSquared() {
return x * x + y * y + z * z + w * w;
}
public double length() {
return Math.sqrt(lengthSquared());
}
public Vector3f toVector3f() {
return new Vector3f(x, y, z);
}
@Override
public String toString() {
return "Vector4f(" + x + ", " + y + ", " + z + ", " + w + ")";
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 257 B

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 331 B

After

Width:  |  Height:  |  Size: 318 B