mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-11-28 21:56:33 +01:00
Fixes #521
This commit is contained in:
parent
40e7e0d290
commit
95faf00467
@ -136,7 +136,6 @@ import javax.management.InstanceAlreadyExistsException;
|
|||||||
import javax.management.Notification;
|
import javax.management.Notification;
|
||||||
import javax.management.NotificationEmitter;
|
import javax.management.NotificationEmitter;
|
||||||
import javax.management.NotificationListener;
|
import javax.management.NotificationListener;
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
|
|
||||||
/**[ WorldEdit action]
|
/**[ WorldEdit action]
|
||||||
* |
|
* |
|
||||||
@ -333,8 +332,6 @@ public class Fawe {
|
|||||||
tmp.loadModTextures();
|
tmp.loadModTextures();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (ParseException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.boydti.fawe.object.pattern;
|
||||||
|
|
||||||
|
import com.boydti.fawe.util.TextureUtil;
|
||||||
|
import com.sk89q.worldedit.Vector;
|
||||||
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
|
import com.sk89q.worldedit.function.pattern.AbstractPattern;
|
||||||
|
|
||||||
|
public class ColorPattern extends AbstractPattern {
|
||||||
|
private final int color;
|
||||||
|
private final Extent extent;
|
||||||
|
private final TextureUtil util;
|
||||||
|
|
||||||
|
public ColorPattern(Extent extent, TextureUtil util, int color) {
|
||||||
|
this.extent = extent;
|
||||||
|
this.util = util;
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseBlock apply(Vector position) {
|
||||||
|
BaseBlock block = extent.getBlock(position);
|
||||||
|
int currentColor = util.getColor(block);
|
||||||
|
int newColor = util.multiplyColor(currentColor, color);
|
||||||
|
return util.getNearestBlock(newColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
|
||||||
|
BaseBlock block = extent.getBlock(setPosition);
|
||||||
|
int currentColor = util.getColor(block);
|
||||||
|
if (currentColor == 0) return false;
|
||||||
|
int newColor = util.multiplyColor(currentColor, color);
|
||||||
|
BaseBlock newBlock = util.getNearestBlock(newColor);
|
||||||
|
if (newBlock.equals(block)) return false;
|
||||||
|
return extent.setBlock(setPosition, newBlock);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.boydti.fawe.object.pattern;
|
||||||
|
|
||||||
|
import com.boydti.fawe.util.TextureUtil;
|
||||||
|
import com.sk89q.worldedit.Vector;
|
||||||
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
|
import com.sk89q.worldedit.function.pattern.AbstractPattern;
|
||||||
|
|
||||||
|
public class ShadePattern extends AbstractPattern{
|
||||||
|
private final TextureUtil util;
|
||||||
|
private final Extent extent;
|
||||||
|
|
||||||
|
public ShadePattern(Extent extent, TextureUtil util) {
|
||||||
|
this.extent = extent;
|
||||||
|
this.util = util;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public BaseBlock apply(Vector position) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,6 @@ import com.sk89q.worldedit.blocks.BaseBlock;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
|
|
||||||
public class DelegateTextureUtil extends TextureUtil {
|
public class DelegateTextureUtil extends TextureUtil {
|
||||||
private final TextureUtil parent;
|
private final TextureUtil parent;
|
||||||
@ -65,13 +64,13 @@ public class DelegateTextureUtil extends TextureUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadModTextures() throws IOException, ParseException {
|
public void loadModTextures() throws IOException {
|
||||||
parent.loadModTextures();
|
parent.loadModTextures();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int multiply(int c1, int c2) {
|
public int multiplyColor(int c1, int c2) {
|
||||||
return parent.multiply(c1, c2);
|
return parent.multiplyColor(c1, c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,6 +3,9 @@ package com.boydti.fawe.util;
|
|||||||
import com.boydti.fawe.Fawe;
|
import com.boydti.fawe.Fawe;
|
||||||
import com.boydti.fawe.FaweCache;
|
import com.boydti.fawe.FaweCache;
|
||||||
import com.boydti.fawe.config.Settings;
|
import com.boydti.fawe.config.Settings;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
import com.sk89q.worldedit.blocks.BlockID;
|
import com.sk89q.worldedit.blocks.BlockID;
|
||||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||||
@ -14,6 +17,7 @@ import java.io.FilenameFilter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -29,9 +33,6 @@ import java.util.regex.Pattern;
|
|||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
|
|
||||||
public class TextureUtil {
|
public class TextureUtil {
|
||||||
private final File folder;
|
private final File folder;
|
||||||
@ -416,9 +417,10 @@ public class TextureUtil {
|
|||||||
return colorDistance(red1, green1, blue1, c2);
|
return colorDistance(red1, green1, blue1, c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadModTextures() throws IOException, ParseException {
|
public void loadModTextures() throws IOException {
|
||||||
Int2ObjectOpenHashMap<Integer> colorMap = new Int2ObjectOpenHashMap<>();
|
Int2ObjectOpenHashMap<Integer> colorMap = new Int2ObjectOpenHashMap<>();
|
||||||
Int2ObjectOpenHashMap<Long> distanceMap = new Int2ObjectOpenHashMap<>();
|
Int2ObjectOpenHashMap<Long> distanceMap = new Int2ObjectOpenHashMap<>();
|
||||||
|
Gson gson = new Gson();
|
||||||
if (folder.exists()) {
|
if (folder.exists()) {
|
||||||
// Get all the jar files
|
// Get all the jar files
|
||||||
for (File file : folder.listFiles(new FilenameFilter() {
|
for (File file : folder.listFiles(new FilenameFilter() {
|
||||||
@ -475,8 +477,9 @@ public class TextureUtil {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try (InputStream is = zipFile.getInputStream(entry)) { //Read from a file, or a HttpRequest, or whatever.
|
try (InputStream is = zipFile.getInputStream(entry)) { //Read from a file, or a HttpRequest, or whatever.
|
||||||
JSONParser parser = new JSONParser();
|
JsonReader reader = new JsonReader(new InputStreamReader(is, "UTF-8"));
|
||||||
JSONObject root = (JSONObject) parser.parse(new InputStreamReader(is, "UTF-8"));
|
Type type = new TypeToken<Map<String, Object>>(){}.getType();
|
||||||
|
Map<String, Object> root = gson.fromJson(reader, type);
|
||||||
// Try to work out the texture names for this file
|
// Try to work out the texture names for this file
|
||||||
addTextureNames(blockName, root, texturesMap);
|
addTextureNames(blockName, root, texturesMap);
|
||||||
}
|
}
|
||||||
@ -581,8 +584,8 @@ public class TextureUtil {
|
|||||||
biomes[6].grass = 0;
|
biomes[6].grass = 0;
|
||||||
biomes[134].grass = 0;
|
biomes[134].grass = 0;
|
||||||
// roofed forest: averaged w/ 0x28340A
|
// roofed forest: averaged w/ 0x28340A
|
||||||
biomes[29].grass = multiply(biomes[29].grass, 0x28340A + (255 << 24));
|
biomes[29].grass = multiplyColor(biomes[29].grass, 0x28340A + (255 << 24));
|
||||||
biomes[157].grass = multiply(biomes[157].grass, 0x28340A + (255 << 24));
|
biomes[157].grass = multiplyColor(biomes[157].grass, 0x28340A + (255 << 24));
|
||||||
// mesa : 0x90814D
|
// mesa : 0x90814D
|
||||||
biomes[37].grass = 0x90814D + (255 << 24);
|
biomes[37].grass = 0x90814D + (255 << 24);
|
||||||
biomes[38].grass = 0x90814D + (255 << 24);
|
biomes[38].grass = 0x90814D + (255 << 24);
|
||||||
@ -593,7 +596,7 @@ public class TextureUtil {
|
|||||||
List<BiomeColor> valid = new ArrayList<>();
|
List<BiomeColor> valid = new ArrayList<>();
|
||||||
for (int i = 0; i < biomes.length; i++) {
|
for (int i = 0; i < biomes.length; i++) {
|
||||||
BiomeColor biome = biomes[i];
|
BiomeColor biome = biomes[i];
|
||||||
biome.grass = multiply(biome.grass, grass);
|
biome.grass = multiplyColor(biome.grass, grass);
|
||||||
if (biome.grass != 0 && !biome.name.equalsIgnoreCase("Unknown Biome")) {
|
if (biome.grass != 0 && !biome.name.equalsIgnoreCase("Unknown Biome")) {
|
||||||
valid.add(biome);
|
valid.add(biome);
|
||||||
}
|
}
|
||||||
@ -631,7 +634,7 @@ public class TextureUtil {
|
|||||||
calculateLayerArrays();
|
calculateLayerArrays();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int multiply(int c1, int c2) {
|
public int multiplyColor(int c1, int c2) {
|
||||||
int alpha1 = (c1 >> 24) & 0xFF;
|
int alpha1 = (c1 >> 24) & 0xFF;
|
||||||
int alpha2 = (c2 >> 24) & 0xFF;
|
int alpha2 = (c2 >> 24) & 0xFF;
|
||||||
int red1 = (c1 >> 16) & 0xFF;
|
int red1 = (c1 >> 16) & 0xFF;
|
||||||
@ -752,8 +755,8 @@ public class TextureUtil {
|
|||||||
* - Match by appending / removing <br>
|
* - Match by appending / removing <br>
|
||||||
* - Match by hardcoded values <br>
|
* - Match by hardcoded values <br>
|
||||||
*/
|
*/
|
||||||
private void addTextureNames(String modelName, JSONObject root, Map<String, String> texturesMap) {
|
private void addTextureNames(String modelName, Map<String, Object> root, Map<String, String> texturesMap) {
|
||||||
JSONObject textures = (JSONObject) root.get("textures");
|
Map textures = (Map) root.get("textures");
|
||||||
if (textures == null) {
|
if (textures == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user