mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
Fix #saturate-Pattern (#1944)
* fix: block type access + resources in #saturate pattern * chore: no need to download jar file in loadModTextures
This commit is contained in:
parent
1706d64ddf
commit
ab55d07ffd
@ -66,7 +66,7 @@ public class SaturatePattern extends AbstractPattern {
|
||||
}
|
||||
int newColor = TextureUtil.multiplyColor(currentColor, color);
|
||||
BlockType newBlock = util.getNearestBlock(newColor);
|
||||
if (newBlock.equals(type)) {
|
||||
if (newBlock == null || newBlock.equals(type)) {
|
||||
return false;
|
||||
}
|
||||
return set.setBlock(extent, newBlock.getDefaultState());
|
||||
|
@ -30,7 +30,6 @@ import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
@ -427,7 +426,7 @@ public class TextureUtil implements TextureHolder {
|
||||
HashSet<BlockType> blocks = new HashSet<>();
|
||||
for (int typeId = 0; typeId < ids.length; typeId++) {
|
||||
if (ids[typeId]) {
|
||||
blocks.add(BlockTypes.get(typeId));
|
||||
blocks.add(BlockTypesCache.values[typeId]);
|
||||
}
|
||||
}
|
||||
return fromBlocks(blocks);
|
||||
@ -445,7 +444,7 @@ public class TextureUtil implements TextureHolder {
|
||||
|
||||
TextureUtil tu = Fawe.instance().getTextureUtil();
|
||||
for (int typeId : tu.getValidBlockIds()) {
|
||||
BlockType block = BlockTypes.get(typeId);
|
||||
BlockType block = BlockTypesCache.values[typeId];
|
||||
extent.init(0, 0, 0, block.getDefaultState().toBaseBlock());
|
||||
if (mask.test(extent)) {
|
||||
blocks.add(block);
|
||||
@ -685,7 +684,7 @@ public class TextureUtil implements TextureHolder {
|
||||
if (min == Long.MAX_VALUE) {
|
||||
return null;
|
||||
}
|
||||
return BlockTypes.get(closest);
|
||||
return BlockTypesCache.values[closest];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -714,7 +713,7 @@ public class TextureUtil implements TextureHolder {
|
||||
if (min == Long.MAX_VALUE) {
|
||||
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[1] = BlockTypes.get(closest[1]);
|
||||
layerBuffer[0] = BlockTypesCache.values[closest[0]];
|
||||
layerBuffer[1] = BlockTypesCache.values[closest[1]];
|
||||
return layerBuffer;
|
||||
}
|
||||
|
||||
@ -905,36 +904,25 @@ public class TextureUtil implements TextureHolder {
|
||||
if (folder.exists()) {
|
||||
// Get all the jar files
|
||||
File[] files = folder.listFiles((dir, name) -> name.endsWith(".jar"));
|
||||
if (files.length == 0) {
|
||||
new File(Fawe.platform().getDirectory() + "/" + Settings.settings().PATHS.TEXTURES + "/")
|
||||
.mkdirs();
|
||||
try (BufferedInputStream in = new BufferedInputStream(
|
||||
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(
|
||||
"Could not download version jar. Please do so manually by creating a `FastAsyncWorldEdit/textures` " +
|
||||
"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.");
|
||||
}
|
||||
// We expect the latest version to be already there, due to the download in TextureUtil#<init>
|
||||
if (files == null || files.length == 0) {
|
||||
LOGGER.error("No version jar found in {}. Delete the named folder and restart your server to download the " +
|
||||
"missing assets.", folder.getPath());
|
||||
LOGGER.error(
|
||||
"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.");
|
||||
}
|
||||
if ((files.length > 0)) {
|
||||
if (files != null && (files.length > 0)) {
|
||||
for (File file : files) {
|
||||
ZipFile zipFile = new ZipFile(file);
|
||||
|
||||
// Get all the groups in the current jar
|
||||
// The vanilla textures are in `assets/minecraft`
|
||||
// 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";
|
||||
|
||||
Type typeToken = new TypeToken<Map<String, Object>>() {
|
||||
@ -958,10 +946,15 @@ public class TextureUtil implements TextureHolder {
|
||||
String nameSpace = split.length == 1 ? "" : split[0];
|
||||
|
||||
// Read models
|
||||
String modelFileName = String.format(modelsDir, nameSpace, name);
|
||||
ZipEntry entry = getEntry(zipFile, modelFileName);
|
||||
ZipEntry entry = null;
|
||||
for (final String dir : modelsDir) {
|
||||
String modelFileName = String.format(dir, nameSpace, name);
|
||||
if ((entry = getEntry(zipFile, modelFileName)) != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (entry == null) {
|
||||
LOGGER.error("Cannot find {} in {}", modelFileName, file);
|
||||
LOGGER.error("Cannot find {} in {}", modelsDir, file);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1179,7 +1172,8 @@ public class TextureUtil implements TextureHolder {
|
||||
if (min == Long.MAX_VALUE) {
|
||||
return null;
|
||||
}
|
||||
return BlockTypes.get(closest);
|
||||
|
||||
return BlockTypesCache.values[closest];
|
||||
}
|
||||
|
||||
private String getFileName(String path) {
|
||||
|
Loading…
Reference in New Issue
Block a user