Connected transmitter textures without any additional model groups, merely texture replacement and UV transformation

This commit is contained in:
aidancbrady committed 2016-05-24 17:32:12 -04:00
1 parent 6c8fec9e25
commit 05c4967f0f
32 files changed
+212 -47

No files matched your search

@@ -27,6 +27,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.model.ModelBakery;
@@ -295,6 +296,43 @@ public class MekanismRenderer
}
}
public static BakedQuad iconTransform(BakedQuad quad, TextureAtlasSprite sprite)
{
int[] vertices = new int[28];
System.arraycopy(quad.getVertexData(), 0, vertices, 0, vertices.length);
vertices[4] = Float.floatToRawIntBits(sprite.getInterpolatedU(16));
vertices[5] = Float.floatToRawIntBits(sprite.getInterpolatedV(16));
vertices[7+4] = Float.floatToRawIntBits(sprite.getInterpolatedU(16));
vertices[7+5] = Float.floatToRawIntBits(sprite.getInterpolatedV(0));
vertices[14+4] = Float.floatToRawIntBits(sprite.getInterpolatedU(0));
vertices[14+5] = Float.floatToRawIntBits(sprite.getInterpolatedV(0));
vertices[21+4] = Float.floatToRawIntBits(sprite.getInterpolatedU(0));
vertices[21+5] = Float.floatToRawIntBits(sprite.getInterpolatedV(16));
return new BakedQuad(vertices, quad.getTintIndex(), quad.getFace());
}
public static BakedQuad rotate(BakedQuad quad, int amount)
{
int[] vertices = new int[28];
System.arraycopy(quad.getVertexData(), 0, vertices, 0, vertices.length);
int[][] uvs = new int[4][2];
for(int i = 0; i < 4; i++)
{
int nextIndex = i+amount%4;
vertices[7*i + 4] = quad.getVertexData()[7*nextIndex + 4];
vertices[7*i + 5] = quad.getVertexData()[7*nextIndex + 5];
}
return new BakedQuad(vertices, quad.getTintIndex(), quad.getFace());
}
public static void prepFlowing(Model3D model, Fluid fluid)
{
TextureAtlasSprite still = getFluidTexture(fluid, FluidType.STILL);
@@ -11,6 +11,7 @@ import java.util.Set;
import javax.vecmath.Matrix4f;
import mekanism.client.render.MekanismRenderer;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@@ -137,18 +138,28 @@ public abstract class OBJBakedModelBase extends OBJBakedModel
color = getOverrideColor(f, groupName);
}
EnumFacing facing = EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z);
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(getFormat());
builder.setQuadOrientation(EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z));
builder.setQuadOrientation(facing);
builder.setQuadColored();
builder.setQuadTint(0);
Normal faceNormal = f.getNormal();
boolean rotate = shouldRotate(f, groupName);
putVertexData(builder, f.getVertices()[0], faceNormal, TextureCoordinate.getDefaultUVs()[0], tempSprite, getFormat(), color);
putVertexData(builder, f.getVertices()[1], faceNormal, TextureCoordinate.getDefaultUVs()[1], tempSprite, getFormat(), color);
putVertexData(builder, f.getVertices()[2], faceNormal, TextureCoordinate.getDefaultUVs()[2], tempSprite, getFormat(), color);
putVertexData(builder, f.getVertices()[3], faceNormal, TextureCoordinate.getDefaultUVs()[3], tempSprite, getFormat(), color);
BakedQuad quad = builder.build();
bakedQuads.add(builder.build());
if(rotate)
{
quad = MekanismRenderer.rotate(quad, 1);
}
bakedQuads.add(quad);
}
}
@@ -263,4 +274,9 @@ public abstract class OBJBakedModelBase extends OBJBakedModel
{
return null;
}
protected boolean shouldRotate(Face f, String groupName)
{
return false;
}
}
@@ -7,7 +7,11 @@ import java.util.Objects;
import javax.vecmath.Matrix4f;
import mcmultipart.client.multipart.ISmartMultipartModel;
import mekanism.api.MekanismConfig.client;
import mekanism.common.multipart.ColorProperty;
import mekanism.common.multipart.ConnectionProperty;
import mekanism.common.multipart.PartSidedPipe;
import mekanism.common.multipart.PartSidedPipe.ConnectionType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@@ -15,6 +19,7 @@ import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.MinecraftForgeClient;
@@ -85,11 +90,14 @@ public class TransmitterModel extends OBJBakedModelBase implements ISmartMultipa
@Override
public float[] getOverrideColor(Face f, String groupName)
{
ColorProperty prop = ((IExtendedBlockState)tempState).getValue(ColorProperty.INSTANCE);
if(MinecraftForgeClient.getRenderLayer() == EnumWorldBlockLayer.TRANSLUCENT && prop != null && prop.color != null)
if(tempState != null)
{
return new float[] {prop.color.getColor(0), prop.color.getColor(1), prop.color.getColor(2), 1};
ColorProperty prop = ((IExtendedBlockState)tempState).getValue(ColorProperty.INSTANCE);
if(MinecraftForgeClient.getRenderLayer() == EnumWorldBlockLayer.TRANSLUCENT && prop != null && prop.color != null)
{
return new float[] {prop.color.getColor(0), prop.color.getColor(1), prop.color.getColor(2), 1};
}
}
return null;
@@ -98,22 +106,93 @@ public class TransmitterModel extends OBJBakedModelBase implements ISmartMultipa
@Override
public TextureAtlasSprite getOverrideTexture(Face f, String groupName)
{
ColorProperty prop = ((IExtendedBlockState)tempState).getValue(ColorProperty.INSTANCE);
if(MinecraftForgeClient.getRenderLayer() == EnumWorldBlockLayer.TRANSLUCENT)
if(tempState != null)
{
if(prop != null && prop.color != null)
EnumFacing side = EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z);
ColorProperty prop = ((IExtendedBlockState)tempState).getValue(ColorProperty.INSTANCE);
ConnectionProperty connection = ((IExtendedBlockState)tempState).getValue(ConnectionProperty.INSTANCE);
boolean sideIconOverride = getIconStatus(side, connection) > 0;
if(MinecraftForgeClient.getRenderLayer() == EnumWorldBlockLayer.TRANSLUCENT)
{
return f.getMaterialName().contains("Center") ? transporter_center_color : transporter_side_color;
if(prop != null && prop.color != null)
{
return (!sideIconOverride && f.getMaterialName().contains("Center")) ? transporter_center_color : transporter_side_color;
}
else {
return (!sideIconOverride && f.getMaterialName().contains("Center")) ? transporter_center : transporter_side;
}
}
else {
return f.getMaterialName().contains("Center") ? transporter_center : transporter_side;
if(groupName.endsWith("NONE") && sideIconOverride)
{
for(Group g : getModel().getMatLib().getGroups().values())
{
for(Face testFace : g.getFaces())
{
String s = testFace.getMaterialName();
if(!s.contains("Center") && !s.contains("Centre"))
{
return textureMap.get(s);
}
}
}
}
}
}
return null;
}
@Override
public boolean shouldRotate(Face f, String groupName)
{
if(tempState != null)
{
EnumFacing side = EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z);
ConnectionProperty connection = ((IExtendedBlockState)tempState).getValue(ConnectionProperty.INSTANCE);
if(groupName.endsWith("NONE") && getIconStatus(side, connection) == 2)
{
return true;
}
}
return false;
}
public byte getIconStatus(EnumFacing side, ConnectionProperty connection)
{
ConnectionType type = PartSidedPipe.getConnectionType(side, connection.connectionByte, connection.transmitterConnections, connection.connectionTypes);
if(type == ConnectionType.NONE)
{
if(client.oldTransmitterRender || connection.renderCenter)
{
return (byte)0;
}
else if(connection.connectionByte == 3 && side != EnumFacing.DOWN && side != EnumFacing.UP)
{
return (byte)1;
}
else if(connection.connectionByte == 12 && (side == EnumFacing.DOWN || side == EnumFacing.UP))
{
return (byte)1;
}
else if(connection.connectionByte == 12 && (side == EnumFacing.EAST || side == EnumFacing.WEST))
{
return (byte)2;
}
else if(connection.connectionByte == 48 && side != EnumFacing.EAST && side != EnumFacing.WEST)
{
return (byte)2;
}
}
return (byte)0;
}
public static void registerIcons(TextureMap map)
{
transporter_center = map.registerSprite(new ResourceLocation("mekanism:blocks/models/multipart/LogisticalTransporterGlass"));
@@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map;
import mcmultipart.client.multipart.MultipartSpecialRenderer;
import mekanism.client.render.MekanismRenderer;
import mekanism.common.ColourRGBA;
import mekanism.common.multipart.PartTransmitter;
import mekanism.common.util.MekanismUtils;
@@ -73,7 +74,7 @@ public abstract class RenderTransmitterBase<T extends PartTransmitter> extends M
for(BakedQuad quad : cc.getGeneralQuads())
{
quad = iconTransform(quad, icon);
quad = MekanismRenderer.iconTransform(quad, icon);
LightUtil.renderQuadColor(renderer, quad, color.argb());
}
}
@@ -116,26 +117,6 @@ public abstract class RenderTransmitterBase<T extends PartTransmitter> extends M
return DummyAtlasTextureFlipV.instance;
}
};
public static BakedQuad iconTransform(BakedQuad quad, TextureAtlasSprite sprite)
{
int[] vertices = new int[28];
System.arraycopy(quad.getVertexData(), 0, vertices, 0, vertices.length);
vertices[4] = Float.floatToRawIntBits(sprite.getInterpolatedU(16));
vertices[5] = Float.floatToRawIntBits(sprite.getInterpolatedV(16));
vertices[7+4] = Float.floatToRawIntBits(sprite.getInterpolatedU(16));
vertices[7+5] = Float.floatToRawIntBits(sprite.getInterpolatedV(0));
vertices[14+4] = Float.floatToRawIntBits(sprite.getInterpolatedU(0));
vertices[14+5] = Float.floatToRawIntBits(sprite.getInterpolatedV(0));
vertices[21+4] = Float.floatToRawIntBits(sprite.getInterpolatedU(0));
vertices[21+5] = Float.floatToRawIntBits(sprite.getInterpolatedV(16));
return new BakedQuad(vertices, quad.getTintIndex(), quad.getFace());
}
private static class DummyAtlasTextureFlipV extends TextureAtlasSprite
{
@@ -0,0 +1,50 @@
package mekanism.common.multipart;
import mekanism.common.multipart.PartSidedPipe.ConnectionType;
import net.minecraftforge.common.property.IUnlistedProperty;
import scala.actors.threadpool.Arrays;
public class ConnectionProperty implements IUnlistedProperty<ConnectionProperty>
{
public static ConnectionProperty INSTANCE = new ConnectionProperty();
public byte connectionByte;
public byte transmitterConnections;
public ConnectionType[] connectionTypes;
public boolean renderCenter;
public ConnectionProperty() {}
public ConnectionProperty(byte b, byte b1, ConnectionType[] types, boolean center)
{
connectionByte = b;
transmitterConnections = b1;
connectionTypes = types;
renderCenter = center;
}
@Override
public String getName()
{
return "connection";
}
@Override
public boolean isValid(ConnectionProperty value)
{
return true;
}
@Override
public Class getType()
{
return getClass();
}
@Override
public String valueToString(ConnectionProperty value)
{
return Byte.toString(connectionByte) + "_" + Byte.toString(transmitterConnections) + "_"
+ Arrays.toString(connectionTypes) + "_" + renderCenter;
}
}
@@ -796,16 +796,21 @@ public abstract class PartSidedPipe extends Multipart implements IOccludingPart,
public ConnectionType getConnectionType(EnumFacing side)
{
if(!connectionMapContainsSide(getAllCurrentConnections(), side))
return getConnectionType(side, getAllCurrentConnections(), currentTransmitterConnections, connectionTypes);
}
public static ConnectionType getConnectionType(EnumFacing side, byte allConnections, byte transmitterConnections, ConnectionType[] types)
{
if(!connectionMapContainsSide(allConnections, side))
{
return ConnectionType.NONE;
}
else if(connectionMapContainsSide(currentTransmitterConnections, side))
else if(connectionMapContainsSide(transmitterConnections, side))
{
return ConnectionType.NORMAL;
}
return connectionTypes[side.ordinal()];
return types[side.ordinal()];
}
public List<EnumFacing> getConnections(ConnectionType type)
@@ -922,7 +927,7 @@ public abstract class PartSidedPipe extends Multipart implements IOccludingPart,
@Override
public BlockState createBlockState()
{
return new ExtendedBlockState(MCMultiPartMod.multipart, new IProperty[0], new IUnlistedProperty[] {OBJProperty.instance, ColorProperty.INSTANCE});
return new ExtendedBlockState(MCMultiPartMod.multipart, new IProperty[0], new IUnlistedProperty[] {OBJProperty.instance, ColorProperty.INSTANCE, ConnectionProperty.INSTANCE});
}
public List<String> getVisibleGroups()
@@ -940,7 +945,9 @@ public abstract class PartSidedPipe extends Multipart implements IOccludingPart,
@Override
public IBlockState getExtendedState(IBlockState state)
{
return ((IExtendedBlockState)state).withProperty(OBJProperty.instance, new OBJState(getVisibleGroups(), true));
ConnectionProperty connectionProp = new ConnectionProperty(getAllCurrentConnections(), currentTransmitterConnections, connectionTypes, renderCenter());
return ((IExtendedBlockState)state).withProperty(OBJProperty.instance, new OBJState(getVisibleGroups(), true)).withProperty(ConnectionProperty.INSTANCE, connectionProp);
}
@Override