Merge between master and legacy/nms
This commit is contained in:
parent
040a5014a4
commit
fd225647f5
89 changed files with 5775 additions and 874 deletions
56
API/src/main/java/com/bergerkiller/bukkit/common/LICENSE
Normal file
56
API/src/main/java/com/bergerkiller/bukkit/common/LICENSE
Normal file
|
@ -0,0 +1,56 @@
|
|||
MIT License
|
||||
|
||||
Copyright (C) 2013-2015 bergerkiller Copyright (C) 2016-2020 Berger Healer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, and/or sublicense the Software,
|
||||
and to permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
==========================================================================================
|
||||
|
||||
BKCommonLib utilizes Objensis and Javassist for some required functionality. Licenses are listed below:
|
||||
|
||||
====================================== Objenesis =========================================
|
||||
http://objenesis.googlecode.com/svn/docs/index.html
|
||||
|
||||
Copyright (c) 2003-2013, Objenesis Team and all contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
====================================== Javassist =========================================
|
||||
|
||||
The Source Code version of the Covered Code of Javassist is available under the
|
||||
MOZILLA PUBLIC LICENSE Version 1.1. The project can be found (oct-2020) here:
|
||||
|
||||
https://github.com/jboss-javassist/javassist
|
||||
|
||||
Javassist was not modified for the purpose of this software.
|
|
@ -0,0 +1,8 @@
|
|||
# BKCommonLib
|
||||
|
||||
These classes are from [BKCommonLib](https://github.com/bergerhealer/BKCommonLib). Only the required classes and methods
|
||||
are extracted.
|
||||
|
||||
**Current version:** master#3fc97d5981742f43348cac1f752404f95daa6c07
|
||||
|
||||
_Last update: 16-03-2023_
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* This file is part of MapReflectionAPI.
|
||||
* Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.bergerkiller.bukkit.common.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Input Stream that can also read individual bits
|
||||
*/
|
||||
public class BitInputStream extends InputStream {
|
||||
private int bitbuff = 0;
|
||||
private int bitbuff_len = 0;
|
||||
private boolean closed = false;
|
||||
private final InputStream input;
|
||||
private final boolean closeInput;
|
||||
|
||||
/**
|
||||
* Initializes a new Bit Input Stream, reading from the Input Stream specified
|
||||
*
|
||||
* @param inputStream to read from
|
||||
*/
|
||||
public BitInputStream(InputStream inputStream) {
|
||||
this(inputStream, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new Bit Input Stream, reading from the Input Stream specified
|
||||
*
|
||||
* @param inputStream to read from
|
||||
* @param closeInputStream whether to close the underlying input stream when closing this stream
|
||||
*/
|
||||
public BitInputStream(InputStream inputStream, boolean closeInputStream) {
|
||||
this.input = inputStream;
|
||||
this.closeInput = closeInputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
if (this.closed) {
|
||||
throw new IOException("Stream is closed");
|
||||
}
|
||||
return this.input.available();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return readBits(8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads bits from the stream
|
||||
*
|
||||
* @param nBits to read
|
||||
* @return read value, -1 when end of stream is reached
|
||||
* @throws IOException
|
||||
*/
|
||||
public int readBits(int nBits) throws IOException {
|
||||
if (this.closed) {
|
||||
throw new IOException("Stream is closed");
|
||||
}
|
||||
while (this.bitbuff_len < nBits) {
|
||||
int readByte = this.input.read();
|
||||
if (readByte == -1) return -1;
|
||||
this.bitbuff |= (readByte << this.bitbuff_len);
|
||||
this.bitbuff_len += 8;
|
||||
}
|
||||
int result = bitbuff & ((1 << nBits) - 1);
|
||||
this.bitbuff >>= nBits;
|
||||
this.bitbuff_len -= nBits;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (!this.closed) {
|
||||
this.closed = true;
|
||||
if (this.closeInput) {
|
||||
this.input.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* This file is part of MapReflectionAPI.
|
||||
* Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.bergerkiller.bukkit.common.io;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Simple container for multiple bits of data.
|
||||
*/
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
public class BitPacket implements Cloneable {
|
||||
public int data, bits;
|
||||
|
||||
public BitPacket() {
|
||||
this.data = 0;
|
||||
this.bits = 0;
|
||||
}
|
||||
|
||||
public BitPacket(int data, int bits) {
|
||||
this.data = data;
|
||||
this.bits = bits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BitPacket clone() {
|
||||
return new BitPacket(this.data, this.bits);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,221 @@
|
|||
/*
|
||||
* This file is part of MapReflectionAPI.
|
||||
* Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.bergerkiller.bukkit.common.map;
|
||||
|
||||
import com.bergerkiller.bukkit.common.map.color.MCSDBubbleFormat;
|
||||
import com.bergerkiller.bukkit.common.map.color.MCSDGenBukkit;
|
||||
import com.bergerkiller.bukkit.common.map.color.MapColorSpaceData;
|
||||
import tech.sbdevelopment.mapreflectionapi.utils.ReflectionUtil;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Additional functionality on top of Bukkit's MapPalette
|
||||
*/
|
||||
public class MapColorPalette {
|
||||
private static final MapColorSpaceData COLOR_MAP_DATA;
|
||||
public static final byte[] COLOR_MAP_AVERAGE = new byte[0x10000];
|
||||
public static final byte[] COLOR_MAP_ADD = new byte[0x10000];
|
||||
public static final byte[] COLOR_MAP_SUBTRACT = new byte[0x10000];
|
||||
public static final byte[] COLOR_MAP_MULTIPLY = new byte[0x10000];
|
||||
public static final byte[] COLOR_MAP_SPECULAR = new byte[0x10000];
|
||||
|
||||
public static final byte COLOR_TRANSPARENT = 0;
|
||||
|
||||
static {
|
||||
// Now we know java.awt exists we can initialize this one
|
||||
COLOR_MAP_DATA = new MapColorSpaceData();
|
||||
|
||||
// Load color map data from the Bubble format file bundled with the library
|
||||
{
|
||||
boolean success = false;
|
||||
MCSDBubbleFormat bubbleData = new MCSDBubbleFormat();
|
||||
try {
|
||||
String bub_path_postfix;
|
||||
if (ReflectionUtil.supports(17)) {
|
||||
bub_path_postfix = "map_1_17.bub";
|
||||
} else if (ReflectionUtil.supports(16)) {
|
||||
bub_path_postfix = "map_1_16.bub";
|
||||
} else if (ReflectionUtil.supports(12)) {
|
||||
bub_path_postfix = "map_1_12.bub";
|
||||
} else {
|
||||
bub_path_postfix = "map_1_8_8.bub";
|
||||
}
|
||||
String bub_path = "/tech/sbdevelopment/mapreflectionapi/libs/bkcommonlib/internal/resources/map/" + bub_path_postfix;
|
||||
InputStream input = MapColorPalette.class.getResourceAsStream(bub_path);
|
||||
if (input != null) {
|
||||
bubbleData.readFrom(input);
|
||||
success = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (success) {
|
||||
COLOR_MAP_DATA.readFrom(bubbleData);
|
||||
} else {
|
||||
MCSDGenBukkit bukkitGen = new MCSDGenBukkit();
|
||||
bukkitGen.generate();
|
||||
COLOR_MAP_DATA.readFrom(bukkitGen);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate 256 lightness values for all colors
|
||||
for (int a = 0; a < 256; a++) {
|
||||
int index = (a * 256);
|
||||
Color color_a = getRealColor((byte) a);
|
||||
if (color_a.getAlpha() < 128) {
|
||||
// All specular colors for the transparent color are transparent
|
||||
Arrays.fill(COLOR_MAP_SPECULAR, index, index + 256, COLOR_TRANSPARENT);
|
||||
} else {
|
||||
for (int b = 0; b < 256; b++) {
|
||||
// 0.0 = black
|
||||
// 1.0 = natural color
|
||||
// 2.0 = white
|
||||
float f = b / 128.0f;
|
||||
int sr = (int) (color_a.getRed() * f);
|
||||
int sg = (int) (color_a.getGreen() * f);
|
||||
int sb = (int) (color_a.getBlue() * f);
|
||||
COLOR_MAP_SPECULAR[index++] = getColor(sr, sg, sb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the color map tables for all possible color values
|
||||
for (int c1 = 0; c1 < 256; c1++) {
|
||||
for (int c2 = 0; c2 < 256; c2++) {
|
||||
initTable((byte) c1, (byte) c2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void initTable(byte color1, byte color2) {
|
||||
int index = getMapIndex(color1, color2);
|
||||
if (isTransparent(color1) || isTransparent(color2)) {
|
||||
initTransparent(index, color2);
|
||||
} else {
|
||||
Color c1 = getRealColor(color1);
|
||||
Color c2 = getRealColor(color2);
|
||||
initColor(
|
||||
index,
|
||||
c1.getRed(), c1.getGreen(), c1.getBlue(),
|
||||
c2.getRed(), c2.getGreen(), c2.getBlue()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static void initTransparent(int index, byte color2) {
|
||||
COLOR_MAP_AVERAGE[index] = color2;
|
||||
COLOR_MAP_ADD[index] = color2;
|
||||
COLOR_MAP_SUBTRACT[index] = color2;
|
||||
COLOR_MAP_MULTIPLY[index] = (byte) 0;
|
||||
}
|
||||
|
||||
private static void initColor(int index, int r1, int g1, int b1, int r2, int g2, int b2) {
|
||||
initArray(COLOR_MAP_AVERAGE, index, (r1 + r2) >> 1, (g1 + g2) >> 1, (b1 + b2) >> 1);
|
||||
initArray(COLOR_MAP_ADD, index, (r1 + r2), (g1 + g2), (b1 + b2));
|
||||
initArray(COLOR_MAP_SUBTRACT, index, (r2 - r1), (g2 - g1), (b2 - b1));
|
||||
initArray(COLOR_MAP_MULTIPLY, index, (r1 * r2) / 255, (g1 * g2) / 255, (b1 * b2) / 255);
|
||||
}
|
||||
|
||||
private static void initArray(byte[] array, int index, int r, int g, int b) {
|
||||
if (r < 0x00) r = 0x00;
|
||||
if (r > 0xFF) r = 0xFF;
|
||||
if (g < 0x00) g = 0x00;
|
||||
if (g > 0xFF) g = 0xFF;
|
||||
if (b < 0x00) b = 0x00;
|
||||
if (b > 0xFF) b = 0xFF;
|
||||
array[index] = getColor(r, g, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether a particular color code is a transparent color.
|
||||
* There are 4 transparent colors available. Usually value 0 is used.
|
||||
*
|
||||
* @param color value
|
||||
* @return True if transparent
|
||||
*/
|
||||
public static boolean isTransparent(byte color) {
|
||||
return (color & 0xFF) < 0x4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Minecraft map color code for an RGB color
|
||||
*
|
||||
* @param color input
|
||||
* @return minecraft color
|
||||
*/
|
||||
public static byte getColor(Color color) {
|
||||
if ((color.getAlpha() & 0x80) == 0) {
|
||||
return COLOR_TRANSPARENT;
|
||||
} else {
|
||||
return COLOR_MAP_DATA.get(color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Minecraft map color code for an RGB color
|
||||
*
|
||||
* @param r - red component
|
||||
* @param g - green component
|
||||
* @param b - blue component
|
||||
* @return minecraft color
|
||||
*/
|
||||
public static byte getColor(int r, int g, int b) {
|
||||
// This helps prevent dumb exceptions.
|
||||
// Nobody likes random exceptions when all you're doing is color calculations
|
||||
if (r < 0)
|
||||
r = 0;
|
||||
else if (r > 255)
|
||||
r = 255;
|
||||
if (g < 0)
|
||||
g = 0;
|
||||
else if (g > 255)
|
||||
g = 255;
|
||||
if (b < 0)
|
||||
b = 0;
|
||||
else if (b > 255)
|
||||
b = 255;
|
||||
|
||||
return COLOR_MAP_DATA.get(r, g, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index into one of the palette remap arrays
|
||||
*
|
||||
* @param color_a first color
|
||||
* @param color_b second color
|
||||
* @return index
|
||||
*/
|
||||
public static int getMapIndex(byte color_a, byte color_b) {
|
||||
return (color_a & 0xFF) | ((color_b & 0xFF) << 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the real RGB color belonging to a color code
|
||||
*
|
||||
* @param color code input
|
||||
* @return real RGB color
|
||||
*/
|
||||
public static Color getRealColor(byte color) {
|
||||
return COLOR_MAP_DATA.getColor(color);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,277 @@
|
|||
/*
|
||||
* This file is part of MapReflectionAPI.
|
||||
* Copyright (c) 2022-2023 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.bergerkiller.bukkit.common.map.color;
|
||||
|
||||
import com.bergerkiller.bukkit.common.io.BitInputStream;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.IntPredicate;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
/**
|
||||
* Stores all map color space information in a highly compressed bubble format.
|
||||
* In this format it is assumed the color data is in cell shapes. It stores the cell
|
||||
* borders separate from the colors using the {@link MCSDWebbingCodec}. These cells
|
||||
* are then filled with colors to reproduce the original image.
|
||||
*/
|
||||
public class MCSDBubbleFormat extends MapColorSpaceData {
|
||||
public final boolean[][] strands = new boolean[256][256 * 256];
|
||||
public final List<Bubble> bubbles = new ArrayList<>();
|
||||
|
||||
public void readFrom(InputStream stream) throws IOException {
|
||||
try (BitInputStream bitStream = new BitInputStream(new InflaterInputStream(stream))) {
|
||||
// Read all color RGB values
|
||||
for (int i = 0; i < 256; i++) {
|
||||
int r = bitStream.read();
|
||||
int g = bitStream.read();
|
||||
int b = bitStream.read();
|
||||
int a = bitStream.read();
|
||||
this.setColor((byte) i, new Color(r, g, b, a));
|
||||
}
|
||||
|
||||
// Read all bubbles from the stream
|
||||
while (true) {
|
||||
Bubble bubble = new Bubble();
|
||||
bubble.color = (byte) bitStream.read();
|
||||
if (bubble.color == 0) {
|
||||
break;
|
||||
}
|
||||
bubble.x = bitStream.read();
|
||||
bubble.y = bitStream.read();
|
||||
bubble.z_min = bitStream.read();
|
||||
bubble.z_max = bubble.z_min + bitStream.read();
|
||||
this.bubbles.add(bubble);
|
||||
}
|
||||
|
||||
// Read bubble boundary information from the stream
|
||||
MCSDWebbingCodec codec = new MCSDWebbingCodec();
|
||||
for (int z = 0; z < 256; z++) {
|
||||
Arrays.fill(this.strands[z], false);
|
||||
codec.reset(strands[z], false);
|
||||
while (codec.readNext(bitStream)) ;
|
||||
}
|
||||
|
||||
// Initialize the colors with the bubble colors
|
||||
this.initColors();
|
||||
|
||||
// Read color correction data for pixels unset (value = 0)
|
||||
for (int i = 0; i < (1 << 24); i++) {
|
||||
if (this.get(i) == 0) {
|
||||
if (bitStream.readBits(1) == 0) {
|
||||
this.set(i, this.get(i - 1));
|
||||
} else {
|
||||
int mode = bitStream.readBits(2);
|
||||
if (mode == 0) {
|
||||
this.set(i, this.get(i - 256));
|
||||
} else if (mode == 1) {
|
||||
this.set(i, this.get(i + 1));
|
||||
} else if (mode == 2) {
|
||||
this.set(i, this.get(i + 256));
|
||||
} else {
|
||||
this.set(i, (byte) bitStream.readBits(8));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initColors() {
|
||||
// Set initial cell colors
|
||||
this.clearRGBData();
|
||||
for (MCSDBubbleFormat.Bubble cell : bubbles) {
|
||||
for (int z = cell.z_min; z <= cell.z_max; z++) {
|
||||
this.set(cell.x, cell.y, z, cell.color);
|
||||
}
|
||||
}
|
||||
spreadColors();
|
||||
}
|
||||
|
||||
private void spreadColors() {
|
||||
// As we'll be processing pretty much every element, allocate the full space (60MB)
|
||||
// The range of the buffer we process shrinks as we spread
|
||||
StrandBuffer buf;
|
||||
{
|
||||
final int[] buffer = new int[1 << 24];
|
||||
int count = -1;
|
||||
for (int z = 0; z < 256; z++) {
|
||||
boolean[] layerStrands = this.strands[z];
|
||||
int indexOffset = z << 16;
|
||||
for (int i = 0; i < (1 << 16); i++) {
|
||||
if (!layerStrands[i]) {
|
||||
buffer[++count] = indexOffset + i;
|
||||
}
|
||||
}
|
||||
}
|
||||
count++;
|
||||
buf = new StrandBuffer(buffer, count);
|
||||
}
|
||||
|
||||
// Process all until no more changes remain
|
||||
buf.process(index -> {
|
||||
byte color;
|
||||
|
||||
boolean col = ((index & 0xFF) < 0xFF);
|
||||
boolean row = ((index & 0xFF00) < 0xFF00);
|
||||
|
||||
if (col && row) {
|
||||
if ((color = this.get(index)) != 0) {
|
||||
this.set(index + 1, color);
|
||||
this.set(index + 256, color);
|
||||
return true;
|
||||
} else if ((color = this.get(index + 1)) != 0) {
|
||||
this.set(index, color);
|
||||
this.set(index + 256, color);
|
||||
return true;
|
||||
} else if ((color = this.get(index + 256)) != 0) {
|
||||
this.set(index, color);
|
||||
this.set(index + 1, color);
|
||||
return true;
|
||||
}
|
||||
} else if (col) {
|
||||
if ((color = this.get(index)) != 0) {
|
||||
this.set(index + 1, color);
|
||||
return true;
|
||||
} else if ((color = this.get(index + 1)) != 0) {
|
||||
this.set(index, color);
|
||||
return true;
|
||||
}
|
||||
} else if (row) {
|
||||
if ((color = this.get(index)) != 0) {
|
||||
this.set(index + 256, color);
|
||||
return true;
|
||||
} else if ((color = this.get(index + 256)) != 0) {
|
||||
this.set(index, color);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
private static class StrandBuffer {
|
||||
private final int[] buf;
|
||||
private int start, end;
|
||||
|
||||
public StrandBuffer(int[] buffer, int count) {
|
||||
this.buf = buffer;
|
||||
this.start = 0;
|
||||
this.end = count - 1;
|
||||
}
|
||||
|
||||
public void process(IntPredicate strandIndexProc) {
|
||||
while (forward(strandIndexProc) && reverse(strandIndexProc)) {
|
||||
// Process alternating over and over until there are no more changes
|
||||
}
|
||||
}
|
||||
|
||||
public boolean forward(IntPredicate strandIndexProc) {
|
||||
int[] buf = this.buf;
|
||||
int writeIdx = start - 1;
|
||||
int endIdx = end;
|
||||
boolean changed = false;
|
||||
for (int i = start; i <= endIdx; ++i) {
|
||||
int strandIndex = buf[i];
|
||||
if (strandIndexProc.test(strandIndex)) {
|
||||
changed = true;
|
||||
} else {
|
||||
buf[++writeIdx] = strandIndex;
|
||||
}
|
||||
}
|
||||
this.end = writeIdx;
|
||||
return changed;
|
||||
}
|
||||
|
||||
public boolean reverse(IntPredicate strandIndexProc) {
|
||||
int[] buf = this.buf;
|
||||
int writeIdx = end + 1;
|
||||
int startIdx = start;
|
||||
boolean changed = false;
|
||||
for (int i = end; i >= startIdx; --i) {
|
||||
int strandIndex = buf[i];
|
||||
if (strandIndexProc.test(strandIndex)) {
|
||||
changed = true;
|
||||
} else {
|
||||
buf[--writeIdx] = strandIndex;
|
||||
}
|
||||
}
|
||||
this.start = writeIdx;
|
||||
return changed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
} else if (o instanceof MCSDBubbleFormat) {
|
||||
MCSDBubbleFormat other = (MCSDBubbleFormat) o;
|
||||
for (int i = 0; i < strands.length; i++) {
|
||||
if (other.strands[i] != this.strands[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (bubbles.size() != other.bubbles.size()) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < bubbles.size(); i++) {
|
||||
if (!bubbles.get(i).equals(other.bubbles.get(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bubble {
|
||||
public int x, y;
|
||||
public int z_min;
|
||||
public int z_max;
|
||||
public byte color;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
} else if (o instanceof Bubble) {
|
||||
Bubble other = (Bubble) o;
|
||||
return other.x == x && other.y == y &&
|
||||
other.z_min == z_min && other.z_max == z_max &&
|
||||
other.color == color;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "cell{x=" + x + ", y=" + y + ", zmin=" + z_min + ", zmax=" + z_max + ", color=" + (color & 0xFF) + "}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* This file is part of MapReflectionAPI.
|
||||
* Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.bergerkiller.bukkit.common.map.color;
|
||||
|
||||
import org.bukkit.map.MapPalette;
|
||||
|
||||
public class MCSDGenBukkit extends MapColorSpaceData {
|
||||
|
||||
/**
|
||||
* Generates the color map information by using Bukkit's algorithms.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void generate() {
|
||||
this.clear();
|
||||
for (int i = 0; i < 256; i++) {
|
||||
try {
|
||||
setColor((byte) i, MapPalette.getColor((byte) i));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
for (int r = 0; r < 256; r++) {
|
||||
for (int g = 0; g < 256; g++) {
|
||||
for (int b = 0; b < 256; b++) {
|
||||
set(r, g, b, MapPalette.matchColor(r, g, b));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* This file is part of MapReflectionAPI.
|
||||
* Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.bergerkiller.bukkit.common.map.color;
|
||||
|
||||
import com.bergerkiller.bukkit.common.io.BitInputStream;
|
||||
import com.bergerkiller.bukkit.common.io.BitPacket;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Encodes or decodes a 256x256 grid of booleans by walking down the connected lines and encoding them
|
||||
* using drawing instructions. For example, a diagonal line in the grid may be encoded as follows:
|
||||
* <ul>
|
||||
* <li>SET_POSITION(23, 56)</li>
|
||||
* <li>SET_DX(-1)</li>
|
||||
* <li>SET_DY(1)</li>
|
||||
* <li>MOVE DX AND DRAW</li>
|
||||
* <li>MOVE DX AND DRAW</li>
|
||||
* <li>MOVE DY AND DRAW</li>
|
||||
* <li>MOVE DX AND DRAW</li>
|
||||
* <li>MOVE DX AND DRAW</li>
|
||||
* <li>MOVE DY AND DRAW</li>
|
||||
* <li>etc.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* For encoding the data, the follow bits are written out in sequence:
|
||||
* <ul>
|
||||
* <li>00 -> MOVE DX AND DRAW</li>
|
||||
* <li>01 -> MOVE DY AND DRAW</li>
|
||||
* <li>10 -> MOVE DX+DY AND DRAW</li>
|
||||
* <li>11 100 -> SET DX = -1</li>
|
||||
* <li>11 101 -> SET DX = 1</li>
|
||||
* <li>11 110 -> SET DY = -1</li>
|
||||
* <li>11 111 -> SET DY = 1</li>
|
||||
* <li>11 00 [byte_x][byte_y] -> SET POSITION AND DRAW</li>
|
||||
* <li>11 01 -> STOP</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class MCSDWebbingCodec {
|
||||
private int last_x, last_y;
|
||||
private int last_dx, last_dy;
|
||||
public boolean[] strands = new boolean[1 << 16];
|
||||
private final BitPacket[] packets = new BitPacket[1024];
|
||||
|
||||
public MCSDWebbingCodec() {
|
||||
for (int i = 0; i < this.packets.length; i++) {
|
||||
this.packets[i] = new BitPacket();
|
||||
}
|
||||
}
|
||||
|
||||
public void reset(boolean[] cells, boolean copyCells) {
|
||||
if (copyCells) {
|
||||
System.arraycopy(cells, 0, this.strands, 0, cells.length);
|
||||
} else {
|
||||
this.strands = cells;
|
||||
}
|
||||
this.last_x = -1000;
|
||||
this.last_y = -1000;
|
||||
this.last_dx = 1;
|
||||
this.last_dy = 1;
|
||||
}
|
||||
|
||||
public boolean readNext(BitInputStream stream) throws IOException {
|
||||
int op = stream.readBits(2);
|
||||
if (op == 0b11) {
|
||||
if (stream.readBits(1) == 1) {
|
||||
// Set DX/DY increment/decrement
|
||||
int sub = stream.readBits(2);
|
||||
if (sub == 0b00) {
|
||||
last_dx = -1;
|
||||
} else if (sub == 0b01) {
|
||||
last_dx = 1;
|
||||
} else if (sub == 0b10) {
|
||||
last_dy = -1;
|
||||
} else if (sub == 0b11) {
|
||||
last_dy = 1;
|
||||
}
|
||||
} else {
|
||||
// Command codes
|
||||
if (stream.readBits(1) == 1) {
|
||||
// End of slice
|
||||
return false;
|
||||
} else {
|
||||
// Reset position
|
||||
last_x = stream.readBits(8);
|
||||
last_y = stream.readBits(8);
|
||||
strands[last_x | (last_y << 8)] = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Write next pixel
|
||||
if (op == 0b00) {
|
||||
last_x += last_dx;
|
||||
} else if (op == 0b01) {
|
||||
last_y += last_dy;
|
||||
} else if (op == 0b10) {
|
||||
last_x += last_dx;
|
||||
last_y += last_dy;
|
||||
} else if (op == -1) {
|
||||
// End of stream
|
||||
return false;
|
||||
}
|
||||
strands[last_x | (last_y << 8)] = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* This file is part of MapReflectionAPI.
|
||||
* Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.bergerkiller.bukkit.common.map.color;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Stores the raw map color space data, enabling transformation between different storage methods.
|
||||
*/
|
||||
public class MapColorSpaceData implements Cloneable {
|
||||
private final Color[] colors = new Color[256];
|
||||
private final byte[] data = new byte[1 << 24];
|
||||
|
||||
public MapColorSpaceData() {
|
||||
Arrays.fill(this.colors, new Color(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears only the RGB data. Equivalent to using {@link #set(int, byte)} on all RGB colors.
|
||||
*/
|
||||
public final void clearRGBData() {
|
||||
Arrays.fill(this.data, (byte) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all data, setting all colors to transparent
|
||||
*/
|
||||
public final void clear() {
|
||||
Arrays.fill(this.colors, new Color(0, 0, 0, 0));
|
||||
Arrays.fill(this.data, (byte) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all color data of this color space data to that from the input color space data
|
||||
*
|
||||
* @param data to set
|
||||
*/
|
||||
public void readFrom(MapColorSpaceData data) {
|
||||
System.arraycopy(data.data, 0, this.data, 0, this.data.length);
|
||||
System.arraycopy(data.colors, 0, this.colors, 0, this.colors.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a single map palette color
|
||||
*
|
||||
* @param code of the color
|
||||
* @param color to set to
|
||||
*/
|
||||
public final void setColor(byte code, Color color) {
|
||||
this.colors[code & 0xFF] = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a single map palette color
|
||||
*
|
||||
* @param code of the color
|
||||
* @return map palette color
|
||||
*/
|
||||
public final Color getColor(byte code) {
|
||||
return this.colors[code & 0xFF];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the map color code value for an rgb value
|
||||
*
|
||||
* @param r component
|
||||
* @param g component
|
||||
* @param b component
|
||||
* @param code to set to
|
||||
*/
|
||||
public final void set(int r, int g, int b, byte code) {
|
||||
this.data[getDataIndex(r, g, b)] = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the map color code value for an rgb value
|
||||
*
|
||||
* @param r component
|
||||
* @param g component
|
||||
* @param b component
|
||||
* @return color code
|
||||
*/
|
||||
public final byte get(int r, int g, int b) {
|
||||
return this.data[getDataIndex(r, g, b)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the map color code for an rgb value
|
||||
*
|
||||
* @param index rgb compound value
|
||||
* @param code to set to
|
||||
*/
|
||||
public final void set(int index, byte code) {
|
||||
this.data[index] = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the map color code for an rgb value
|
||||
*
|
||||
* @param index rgb compound value
|
||||
* @return color code
|
||||
*/
|
||||
public final byte get(int index) {
|
||||
return this.data[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapColorSpaceData clone() {
|
||||
MapColorSpaceData clone = new MapColorSpaceData();
|
||||
System.arraycopy(this.colors, 0, clone.colors, 0, this.colors.length);
|
||||
System.arraycopy(this.data, 0, clone.data, 0, this.data.length);
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mapping index of an rgb value
|
||||
*
|
||||
* @param r component
|
||||
* @param g component
|
||||
* @param b component
|
||||
* @return index
|
||||
*/
|
||||
private static int getDataIndex(byte r, byte g, byte b) {
|
||||
return (r & 0xFF) + ((g & 0xFF) << 8) + ((b & 0xFF) << 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mapping index of an rgb value
|
||||
*
|
||||
* @param r component
|
||||
* @param g component
|
||||
* @param b component
|
||||
* @return index
|
||||
*/
|
||||
private static int getDataIndex(int r, int g, int b) {
|
||||
return (r & 0xFF) + ((g & 0xFF) << 8) + ((b & 0xFF) << 16);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue