add dynamic Zone Planner texture

This commit is contained in:
Adrian 2015-07-20 17:33:28 +02:00
parent d7d7585c70
commit 578db0e85c
5 changed files with 157 additions and 6 deletions

View file

@ -0,0 +1,62 @@
package buildcraft.core.lib.render;
import net.minecraft.util.IIcon;
public class FakeIcon implements IIcon {
private final int w, h;
private final float minU, maxU, minV, maxV;
public FakeIcon(float minU, float maxU, float minV, float maxV, int w, int h) {
this.minU = minU;
this.minV = minV;
this.maxU = maxU;
this.maxV = maxV;
this.w = w;
this.h = h;
}
@Override
public int getIconWidth() {
return w;
}
@Override
public int getIconHeight() {
return h;
}
@Override
public float getMinU() {
return minU;
}
@Override
public float getMaxU() {
return maxU;
}
@Override
public float getInterpolatedU(double uu) {
return (float) (minU + (uu * (maxU - minU) / 16.0));
}
@Override
public float getMinV() {
return minV;
}
@Override
public float getMaxV() {
return maxV;
}
@Override
public float getInterpolatedV(double uu) {
return (float) (minV + (uu * (maxV - minV) / 16.0));
}
@Override
public String getIconName() {
return "FakeIcon";
}
}

View file

