123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706 |
- /*
- * Copyright (C) 2015 iZc
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package de.nplusc.izc.logblockheatmapper;
- import ar.com.hjg.pngj.ImageInfo;
- import ar.com.hjg.pngj.ImageLineHelper;
- import ar.com.hjg.pngj.ImageLineInt;
- import ar.com.hjg.pngj.PngWriter;
- import ar.com.hjg.pngj.chunks.PngChunkTextVar;
- import java.awt.Color;
- import java.awt.GradientPaint;
- import java.awt.Graphics2D;
- import java.awt.image.BufferedImage;
- import java.io.*;
- import java.util.*;
- import javax.imageio.ImageIO;
- /**
- *
- * @author iZc <nplusc.de>
- */
- enum BlockState
- {
- NONE,
- BUFFER,
- ACTIVITY,
- BUFFER_PURGED,
- ACTIVITY_PURGED,
- WORKBENCH_FORCED,
- WORKBENCH_FORCED_BUFFER,
- }
- enum RegionState
- {
- REMOVE,
- CORE,
- KEEP,
- WATERIZE,
- DROPPED
- }
- class CoordHolder
- {
- public final int x;
- public final int y;
- public final int z;
- public final String blocktype;
- CoordHolder(int x, int y, int z, String blocktype) {
- this.x = x;
- this.y = y;
- this.z = z;
- this.blocktype = blocktype;
- }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- CoordHolder that = (CoordHolder) o;
- return x == that.x &&
- y == that.y &&
- z == that.z &&
- Objects.equals(blocktype, that.blocktype);
- }
- @Override
- public int hashCode() {
- return Objects.hash(x, y, z, blocktype);
- }
- }
- public class LogBlockHeatmapperRegionTrimmer
- {
- static final int treshold = 100;
- static final int buffer = 30;
- static final int workbenchbuffer = 50;
- static final List<String> blocktypes = Arrays.asList(
- "minecraft:crafting_table",
- "minecraft:furnace",
- "minecraft:barrel",
- "minecraft:ender_chest",
- "minecraft:shulker_box",
- "minecraft:black_shulker_box",
- "minecraft:gray_shulker_box",
- "minecraft:white_shulker_box",
- "minecraft:light_gray_shulker_box",
- "minecraft:red_shulker_box",
- "minecraft:pink_shulker_box",
- "minecraft:purple_shulker_box",
- "minecraft:magenta_shulker_box",
- "minecraft:orange_shulker_box",
- "minecraft:brown_shulker_box",
- "minecraft:cyan_shulker_box",
- "minecraft:light_blue_shulker_box",
- "minecraft:yellow_shulker_box",
- "minecraft:lime_shulker_box",
- "minecraft:green_shulker_box",
- "minecraft:blue_shulker_box",
- "minecraft:hopper",
- "minecraft:chest"
- );
- //x y
- static final Color removeA = new Color(255, 127, 39);
- static final Color removeB = new Color(251, 100, 0);
- static final Color removeA_Dropped = new Color(255, 13, 90);
- static final Color removeB_Dropped = new Color(255, 13, 120);
- static final Color keepA = new Color(128, 255, 0);
- static final Color keepB = new Color(0, 255, 64);
- static final Color waterA = new Color(0, 128, 192);
- static final Color waterB = new Color(0, 128, 255);
- static final Color keepCoreA = new Color(0, 64, 0);
- static final Color keepCoreB = new Color(0, 106, 0);
-
- static final Color activity = new Color(87, 87, 87);
- static final Color activityBuffer = new Color(157, 157, 157);
- static final Color activityPurged = new Color(230, 230, 230);
- static final Color activityBufferPurged = new Color(255, 255, 255);
- static final Color workbench_keep = new Color(255, 255, 0);
- static final Color workbench_keep_buffer = new Color(128, 128, 0);
-
- static final Color coreEdge = new Color(255, 0, 0);
- static int[ ][ ] dataField ;
- static Map<String,Integer> keepRegionsIn = new TreeMap<>();
- static Map<String,RegionState> keepRegions = new TreeMap<>();
- static Map<CoordHolder,Integer> workbenchCalculations = new HashMap<>();
- static int radius=0;
- static int coreRadius=0;
- static int regionRedius = 0;
- static int fuckyou = 0;
- private static void setRegion(int x,int y, int s)
- {
- int rx = (int)Math.floor((x)/512.0f);
- int ry = (int)Math.floor((y)/512.0f);
- keepRegionsIn.putIfAbsent(("r."+rx+"."+ry+".mca"),0);
- keepRegionsIn.put(("r."+rx+"."+ry+".mca"),keepRegionsIn.get(("r."+rx+"."+ry+".mca"))+s);
- }
- private static void setRegionFinal(int x,int y, RegionState s)
- {
- int rx = (int)Math.floor((x)/512.0f);
- int ry = (int)Math.floor((y)/512.0f);
- keepRegions.put(("r."+rx+"."+ry+".mca"),s);
- }
-
-
-
- /**
- * @param args the command line arguments
- * @throws java.lang.Exception
- */
- public static void main(String[] args)throws Exception
- {
- if(args.length<3)
- {
- throw new UnsupportedOperationException("not enough parameters");
- }
- /*
- if(args.length>2)
- {
- targetBlockID = Integer.valueOf(args[2]);
- if(args.length>3)
- {
- removalsOnly = Boolean.valueOf(args[3]);
- }
- }*/
-
-
- radius = Integer.valueOf(args[1]);
- dataField = new int[radius*2][radius*2];
- int regionBase = radius/512;
- int regionRemainder = radius%512;
-
- if(regionRemainder>0)
- {
- regionBase++;
- }
-
- coreRadius = Integer.valueOf(args[2]);
- int coreBase = coreRadius/512;
- int coreRemainder = coreRadius%512;
-
- if(coreRemainder>0)
- {
- coreBase++;
- }
-
- regionRedius = regionBase;
-
- for(int i=0;i<coreRadius;i++)
- {
- for(int j=0;j<coreRadius;j++)
- {
- setRegionFinal(i, j, RegionState.CORE);
- setRegionFinal(i, -j, RegionState.CORE);
- setRegionFinal(-i, j, RegionState.CORE);
- setRegionFinal(-i, -j, RegionState.CORE);
- }
- System.out.print(i+" Preparation Core Lines\r");
- }
- for(int i=0;i<dataField.length;i++)
- {
- for(int j=0;j<dataField.length;j++)
- {
- dataField[i][j]=BlockState.NONE.ordinal();
- }
- System.out.print(i+" Preparation Data Lines\r");
- }
-
- BufferedReader br = new BufferedReader(new FileReader(args[0]));
- PrintStream lmaa = new PrintStream(new FileOutputStream("fuckyouandeatshit.txt"));
- br.lines().forEach((xx)->
- {
-
- //4 als 5 und nen bisschen arithmetik gibt seitwärts-schnittansicht
- //id_0 oldblox_1 newblox_2 newdv_3 X_4 height_5 y_6
- //10 5 0 0 -1373 27 4008
- xx = xx.replace("\"", "");
- xx = xx.replace(",", "\t");
- String[] xes = xx.split("\\t");
- int l = Integer.parseInt(xes[0]);
- boolean register=false;
- String to = xes[2].intern();
- String from = xes[3].intern(); //richtigrum, verfickt und zugenäht
- int x= Integer.parseInt(xes[4])+radius,y= Integer.parseInt(xes[6])+radius;
- int z = Integer.parseInt(xes[5]);
- if(blocktypes.contains(from)||blocktypes.contains(to))
- {
- if(from!=to) // yes, this works since i interned the strings beforehand :P
- {
- fuckyou++;
- lmaa.println(xx);
- if(blocktypes.contains(from))
- {
- CoordHolder location = new CoordHolder(x,y,z,from);
- if(!workbenchCalculations.containsKey(location))
- {
- workbenchCalculations.put(location,-1);
- }
- else
- {
- workbenchCalculations.put(location,workbenchCalculations.get(location)-1);
- }
- }
- if(blocktypes.contains(to))
- {
- CoordHolder location = new CoordHolder(x,y,z,to);
- if(!workbenchCalculations.containsKey(location))
- {
- workbenchCalculations.put(location,1);
- }
- else
- {
- workbenchCalculations.put(location,workbenchCalculations.get(location)+1);
- }
- }
- }
- else
- {
- //System.out.print("Skipped Transaction due to from and to being equal");
- }
- }
- else
- {
- //-y=up
- if(x<radius*2&&x>=0&&y<radius*2&&y>=0)
- {
- for(int i=-buffer;i<buffer+1;i++)
- {
- if((x+i)<(radius*2)&&(x+i)>0)
- {
- for(int j=-buffer;j<+1;j++)
- {
- if((y+j)<(radius*2)&&(y+j)>0)
- {
- //only switching NONE to BUFFER
- if(dataField[y+j][x+i]==BlockState.NONE.ordinal())
- {
- dataField[y+j][x+i]=BlockState.BUFFER_PURGED.ordinal();
- // setRegion(x+i-radius, y+i-radius, 1);
- // propagating buffer markers in second pass... buffer rendering handled in same pass
- }
- }
- }
- }
- }
- dataField[y][x]=BlockState.ACTIVITY.ordinal();
- setRegion(x-radius, y-radius, 1);
- }
- }
- if(l%10000==0)
- {
- System.out.print(l+"changes so far\r");
- }
- });
- System.out.println("\n");
- System.out.println(fuckyou);
- System.out.println("\nDatabase crunched to 100%\n");
- System.out.print("\nCalculating Workbenches("+workbenchCalculations.size()+") \n");
- lmaa.close();
- workbenchCalculations.forEach((c,i) ->
- {
- if(i>0)
- {
- System.out.println("workbench at"+c.x+"|"+c.y);
- if(c.x<0||c.y<0||c.x>=dataField.length||c.y>=dataField.length)
- {
- return;
- }
- System.out.println("workbench kept at"+c.x+"|"+c.y+"| cnt = "+i);
- setRegion(c.x-radius,c.y-radius,3*treshold); // force keep
- dataField[c.y][c.x]=BlockState.WORKBENCH_FORCED.ordinal();
- }
- if(i<-1)
- {
- System.out.println("DAFUQ at"+c.x+"|"+c.y+"| as "+i);
- }
- });
- System.out.println("\nWorkbenches calculated\n");
- for(int i=-regionBase;i<=regionBase;i++)
- {
- for(int j=-regionBase;j<=regionBase;j++)
- {
- int current=keepRegionsIn.getOrDefault(("r."+(i)+"."+(j)+".mca"),-1);
- System.out.println("Processing r."+(i)+"."+(j)+".mca; ("+i+"/"+regionBase+"|"+j+"/"+regionBase);
- if(current<treshold)
- {
- RegionState old = keepRegions.getOrDefault(("r."+(i)+"."+(j)+".mca"),RegionState.REMOVE);
- System.out.println("Processing r."+(i)+"."+(j)+".mca; Is: "+old);
- if(((old)!=RegionState.CORE)&&(old!=RegionState.KEEP))
- {
- System.out.println("Dropping r."+(i)+"."+(j)+".mca; Is: "+old);
- keepRegions.put(("r."+(i)+"."+(j)+".mca"),RegionState.REMOVE);
- }
- if(current>0) // no activity inside so no need to search for activity spots
- {
- //highlighgt actively dropped ones differently...
- if(((old)!=RegionState.CORE)&&(old!=RegionState.KEEP))
- {
- System.out.println("Dropping r."+(i)+"."+(j)+".mca; Is: "+old);
- keepRegions.put(("r."+(i)+"."+(j)+".mca"),RegionState.DROPPED);
- }
- for(int pi = 0;pi<512;pi++)
- {
- for(int pj = 0;pj<512;pj++)
- {
- int kx = i*512+pi+radius+1;
- int ky = j*512+pj+radius+1;
- if(kx<0||ky<0||kx>=dataField.length||ky>=dataField.length)
- {
- continue; // coordinate not valid. can't crunch
- }
- BlockState k = BlockState.values()[dataField[ky][kx]];
- if(k==BlockState.ACTIVITY)
- {
- dataField[ky][kx]=BlockState.ACTIVITY_PURGED.ordinal();
- }
- }
- }
- }
- }
- else
- {
- keepRegions.put(("r."+(i)+"."+(j)+".mca"),RegionState.KEEP);
- for(int pi = 0;pi<512;pi++)
- {
- for(int pj = 0;pj<512;pj++)
- {
- int kx = i*512+pi+radius;
- int ky = j*512+pj+radius;
- if(kx<0||ky<0||kx>=dataField.length||ky>=dataField.length)
- {
- continue; // coordinate not valid. can't crunch
- }
- BlockState k = BlockState.values()[dataField[ky][kx]];
- if(k==BlockState.ACTIVITY)
- {
- if(pi<buffer&&pj<buffer)
- {
- keepRegions.put(("r."+(i-1)+"."+(j-1)+".mca"),RegionState.KEEP);
- }
- if(pi<buffer)
- {
- keepRegions.put(("r."+(i-1)+"."+(j)+".mca"),RegionState.KEEP);
- }
- if (pj<buffer)
- {
- keepRegions.put(("r."+(i)+"."+(j-1)+".mca"),RegionState.KEEP);
- }
- int max = 512-(buffer+1);
- if(pi>max&&pj>max)
- {
- keepRegions.put(("r."+(i+1)+"."+(j+1)+".mca"),RegionState.KEEP);
- }
- if(pi>max)
- {
- keepRegions.put(("r."+(i+1)+"."+(j)+".mca"),RegionState.KEEP);
- }
- if (pj>max)
- {
- keepRegions.put(("r."+(i)+"."+(j+1)+".mca"),RegionState.KEEP);
- }
- //propagating buffers
- int kxmin = Math.max(0,kx-(buffer+1));
- int kymin = Math.max(0,ky-(buffer+1));
- int kxmax = Math.min(dataField.length,kx+buffer+1);
- int kymax = Math.min(dataField.length,ky+buffer+1);
- for(int ki = kxmin;ki<kxmax;ki++)
- {
- for(int kj = kymin;kj<kymax;kj++)
- {
- int ov = dataField[kj][ki];
- if(ov==BlockState.NONE.ordinal()||ov==BlockState.BUFFER_PURGED.ordinal())
- {
- dataField[kj][ki] = BlockState.BUFFER.ordinal();
- }
- }
- }
- }
- if(k==BlockState.WORKBENCH_FORCED)
- {
- if(pi<workbenchbuffer&&pj<workbenchbuffer)
- {
- keepRegions.put(("r."+(i-1)+"."+(j-1)+".mca"),RegionState.KEEP);
- }
- if(pi<workbenchbuffer+1)
- {
- keepRegions.put(("r."+(i-1)+"."+(j)+".mca"),RegionState.KEEP);
- }
- if (pj<workbenchbuffer+1)
- {
- keepRegions.put(("r."+(i)+"."+(j-1)+".mca"),RegionState.KEEP);
- }
- int max = 512-(workbenchbuffer+1);
- if(pi>max&&pj>max)
- {
- keepRegions.put(("r."+(i+1)+"."+(j+1)+".mca"),RegionState.KEEP);
- }
- if(pi>max)
- {
- keepRegions.put(("r."+(i+1)+"."+(j)+".mca"),RegionState.KEEP);
- }
- if (pj>max)
- {
- keepRegions.put(("r."+(i)+"."+(j+1)+".mca"),RegionState.KEEP);
- }
- //propagating buffers
- int kxmin = Math.max(0,kx-(workbenchbuffer+1));
- int kymin = Math.max(0,ky-(workbenchbuffer+1));
- int kxmax = Math.min(dataField.length,kx+(workbenchbuffer+1));
- int kymax = Math.min(dataField.length,ky+(workbenchbuffer+1));
- for(int ki = kxmin;ki<kxmax;ki++)
- {
- for(int kj = kymin;kj<kymax;kj++)
- {
- int ov = dataField[kj][ki];
- if(ov==BlockState.NONE.ordinal()||ov==BlockState.BUFFER_PURGED.ordinal()||ov==BlockState.BUFFER.ordinal())
- {
- dataField[kj][ki] = BlockState.WORKBENCH_FORCED_BUFFER.ordinal();
- }
- }
- }
- }
- }
- }
- }
- /*for(int k=0;k<8;k++)
- {
- if((neighbors[k]==RegionState.KEEP||neighbors[k]==RegionState.CORE)&&((current!=RegionState.KEEP)&&(current!=RegionState.CORE)))
- {
- keepRegions.put(("r."+i+"."+j+".mca"),RegionState.WATERIZE);
- }
- }*/
- }
- }
- //max=Math.min(max, 1000);
- //int steps=max/256;
- //BufferedWriter bw = new BufferedWriter(new FileWriter(new File("D:/emc2/arca_slash/database/crunched.pgm")));
- //bw.write("P6");
- //bw.newLine();
- //bw.write("20000 20000");
- //bw.newLine();
- //bw.write("255");
- //bw.newLine();
- //SELECT id, replaced, `type`, `data`, x, y, z
- //FROM `lb-surv`
- //INTO OUTFILE 'D:/emc2/arca_slash/database/lbcrunchsurvival.csv';
- ImageInfo imi = new ImageInfo(dataField.length, dataField.length, 8, false); // 8 bits per channel, no alpha
- // open image for writing to a output stream
- PngWriter png = new PngWriter(new FileOutputStream("map_rg.png"), imi);
- // add some optional metadata (chunks)
- png.getMetadata().setDpi(100.0);
- png.getMetadata().setTimeNow(0); // 0 seconds fron now = now
- //0-49 1 stufe=1 farbschritt 50 -1049: 10 stufen pro farbschritt: rest gleichmäßig aufgeteilt bis maximum
- for (int i = 0; i < dataField.length; i++) {
- int[] is = dataField[i];
- ImageLineInt iline = new ImageLineInt(imi);
- for (int j = 0; j < is.length; j++) {
- int color = Color.white.getRGB();
- BlockState k = BlockState.values()[is[j]];
- switch (k) {
- case NONE:
- int rx = (int) Math.floor((j - radius) / 512.0);
- int ry = (int) Math.floor((i - radius) / 512.0);
- if ((i == radius + coreRadius || j == radius - coreRadius) ||
- (j == radius + coreRadius || j == radius - coreRadius)) {
- color = coreEdge.getRGB();
- } else {
- boolean grid = (rx + ry) % 2 == 0;
- RegionState s = keepRegions.get(("r." + rx + "." + ry + ".mca"));
- if (s == null) {
- s = RegionState.REMOVE;
- }
- switch (s) {
- case REMOVE:
- color = (grid ? removeA : removeB).getRGB();
- break;
- case CORE:
- color = (grid ? keepCoreA : keepCoreB).getRGB();
- break;
- case KEEP:
- color = (grid ? keepA : keepB).getRGB();
- break;
- case WATERIZE:
- color = (grid ? waterA : waterB).getRGB();
- break;
- case DROPPED:
- color = (grid ? removeA_Dropped : removeB_Dropped).getRGB();
- break;
- }
- }
- break;
- case BUFFER:
- color = activityBuffer.getRGB();
- break;
- case ACTIVITY:
- color = activity.getRGB();
- break;
- case BUFFER_PURGED:
- color = activityBufferPurged.getRGB();
- break;
- case ACTIVITY_PURGED:
- color = activityPurged.getRGB();
- break;
- case WORKBENCH_FORCED:
- color = workbench_keep.getRGB();
- break;
- case WORKBENCH_FORCED_BUFFER:
- color = workbench_keep_buffer.getRGB();
- break;
- }
- ImageLineHelper.setPixelRGB8(iline, j, color);
- }
- png.writeRow(iline);
- System.out.print(i + "lines rasterized\r");
- }
- png.end();
- System.out.println();
- PrintStream fileActions;
- try {
- fileActions = new PrintStream(new FileOutputStream("mergeMap.sh"));
- fileActions.println("mkdir oldChunks");
- System.out.println("mkdir oldChunks");
- fileActions.println("mkdir oldChunksWaterize");
- System.out.println("mkdir oldChunksWaterize");
- keepRegions.forEach((k,v)->
- {
- switch(v)
- {
- case REMOVE:
- case DROPPED:
- fileActions.println("mv "+k+" oldChunks/");
- System.out.println("mv "+k+" oldChunks/");
- break;
- case CORE:
- fileActions.println("echo "+k+" is keepCore");
- System.out.println("echo "+k+" is keepCore");
- break;
- case KEEP:
- fileActions.println("echo "+k+" is keep");
- System.out.println("echo "+k+" is keep");
- break;
- case WATERIZE:
- fileActions.println("mv "+k+" oldChunksWaterize/");
- System.out.println("mv "+k+" oldChunksWaterize/");
- fileActions.println("mv waterize/"+k+" ./");
- System.out.println("mv waterize/"+k+" ./");
- break;
- }
- });
- fileActions.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
- //use mcserver;
- //mysql> SELECT id,replaced,type,data,x,y,z from `lb-surv` into outfile D:\\emc2\\arca_slash\\heatmap.tsv FIELDS TERMINATED BY `\t` LINES TERMINATED BY `\n`
- /*
- SELECT blocks.id, blocks.id, blocks.type, blocks.replaced, blocks.x,blocks.y, blocks.z FROM `lb-players` as player, `lb-surv-blocks` as blocks
- where player.playerid = blocks.playerid
- AND player.UUID NOT LIKE 'l%'
- INTO OUTFILE 'C:/lmaa/crunchme/survival2-oct-novirt.csv'
- ;
- */
- /*
- SELECT blocks.id, blocks.id, materials.name, materials2.name, blocks.x,blocks.y, blocks.z FROM `lb-players` as player, `lb-surv-blocks` as blocks, `lb-materials` as materials, `lb-materials` as materials2
- where player.playerid = blocks.playerid
- AND player.UUID NOT LIKE 'l%'
- and blocks.type = materials.id
- and blocks.replaced = materials2.id
- INTO OUTFILE '/tmp/crunchy.csv';
- * */
|