Basics of "painted" panels

This commit is contained in:
malte0811 2019-01-11 15:05:39 +01:00
parent c84a0476fd
commit ceb28da474
4 changed files with 35 additions and 11 deletions

View file

@ -34,6 +34,7 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.ITickable; import net.minecraft.util.ITickable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
@ -139,6 +140,9 @@ public class TileEntityPanel extends TileEntityGeneralCP implements IDirectional
} }
} }
components.setHeight(nbt.getFloat("height")); components.setHeight(nbt.getFloat("height"));
if (nbt.hasKey("texture")) {
components.setTexture(new ResourceLocation(nbt.getString("texture")));
}
components.setAngle(nbt.getFloat("angle")); components.setAngle(nbt.getFloat("angle"));
} }
defAABB = null; defAABB = null;
@ -154,6 +158,7 @@ public class TileEntityPanel extends TileEntityGeneralCP implements IDirectional
nbt.setTag("components", comps); nbt.setTag("components", comps);
nbt.setFloat("height", components.getHeight()); nbt.setFloat("height", components.getHeight());
nbt.setFloat("angle", components.getAngle()); nbt.setFloat("angle", components.getAngle());
nbt.setString("texture", components.getTexture().toString());
} }
@Nonnull @Nonnull

View file

@ -41,7 +41,6 @@ public abstract class TileEntityRSPanel extends TileEntityGeneralCP implements I
} }
private void updateChannelsArray() { private void updateChannelsArray() {
byte[] oldIn = currInput;
if (world == null || !world.isRemote) { if (world == null || !world.isRemote) {
panelNetwork.removeIOFor(this); panelNetwork.removeIOFor(this);
for (byte i = 0; i < 16; i++) { for (byte i = 0; i < 16; i++) {
@ -69,8 +68,12 @@ public abstract class TileEntityRSPanel extends TileEntityGeneralCP implements I
@Override @Override
public void readNBT(NBTTagCompound nbt, boolean updatePacket) { public void readNBT(NBTTagCompound nbt, boolean updatePacket) {
out = nbt.getByteArray("out"); if (nbt.hasKey("out") && nbt.getByteArray("out").length == 16) {
currInput = nbt.getByteArray("in"); out = nbt.getByteArray("out");
}
if (nbt.hasKey("in") && nbt.getByteArray("in").length == 16) {
currInput = nbt.getByteArray("in");
}
controller = nbt.getInteger("rsId"); controller = nbt.getInteger("rsId");
updateChannelsArray(); updateChannelsArray();
} }

View file

@ -25,6 +25,7 @@ import malte0811.industrialwires.controlpanel.PropertyComponents.PanelRenderProp
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.item.EnumDyeColor; import net.minecraft.item.EnumDyeColor;
@ -61,9 +62,11 @@ public final class PanelUtils {
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public static List<BakedQuad> generateQuads(PanelRenderProperties components) { public static List<BakedQuad> generateQuads(PanelRenderProperties components) {
TextureMap texMap = Minecraft.getMinecraft().getTextureMapBlocks();
if (PANEL_TEXTURE == null) { if (PANEL_TEXTURE == null) {
PANEL_TEXTURE = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(IndustrialWires.MODID + ":blocks/control_panel"); PANEL_TEXTURE = texMap.getAtlasSprite(IndustrialWires.MODID + ":blocks/control_panel");
} }
final TextureAtlasSprite mainTex = texMap.getAtlasSprite(components.getTexture().toString());
List<BakedQuad> ret = new ArrayList<>(); List<BakedQuad> ret = new ArrayList<>();
Matrix4 m4 = components.getPanelTopTransform(); Matrix4 m4 = components.getPanelTopTransform();
Matrix4 m4RotOnly = m4.copy(); Matrix4 m4RotOnly = m4.copy();
@ -105,33 +108,33 @@ public final class PanelUtils {
//TOP //TOP
rawOut.add(new RawQuad(new Vector3f(xMin, height0, zMin), new Vector3f(xMin, height1, zMax), rawOut.add(new RawQuad(new Vector3f(xMin, height0, zMin), new Vector3f(xMin, height1, zMax),
new Vector3f(xMax, height1, zMax), new Vector3f(xMax, height0, zMin), new Vector3f(xMax, height1, zMax), new Vector3f(xMax, height0, zMin),
EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[]{0, 0, uMaxX, uMaxZ}, -1)); EnumFacing.UP, mainTex, WHITE, null, new float[]{0, 0, uMaxX, uMaxZ}, -1));
//BOTTOM //BOTTOM
rawOut.add(new RawQuad(new Vector3f(xMin, 0, zMin), new Vector3f(xMax, 0, zMin), rawOut.add(new RawQuad(new Vector3f(xMin, 0, zMin), new Vector3f(xMax, 0, zMin),
new Vector3f(xMax, 0, zMax), new Vector3f(xMin, 0, zMax), new Vector3f(xMax, 0, zMax), new Vector3f(xMin, 0, zMax),
EnumFacing.DOWN, PANEL_TEXTURE, WHITE, null, UV_FULL, -1)); EnumFacing.DOWN, mainTex, WHITE, null, UV_FULL, -1));
//LEFT //LEFT
rawOut.add(new RawQuad(new Vector3f(xMin, 0, zMin), new Vector3f(xMin, 0, zMax), rawOut.add(new RawQuad(new Vector3f(xMin, 0, zMin), new Vector3f(xMin, 0, zMax),
new Vector3f(xMin, height1, zMax), new Vector3f(xMin, height0, zMin), new Vector3f(xMin, height1, zMax), new Vector3f(xMin, height0, zMin),
EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[][]{ EnumFacing.UP, mainTex, WHITE, null, new float[][]{
{0, 0}, {0, uMaxZ}, {0, 0}, {0, uMaxZ},
{vMax1, uMaxZ}, {vMax0, 0} {vMax1, uMaxZ}, {vMax0, 0}
}, -1)); }, -1));
//RIGHT //RIGHT
rawOut.add(new RawQuad(new Vector3f(xMax, 0, zMin), new Vector3f(xMax, height0, zMin), rawOut.add(new RawQuad(new Vector3f(xMax, 0, zMin), new Vector3f(xMax, height0, zMin),
new Vector3f(xMax, height1, zMax), new Vector3f(xMax, 0, zMax), new Vector3f(xMax, height1, zMax), new Vector3f(xMax, 0, zMax),
EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[][]{ EnumFacing.UP, mainTex, WHITE, null, new float[][]{
{0, 0}, {vMax0, 0}, {0, 0}, {vMax0, 0},
{vMax1, uMaxZ}, {0, uMaxZ} {vMax1, uMaxZ}, {0, uMaxZ}
}, -1)); }, -1));
//BACK //BACK
rawOut.add(new RawQuad(new Vector3f(xMax, 0, zMin), new Vector3f(xMin, 0, zMin), rawOut.add(new RawQuad(new Vector3f(xMax, 0, zMin), new Vector3f(xMin, 0, zMin),
new Vector3f(xMin, height0, zMin), new Vector3f(xMax, height0, zMin), new Vector3f(xMin, height0, zMin), new Vector3f(xMax, height0, zMin),
EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[]{0, 0, vMax0, uMaxX}, -1)); EnumFacing.UP, mainTex, WHITE, null, new float[]{0, 0, vMax0, uMaxX}, -1));
//FRONT //FRONT
rawOut.add(new RawQuad(new Vector3f(xMin, 0, zMax), new Vector3f(xMax, 0, zMax), rawOut.add(new RawQuad(new Vector3f(xMin, 0, zMax), new Vector3f(xMax, 0, zMax),
new Vector3f(xMax, height1, zMax), new Vector3f(xMin, height1, zMax), new Vector3f(xMax, height1, zMax), new Vector3f(xMin, height1, zMax),
EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[]{0, 0, vMax1, uMaxX}, -1)); EnumFacing.UP, mainTex, WHITE, null, new float[]{0, 0, vMax1, uMaxX}, -1));
for (RawQuad bq : rawOut) { for (RawQuad bq : rawOut) {
ret.add(ClientUtilsIW.bakeQuad(bq, baseTrans, baseNorm)); ret.add(ClientUtilsIW.bakeQuad(bq, baseTrans, baseNorm));
} }

View file

@ -16,10 +16,12 @@
package malte0811.industrialwires.controlpanel; package malte0811.industrialwires.controlpanel;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4; import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import malte0811.industrialwires.IndustrialWires;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
@ -62,6 +64,7 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
private Matrix4 topTransform; private Matrix4 topTransform;
private Matrix4 topTransformInverse; private Matrix4 topTransformInverse;
private Matrix4 baseTransform; private Matrix4 baseTransform;
private ResourceLocation texture = new ResourceLocation(IndustrialWires.MODID, "blocks/control_panel");
public PanelRenderProperties() { public PanelRenderProperties() {
@ -174,6 +177,7 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
ret.facing = facing; ret.facing = facing;
ret.top = top; ret.top = top;
ret.angle = angle; ret.angle = angle;
ret.texture = texture;
return ret; return ret;
} }
@ -198,6 +202,13 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
} }
} }
public void setTexture(ResourceLocation texture) {
this.texture = texture;
}
public ResourceLocation getTexture() {
return texture;
}
public float getHeight() { public float getHeight() {
return height; return height;
@ -243,7 +254,8 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
if (Float.compare(that.height, height) != 0) return false; if (Float.compare(that.height, height) != 0) return false;
if (Float.compare(that.angle, angle) != 0) return false; if (Float.compare(that.angle, angle) != 0) return false;
if (facing != that.facing) return false; if (facing != that.facing) return false;
return top == that.top; if (top != that.top) return false;
return texture.equals(that.texture);
} }
@Override @Override
@ -253,6 +265,7 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
result = 31 * result + (height != +0.0f ? Float.floatToIntBits(height) : 0); result = 31 * result + (height != +0.0f ? Float.floatToIntBits(height) : 0);
result = 31 * result + top.hashCode(); result = 31 * result + top.hashCode();
result = 31 * result + (angle != +0.0f ? Float.floatToIntBits(angle) : 0); result = 31 * result + (angle != +0.0f ? Float.floatToIntBits(angle) : 0);
result = 31 * result + texture.hashCode();
return result; return result;
} }
} }