Fix #saturate-Pattern (#1944)

* fix: block type access + resources in #saturate pattern

* chore: no need to download jar file in loadModTextures
Dieser Commit ist enthalten in:
Pierre Maurice Schwang 2022-09-21 16:17:41 +02:00 committet von GitHub
Ursprung 1706d64ddf
Commit ab55d07ffd
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 29 neuen und 35 gelöschten Zeilen

Datei anzeigen

@ -66,7 +66,7 @@ public class SaturatePattern extends AbstractPattern {
} }
int newColor = TextureUtil.multiplyColor(currentColor, color); int newColor = TextureUtil.multiplyColor(currentColor, color);
BlockType newBlock = util.getNearestBlock(newColor); BlockType newBlock = util.getNearestBlock(newColor);
if (newBlock.equals(type)) { if (newBlock == null || newBlock.equals(type)) {
return false; return false;
} }
return set.setBlock(extent, newBlock.getDefaultState()); return set.setBlock(extent, newBlock.getDefaultState());

Datei anzeigen

@ -30,7 +30,6 @@ import java.io.BufferedInputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -427,7 +426,7 @@ public class TextureUtil implements TextureHolder {
HashSet<BlockType> blocks = new HashSet<>(); HashSet<BlockType> blocks = new HashSet<>();
for (int typeId = 0; typeId < ids.length; typeId++) { for (int typeId = 0; typeId < ids.length; typeId++) {
if (ids[typeId]) { if (ids[typeId]) {
blocks.add(BlockTypes.get(typeId)); blocks.add(BlockTypesCache.values[typeId]);
} }
} }
return fromBlocks(blocks); return fromBlocks(blocks);
@ -445,7 +444,7 @@ public class TextureUtil implements TextureHolder {
TextureUtil tu = Fawe.instance().getTextureUtil(); TextureUtil tu = Fawe.instance().getTextureUtil();
for (int typeId : tu.getValidBlockIds()) { for (int typeId : tu.getValidBlockIds()) {
BlockType block = BlockTypes.get(typeId); BlockType block = BlockTypesCache.values[typeId];
extent.init(0, 0, 0, block.getDefaultState().toBaseBlock()); extent.init(0, 0, 0, block.getDefaultState().toBaseBlock());
if (mask.test(extent)) { if (mask.test(extent)) {
blocks.add(block); blocks.add(block);
@ -685,7 +684,7 @@ public class TextureUtil implements TextureHolder {
if (min == Long.MAX_VALUE) { if (min == Long.MAX_VALUE) {
return null; return null;
} }
return BlockTypes.get(closest); return BlockTypesCache.values[closest];
} }
/** /**
@ -714,7 +713,7 @@ public class TextureUtil implements TextureHolder {
if (min == Long.MAX_VALUE) { if (min == Long.MAX_VALUE) {
return null; return null;
} }
return BlockTypes.get(closest); return BlockTypesCache.values[closest];
} }
/** /**
@ -737,8 +736,8 @@ public class TextureUtil implements TextureHolder {
} }
} }
} }
layerBuffer[0] = BlockTypes.get(closest[0]); layerBuffer[0] = BlockTypesCache.values[closest[0]];
layerBuffer[1] = BlockTypes.get(closest[1]); layerBuffer[1] = BlockTypesCache.values[closest[1]];
return layerBuffer; return layerBuffer;
} }
@ -905,36 +904,25 @@ public class TextureUtil implements TextureHolder {
if (folder.exists()) { if (folder.exists()) {
// Get all the jar files // Get all the jar files
File[] files = folder.listFiles((dir, name) -> name.endsWith(".jar")); File[] files = folder.listFiles((dir, name) -> name.endsWith(".jar"));
if (files.length == 0) { // We expect the latest version to be already there, due to the download in TextureUtil#<init>
new File(Fawe.platform().getDirectory() + "/" + Settings.settings().PATHS.TEXTURES + "/") if (files == null || files.length == 0) {
.mkdirs(); LOGGER.error("No version jar found in {}. Delete the named folder and restart your server to download the " +
try (BufferedInputStream in = new BufferedInputStream( "missing assets.", folder.getPath());
new URL("https://piston-data.mojang.com/v1/objects/c0898ec7c6a5a2eaa317770203a1554260699994/client.jar")
.openStream());
FileOutputStream fileOutputStream = new FileOutputStream(
Fawe.platform().getDirectory() + "/" + Settings.settings().PATHS.TEXTURES + "/1.19.2.jar")) {
byte[] dataBuffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
fileOutputStream.write(dataBuffer, 0, bytesRead);
}
fileOutputStream.close();
files = folder.listFiles((dir, name) -> name.endsWith(".jar"));
} catch (IOException e) {
LOGGER.error( LOGGER.error(
"Could not download version jar. Please do so manually by creating a `FastAsyncWorldEdit/textures` " + "If no asset jar is created, please do so manually by creating a `FastAsyncWorldEdit/textures` " +
"folder with a `.minecraft/versions` jar or mods in it."); "folder with a `.minecraft/versions` jar or mods in it.");
LOGGER.error("If the file exists, please make sure the server has read access to the directory.");
} }
} if (files != null && (files.length > 0)) {
if ((files.length > 0)) {
for (File file : files) { for (File file : files) {
ZipFile zipFile = new ZipFile(file); ZipFile zipFile = new ZipFile(file);
// Get all the groups in the current jar // Get all the groups in the current jar
// The vanilla textures are in `assets/minecraft` // The vanilla textures are in `assets/minecraft`
// A jar may contain textures for multiple mods // A jar may contain textures for multiple mods
String modelsDir = "assets/%1$s/models/block/%2$s.json"; String[] modelsDir = {
"assets/%1$s/models/block/%2$s.json",
"assets/%1$s/models/item/%2$s.json"
};
String texturesDir = "assets/%1$s/textures/%2$s.png"; String texturesDir = "assets/%1$s/textures/%2$s.png";
Type typeToken = new TypeToken<Map<String, Object>>() { Type typeToken = new TypeToken<Map<String, Object>>() {
@ -958,10 +946,15 @@ public class TextureUtil implements TextureHolder {
String nameSpace = split.length == 1 ? "" : split[0]; String nameSpace = split.length == 1 ? "" : split[0];
// Read models // Read models
String modelFileName = String.format(modelsDir, nameSpace, name); ZipEntry entry = null;
ZipEntry entry = getEntry(zipFile, modelFileName); for (final String dir : modelsDir) {
String modelFileName = String.format(dir, nameSpace, name);
if ((entry = getEntry(zipFile, modelFileName)) != null) {
break;
}
}
if (entry == null) { if (entry == null) {
LOGGER.error("Cannot find {} in {}", modelFileName, file); LOGGER.error("Cannot find {} in {}", modelsDir, file);
continue; continue;
} }
@ -1179,7 +1172,8 @@ public class TextureUtil implements TextureHolder {
if (min == Long.MAX_VALUE) { if (min == Long.MAX_VALUE) {
return null; return null;
} }
return BlockTypes.get(closest);
return BlockTypesCache.values[closest];
} }
private String getFileName(String path) { private String getFileName(String path) {