use of buildcraft.robotics.zone.ZonePlan in project BuildCraft by BuildCraft.
the class TileZonePlanner method readFromNBT.
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
for (int i = 0; i < layers.length; i++) {
ZonePlan layer = layers[i];
layer.readFromNBT(nbt.getCompoundTag("layer_" + i));
}
}
use of buildcraft.robotics.zone.ZonePlan in project BuildCraft by BuildCraft.
the class TileZonePlanner method writeToNBT.
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
for (int i = 0; i < layers.length; i++) {
ZonePlan layer = layers[i];
NBTTagCompound layerCompound = new NBTTagCompound();
layer.writeToNBT(layerCompound);
nbt.setTag("layer_" + i, layerCompound);
}
return nbt;
}
use of buildcraft.robotics.zone.ZonePlan in project BuildCraft by BuildCraft.
the class TileZonePlanner method update.
@Override
public void update() {
deltaManager.tick();
if (getWorld().isRemote) {
return;
}
{
// noinspection ConstantConditions
if (!invInputPaintbrush.getStackInSlot(0).isEmpty() && invInputPaintbrush.getStackInSlot(0).getItem() instanceof ItemPaintbrush_BC8 && !invInputMapLocation.getStackInSlot(0).isEmpty() && invInputMapLocation.getStackInSlot(0).getItem() instanceof ItemMapLocation && invInputMapLocation.getStackInSlot(0).getTagCompound() != null && invInputMapLocation.getStackInSlot(0).getTagCompound().hasKey("chunkMapping") && invInputResult.getStackInSlot(0).isEmpty()) {
if (progressInput == 0) {
deltaProgressInput.addDelta(0, 200, 1);
deltaProgressInput.addDelta(200, 205, -1);
}
if (progressInput < 200) {
progressInput++;
return;
}
ZonePlan zonePlan = new ZonePlan();
zonePlan.readFromNBT(invInputMapLocation.getStackInSlot(0).getTagCompound());
layers[BCCoreItems.paintbrush.getBrushFromStack(invInputPaintbrush.getStackInSlot(0)).colour.getMetadata()] = zonePlan.getWithOffset(-pos.getX(), -pos.getZ());
invInputMapLocation.setStackInSlot(0, StackUtil.EMPTY);
invInputResult.setStackInSlot(0, new ItemStack(BCCoreItems.mapLocation));
this.markDirty();
this.sendNetworkUpdate(NET_RENDER_DATA);
progressInput = 0;
} else if (progressInput != -1) {
progressInput = -1;
deltaProgressInput.setValue(0);
}
}
{
if (!invOutputPaintbrush.getStackInSlot(0).isEmpty() && invOutputPaintbrush.getStackInSlot(0).getItem() instanceof ItemPaintbrush_BC8 && !invOutputMapLocation.getStackInSlot(0).isEmpty() && invOutputMapLocation.getStackInSlot(0).getItem() instanceof ItemMapLocation && invOutputResult.getStackInSlot(0).isEmpty()) {
if (progressOutput == 0) {
deltaProgressOutput.addDelta(0, 200, 1);
deltaProgressOutput.addDelta(200, 205, -1);
}
if (progressOutput < 200) {
progressOutput++;
return;
}
ItemMapLocation.setZone(invOutputMapLocation.getStackInSlot(0), layers[BCCoreItems.paintbrush.getBrushFromStack(invOutputPaintbrush.getStackInSlot(0)).colour.getMetadata()].getWithOffset(pos.getX(), pos.getZ()));
invOutputResult.setStackInSlot(0, invOutputMapLocation.getStackInSlot(0));
invOutputMapLocation.setStackInSlot(0, StackUtil.EMPTY);
progressOutput = 0;
} else if (progressOutput != -1) {
progressOutput = -1;
deltaProgressOutput.setValue(0);
}
}
}
use of buildcraft.robotics.zone.ZonePlan in project BuildCraft by BuildCraft.
the class TileZonePlanner method readPayload.
@Override
public void readPayload(int id, PacketBufferBC buffer, Side side, MessageContext ctx) throws IOException {
super.readPayload(id, buffer, side, ctx);
if (side == Side.CLIENT) {
if (id == NET_RENDER_DATA) {
for (int i = 0; i < layers.length; i++) {
ZonePlan layer = layers[i];
layers[i] = layer.readFromByteBuf(buffer);
}
}
} else if (side == Side.SERVER) {
if (id == NET_PLAN_CHANGE) {
int index = buffer.readUnsignedShort();
layers[index].readFromByteBuf(buffer);
markDirty();
sendNetworkUpdate(NET_RENDER_DATA);
}
}
}
use of buildcraft.robotics.zone.ZonePlan in project BuildCraft by BuildCraft.
the class GuiZonePlanner method drawForegroundLayer.
@SuppressWarnings("PointlessBitwiseExpression")
@Override
protected void drawForegroundLayer() {
camY += scaleSpeed;
scaleSpeed *= 0.7F;
int posX = (int) positionX;
int posZ = (int) positionZ;
int dimension = mc.world.provider.getDimension();
{
ChunkPos chunkPos = new ChunkPos(posX >> 4, posZ >> 4);
ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(chunkPos, dimension, container.tile.getLevel()));
BlockPos pos = null;
if (zonePlannerMapChunk != null) {
MapColourData data = zonePlannerMapChunk.getData(posX, posZ);
if (data != null) {
pos = new BlockPos(posX, data.posY, posZ);
}
}
if (pos != null && pos.getY() + 10 > camY) {
camY = Math.max(camY, pos.getY() + 10);
}
}
int x = guiLeft;
int y = guiTop;
if (lastSelected != null) {
String text = "X: " + lastSelected.getX() + " Y: " + lastSelected.getY() + " Z: " + lastSelected.getZ();
fontRenderer.drawString(text, x + 130, y + 130, 0x404040);
}
int offsetX = 8;
int offsetY = 9;
int sizeX = 213;
int sizeY = 100;
GlStateManager.pushMatrix();
GlStateManager.matrixMode(GL11.GL_PROJECTION);
GlStateManager.pushMatrix();
GlStateManager.loadIdentity();
ScaledResolution scaledResolution = new ScaledResolution(mc);
int viewportX = (x + offsetX) * scaledResolution.getScaleFactor();
int viewportY = mc.displayHeight - (sizeY + y + offsetY) * scaledResolution.getScaleFactor();
int viewportWidth = sizeX * scaledResolution.getScaleFactor();
int viewportHeight = sizeY * scaledResolution.getScaleFactor();
GL11.glEnable(GL11.GL_SCISSOR_TEST);
GL11.glScissor(viewportX, viewportY, viewportWidth, viewportHeight);
GlStateManager.clear(GL11.GL_DEPTH_BUFFER_BIT);
GL11.glDisable(GL11.GL_SCISSOR_TEST);
GlStateManager.viewport(viewportX, viewportY, viewportWidth, viewportHeight);
GlStateManager.scale(scaledResolution.getScaleFactor(), scaledResolution.getScaleFactor(), 1);
GLU.gluPerspective(70.0F, (float) sizeX / sizeY, 1F, 10000.0F);
GlStateManager.matrixMode(GL11.GL_MODELVIEW);
GlStateManager.loadIdentity();
RenderHelper.enableStandardItemLighting();
GlStateManager.enableRescaleNormal();
// look down
GlStateManager.rotate(90, 1, 0, 0);
GlStateManager.pushMatrix();
GlStateManager.translate(-positionX, -camY, -positionZ);
GlStateManager.disableBlend();
GlStateManager.disableAlpha();
GlStateManager.disableTexture2D();
int minScreenX = (x + offsetX) * scaledResolution.getScaleFactor();
int minScreenY = (scaledResolution.getScaledHeight() - (y + offsetY)) * scaledResolution.getScaleFactor();
int maxScreenX = (x + offsetX + sizeX) * scaledResolution.getScaleFactor();
int maxScreenY = (scaledResolution.getScaledHeight() - (y + offsetY + sizeY)) * scaledResolution.getScaleFactor();
int minChunkX = (posX >> 4) - 8;
int minChunkZ = (posZ >> 4) - 8;
int maxChunkX = (posX >> 4) + 8;
int maxChunkZ = (posZ >> 4) + 8;
// noinspection SuspiciousNameCombination
List<ChunkPos> chunkPosBounds = Stream.of(Pair.of(minScreenX, minScreenY), Pair.of(minScreenX, maxScreenY), Pair.of(maxScreenX, minScreenY), Pair.of(maxScreenX, maxScreenY)).map(p -> rayTrace(p.getLeft(), p.getRight())).filter(Objects::nonNull).map(ChunkPos::new).collect(Collectors.toList());
for (ChunkPos chunkPos : chunkPosBounds) {
if (chunkPos.x < minChunkX) {
minChunkX = chunkPos.x;
}
if (chunkPos.z < minChunkZ) {
minChunkZ = chunkPos.z;
}
if (chunkPos.x > maxChunkX) {
maxChunkX = chunkPos.x;
}
if (chunkPos.z > maxChunkZ) {
maxChunkZ = chunkPos.z;
}
}
minChunkX--;
minChunkZ--;
maxChunkX++;
maxChunkZ++;
for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
ZonePlannerMapRenderer.INSTANCE.getChunkGlList(new ZonePlannerMapChunkKey(new ChunkPos(chunkX, chunkZ), dimension, container.tile.getLevel())).ifPresent(GlStateManager::callList);
}
}
BlockPos found = null;
int foundColor = 0;
if (Mouse.getX() >= minScreenX && Mouse.getY() <= minScreenY && Mouse.getX() <= maxScreenX && Mouse.getY() >= maxScreenY) {
found = rayTrace(Mouse.getX(), Mouse.getY());
}
if (found != null) {
ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(new ChunkPos(found), mc.world.provider.getDimension(), container.tile.getLevel()));
if (zonePlannerMapChunk != null) {
MapColourData data = zonePlannerMapChunk.getData(found.getX(), found.getZ());
if (data != null) {
foundColor = data.colour;
}
}
}
if (found != null) {
GlStateManager.disableDepth();
GlStateManager.enableBlend();
GlStateManager.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
GlStateManager.glLineWidth(2);
int r = (int) (((foundColor >> 16) & 0xFF) * 0.7);
int g = (int) (((foundColor >> 8) & 0xFF) * 0.7);
int b = (int) (((foundColor >> 0) & 0xFF) * 0.7);
int a = 0x77;
ZonePlannerMapRenderer.INSTANCE.setColor(r << 16 | g << 8 | b << 0 | a << 24);
BufferBuilder builder = Tessellator.getInstance().getBuffer();
builder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
ZonePlannerMapRenderer.INSTANCE.drawBlockCuboid(builder, found.getX(), found.getY(), found.getZ());
Tessellator.getInstance().draw();
GlStateManager.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
GlStateManager.disableBlend();
GlStateManager.enableDepth();
}
GlStateManager.disableLighting();
GlStateManager.enableBlend();
for (int i = 0; i < container.tile.layers.length; i++) {
if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() != i) {
continue;
}
ZonePlan layer = container.tile.layers[i];
if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() == i && bufferLayer != null) {
layer = bufferLayer;
}
if (!layer.getChunkPoses().isEmpty()) {
Tessellator.getInstance().getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
ChunkPos chunkPos = new ChunkPos(chunkX, chunkZ);
for (int blockX = chunkPos.getXStart(); blockX <= chunkPos.getXEnd(); blockX++) {
for (int blockZ = chunkPos.getZStart(); blockZ <= chunkPos.getZEnd(); blockZ++) {
if (!layer.get(blockX - container.tile.getPos().getX(), blockZ - container.tile.getPos().getZ())) {
continue;
}
int height;
ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(chunkPos, dimension, container.tile.getLevel()));
if (zonePlannerMapChunk != null) {
MapColourData data = zonePlannerMapChunk.getData(blockX, blockZ);
if (data != null) {
height = data.posY;
} else {
continue;
}
} else {
continue;
}
int color = EnumDyeColor.byMetadata(i).getColorValue();
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color >> 0) & 0xFF;
int a = 0x55;
ZonePlannerMapRenderer.INSTANCE.setColor(r << 16 | g << 8 | b << 0 | a << 24);
ZonePlannerMapRenderer.INSTANCE.drawBlockCuboid(Tessellator.getInstance().getBuffer(), blockX, height + 0.1, blockZ, height, 0.6);
}
}
}
}
Tessellator.getInstance().draw();
}
}
GlStateManager.disableBlend();
GlStateManager.disableLighting();
GlStateManager.enableTexture2D();
lastSelected = found;
GlStateManager.popMatrix();
GlStateManager.disableRescaleNormal();
GlStateManager.matrixMode(GL11.GL_PROJECTION);
GlStateManager.viewport(0, 0, mc.displayWidth, mc.displayHeight);
GlStateManager.popMatrix();
GlStateManager.matrixMode(GL11.GL_MODELVIEW);
GlStateManager.popMatrix();
RenderHelper.disableStandardItemLighting();
GlStateManager.disableBlend();
}
Aggregations