@ -52,12 +52,11 @@ public final class RenderEntityBlock extends Render {
public Block baseBlock = Blocks.sand;
public IIcon texture = null;
public IIcon[] textureArray = null;
public boolean[] renderSide = new boolean[6];
public boolean[] renderSide = new boolean[]{true, true, true, true, true, true};
public int light = -1;
public int brightness = -1;
public RenderInfo() {
setRenderAllSides();
}
public RenderInfo(Block template, IIcon[] texture) {

View file

@ -8,11 +8,13 @@
*/
package buildcraft.robotics;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.Loader;
import net.minecraftforge.client.MinecraftForgeClient;
import buildcraft.BuildCraftRobotics;
import buildcraft.robotics.render.RenderZonePlan;
import buildcraft.robotics.render.RenderRobot;
import buildcraft.robotics.render.RobotStationItemRenderer;
@ -20,6 +22,8 @@ public class RoboticsProxyClient extends RoboticsProxy {
public void registerRenderers() {
RenderingRegistry.registerEntityRenderingHandler(EntityRobot.class, new RenderRobot());
MinecraftForgeClient.registerItemRenderer(BuildCraftRobotics.robotItem, new RenderRobot());
ClientRegistry.bindTileEntitySpecialRenderer(TileZonePlan.class, new RenderZonePlan());
// TODO: Move robot station textures locally
if (Loader.isModLoaded("BuildCraft|Transport")) {
loadBCTransport();

View file

@ -8,6 +8,7 @@
*/
package buildcraft.robotics;
import java.util.Arrays;
import java.util.List;
import io.netty.buffer.ByteBuf;
@ -19,7 +20,9 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftRobotics;
import buildcraft.api.core.IZone;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.items.IMapLocation;
import buildcraft.api.items.INamedItem;
import buildcraft.core.ItemMapLocation;
@ -31,6 +34,7 @@ import buildcraft.core.lib.network.command.CommandWriter;
import buildcraft.core.lib.network.command.PacketCommand;
import buildcraft.core.lib.utils.NetworkUtils;
import buildcraft.robotics.gui.ContainerZonePlan;
import buildcraft.robotics.map.MapWorld;
public class TileZonePlan extends TileBuildCraft implements IInventory {
@ -38,17 +42,17 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
public static final int CRAFT_TIME = 120;
private static int RESOLUTION_CHUNKS = RESOLUTION >> 4;
public final byte[] previewColors = new byte[80];
public int chunkStartX, chunkStartZ;
public short progress = 0;
public String mapName = "";
private final SimpleInventory inv = new SimpleInventory(3, "inv", 64);
private final SafeTimeTracker previewRecalcTimer = new SafeTimeTracker(100);
private ZonePlan[] selectedAreas = new ZonePlan[16];
private int currentSelectedArea = 0;
private SimpleInventory inv = new SimpleInventory(3, "inv", 64);
@Override
public void initialize() {
super.initialize();
@ -68,6 +72,10 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
return;
}
if (previewRecalcTimer.markTimeIfDelay(worldObj)) {
recalculatePreview();
}
if (inv.getStackInSlot(0) != null
&& inv.getStackInSlot(1) == null
&& inv.getStackInSlot(0).getItem() instanceof ItemMapLocation) {
@ -94,6 +102,24 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
}
}
private void recalculatePreview() {
byte[] newPreviewColors = new byte[80];
MapWorld mw = BuildCraftRobotics.manager.getWorld(worldObj);
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 10; x++) {
int tx = (x * 10) - 45;
int ty = (y * 10) - 35;
newPreviewColors[y * 10 + x] = (byte) mw.getColor(xCoord + tx, zCoord + ty);
}
}
if (!Arrays.equals(previewColors, newPreviewColors)) {
System.arraycopy(newPreviewColors, 0, previewColors, 0, 80);
sendNetworkUpdate();
}
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
@ -136,12 +162,14 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
public void writeData(ByteBuf stream) {
stream.writeShort(progress);
NetworkUtils.writeUTF(stream, mapName);
stream.writeBytes(previewColors, 0, 80);
}
@Override
public void readData(ByteBuf stream) {
progress = stream.readShort();
mapName = NetworkUtils.readUTF(stream);
stream.readBytes(previewColors, 0, 80);
}
private void importMap(ItemStack stack) {

View file

@ -0,0 +1,58 @@
package buildcraft.robotics.render;
import java.util.HashMap;
import org.lwjgl.opengl.GL11;
import net.minecraft.block.material.MapColor;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import buildcraft.core.lib.block.BlockBuildCraft;
import buildcraft.core.lib.render.DynamicTextureBC;
import buildcraft.core.lib.render.FakeIcon;
import buildcraft.core.lib.render.RenderEntityBlock;
import buildcraft.robotics.TileZonePlan;
public class RenderZonePlan extends TileEntitySpecialRenderer {
private static final float Z_OFFSET = 2049 / 2048.0F;
private static final HashMap<TileZonePlan, DynamicTextureBC> TEXTURES = new HashMap<TileZonePlan, DynamicTextureBC>();
@Override
public void renderTileEntityAt(TileEntity tile, double tx, double ty, double tz, float partialTicks) {
TileZonePlan zonePlan = (TileZonePlan) tile;
if (!TEXTURES.containsKey(zonePlan)) {
DynamicTextureBC textureBC = new DynamicTextureBC(16, 16);
TEXTURES.put(zonePlan, textureBC);
}
DynamicTextureBC textureBC = TEXTURES.get(zonePlan);
FakeIcon fakeIcon = new FakeIcon(0, 1, 0, 1, 16, 16);
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 10; x++) {
textureBC.setColor(x + 3, y + 3, 0xFF000000 | MapColor.mapColorArray[zonePlan.previewColors[y * 10 + x]].colorValue);
}
}
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT);
GL11.glTranslatef((float) tx + 0.5F, (float) ty + 0.5F, (float) tz + 0.5F);
GL11.glScalef(Z_OFFSET, Z_OFFSET, Z_OFFSET);
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
textureBC.updateTexture();
RenderEntityBlock.RenderInfo renderBox = new RenderEntityBlock.RenderInfo();
renderBox.setRenderSingleSide(((BlockBuildCraft) zonePlan.getBlockType()).getFrontSide(zonePlan.getBlockMetadata()));
renderBox.texture = fakeIcon;
renderBox.light = 15;
RenderEntityBlock.INSTANCE.renderBlock(renderBox);
GL11.glPopAttrib();
GL11.glPopMatrix();
}
}