use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method fall.
public <B extends BlockStateHolder<B>> int fall(final Region region, boolean fullHeight, final B replace) {
FlatRegion flat = asFlatRegion(region);
final int startPerformY = region.getMinimumPoint().getBlockY();
final int startCheckY = fullHeight ? getMinY() : startPerformY;
final int endY = region.getMaximumPoint().getBlockY();
RegionVisitor visitor = new RegionVisitor(flat, pos -> {
int x = pos.getX();
int z = pos.getZ();
int freeSpot = startCheckY;
for (int y = startCheckY; y <= endY; y++) {
if (y < startPerformY) {
if (!getBlockType(x, y, z).getMaterial().isAir()) {
freeSpot = y + 1;
}
continue;
}
BlockType block = getBlockType(x, y, z);
if (!block.getMaterial().isAir()) {
if (freeSpot != y) {
setBlock(x, freeSpot, z, block);
setBlock(x, y, z, replace);
}
freeSpot++;
}
}
return true;
}, this);
Operations.completeBlindly(visitor);
return this.changes;
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class TextureUtil method getNearestBlock.
protected BlockType getNearestBlock(BlockType block, boolean darker) {
int color = getColor(block);
if (color == 0) {
return block;
}
BlockType darkerBlock = getNearestBlock(color, darker);
return darkerBlock != null ? darkerBlock : block;
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class TextureUtil method loadModTextures.
public void loadModTextures() throws IOException {
Int2ObjectOpenHashMap<Integer> colorMap = new Int2ObjectOpenHashMap<>();
Int2ObjectOpenHashMap<Long> distanceMap = new Int2ObjectOpenHashMap<>();
Gson gson = new Gson();
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://launcher.mojang.com/v1/objects/2e9a3e3107cca00d6bc9c97bf7d149cae163ef21/client.jar").openStream());
FileOutputStream fileOutputStream = new FileOutputStream(Fawe.platform().getDirectory() + "/" + Settings.settings().PATHS.TEXTURES + "/1.18.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.");
}
}
if ((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 texturesDir = "assets/%1$s/textures/%2$s.png";
Type typeToken = new TypeToken<Map<String, Object>>() {
}.getType();
for (BlockType blockType : BlockTypesCache.values) {
if (!blockType.getMaterial().isFullCube() || blockType.getId().toLowerCase().contains("shulker")) {
continue;
}
switch(blockType.getId().toLowerCase(Locale.ROOT)) {
case "slime_block":
case "honey_block":
case "mob_spawner":
case "spawner":
continue;
}
int combined = blockType.getInternalId();
String id = blockType.getId();
String[] split = id.split(":", 2);
String name = split.length == 1 ? id : split[1];
String nameSpace = split.length == 1 ? "" : split[0];
// Read models
String modelFileName = String.format(modelsDir, nameSpace, name);
ZipEntry entry = getEntry(zipFile, modelFileName);
if (entry == null) {
LOGGER.error("Cannot find {} in {}", modelFileName, file);
continue;
}
String textureFileName;
try (InputStream is = zipFile.getInputStream(entry)) {
JsonReader reader = new JsonReader(new InputStreamReader(is, StandardCharsets.UTF_8));
Map<String, Object> root = gson.fromJson(reader, typeToken);
Map<String, Object> textures = (Map) root.get("textures");
if (textures == null) {
continue;
}
Set<String> models = new HashSet<>();
// Get models
for (Map.Entry<String, Object> stringObjectEntry : textures.entrySet()) {
Object value = stringObjectEntry.getValue();
if (value instanceof String) {
models.add((String) value);
} else if (value instanceof Map) {
value = ((Map<?, ?>) value).get("model");
if (value != null) {
models.add((String) value);
}
}
}
if (models.size() != 1) {
continue;
}
String[] texSplit = models.iterator().next().split(":");
String texture = texSplit[texSplit.length - 1];
textureFileName = String.format(texturesDir, nameSpace, texture);
}
BufferedImage image = readImage(zipFile, textureFileName);
if (image == null) {
LOGGER.error("Cannot find {}", textureFileName);
continue;
}
int color = ImageUtil.getColor(image);
long distance = getDistance(image, color);
distanceMap.put(combined, (Long) distance);
colorMap.put(combined, (Integer) color);
}
Integer grass = null;
{
String grassFileName = String.format(texturesDir, "minecraft", "block/grass_block_top");
BufferedImage image = readImage(zipFile, grassFileName);
if (image != null) {
grass = ImageUtil.getColor(image);
}
}
if (grass != null) {
colorMap.put(BlockTypes.GRASS_BLOCK.getInternalId(), grass);
// assets\minecraft\textures\colormap
ZipEntry grassEntry = getEntry(zipFile, "assets/minecraft/textures/colormap/grass.png");
if (grassEntry != null) {
try (InputStream is = zipFile.getInputStream(grassEntry)) {
BufferedImage image = ImageIO.read(is);
// Update biome colors
for (BiomeColor biome : biomes) {
float adjTemp = MathMan.clamp(biome.temperature, 0.0f, 1.0f);
float adjRainfall = MathMan.clamp(biome.rainfall, 0.0f, 1.0f) * adjTemp;
int x = (int) (255 - adjTemp * 255);
int z = (int) (255 - adjRainfall * 255);
biome.grass = image.getRGB(x, z);
}
}
// swampland: perlin - avoid
biomes[6].grass = 0;
biomes[134].grass = 0;
// roofed forest: averaged w/ 0x28340A
biomes[29].grass = multiplyColor(biomes[29].grass, 0x28340A + (255 << 24));
biomes[157].grass = multiplyColor(biomes[157].grass, 0x28340A + (255 << 24));
// mesa : 0x90814D
biomes[37].grass = 0x90814D + (255 << 24);
biomes[38].grass = 0x90814D + (255 << 24);
biomes[39].grass = 0x90814D + (255 << 24);
biomes[165].grass = 0x90814D + (255 << 24);
biomes[166].grass = 0x90814D + (255 << 24);
biomes[167].grass = 0x90814D + (255 << 24);
List<BiomeColor> valid = new ArrayList<>();
for (BiomeColor biome : biomes) {
// biome.grass = multiplyColor(biome.grass, grass);
if (biome.grass != 0 && !biome.name.equalsIgnoreCase("Unknown Biome")) {
valid.add(biome);
}
biome.grassCombined = multiplyColor(grass, biome.grass);
}
this.validBiomes = valid.toArray(new BiomeColor[0]);
ArrayList<BiomeColor> uniqueColors = new ArrayList<>();
Set<Integer> uniqueBiomesColors = new IntArraySet();
for (BiomeColor color : validBiomes) {
if (uniqueBiomesColors.add(color.grass)) {
uniqueColors.add(color);
}
}
uniqueBiomesColors.clear();
LongArrayList layerIds = new LongArrayList();
LongArrayList layerColors = new LongArrayList();
for (int i = 0; i < uniqueColors.size(); i++) {
for (int j = i; j < uniqueColors.size(); j++) {
for (int k = j; k < uniqueColors.size(); k++) {
BiomeColor c1 = uniqueColors.get(i);
BiomeColor c2 = uniqueColors.get(j);
BiomeColor c3 = uniqueColors.get(k);
int average = averageColor(c1.grass, c2.grass, c3.grass);
if (uniqueBiomesColors.add(average)) {
layerColors.add(average);
layerIds.add((c1.id) + ((long) c2.id << 8) + ((long) c3.id << 16));
}
}
}
}
validMixBiomeColors = new int[layerColors.size()];
for (int i = 0; i < layerColors.size(); i++) {
validMixBiomeColors[i] = (int) layerColors.getLong(i);
}
validMixBiomeIds = layerIds.toLongArray();
}
}
// Close the file
zipFile.close();
}
}
}
// Convert the color map to a simple array
validBlockIds = new int[colorMap.size()];
validColors = new int[colorMap.size()];
int index = 0;
for (Int2ObjectMap.Entry<Integer> entry : colorMap.int2ObjectEntrySet()) {
int combinedId = entry.getIntKey();
int color = entry.getValue();
blockColors[combinedId] = color;
validBlockIds[index] = combinedId;
validColors[index] = color;
index++;
}
ArrayList<Long> distances = new ArrayList<>(distanceMap.values());
Collections.sort(distances);
this.distances = new long[distances.size()];
for (int i = 0; i < this.distances.length; i++) {
this.distances[i] = distances.get(i);
}
for (Int2ObjectMap.Entry<Long> entry : distanceMap.int2ObjectEntrySet()) {
blockDistance[entry.getIntKey()] = entry.getValue();
}
calculateLayerArrays();
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class PropertyGroup method set.
public <B extends BlockStateHolder<B>> BlockStateHolder<B> set(BlockStateHolder<B> state, A value) {
BlockType type = state.getBlockType();
PropertyFunction func = states[type.getInternalId()];
if (func != null) {
value = (A) func.setFunc.apply(value);
state = state.with(func.key, value);
}
return state;
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class RandomTextureUtil method getIsBlockCloserThanBiome.
@Override
public boolean getIsBlockCloserThanBiome(char[] blockAndBiomeIdOutput, int color, int biomePriority) {
BlockType block = getNearestBlock(color);
int[] mix = biomeMixes.getOrDefault(color, null);
if (mix == null) {
int average = getBiomeMix(biomeMixBuffer, color);
mix = new int[4];
System.arraycopy(biomeMixBuffer, 0, mix, 0, 3);
mix[3] = average;
biomeMixes.put(color, mix);
}
if (++index > 2) {
index = 0;
}
int biomeId = mix[index];
int biomeAvColor = mix[3];
int blockColor = getColor(block);
blockAndBiomeIdOutput[0] = block.getDefaultState().getOrdinalChar();
blockAndBiomeIdOutput[1] = (char) biomeId;
return colorDistance(biomeAvColor, color) - biomePriority > colorDistance(blockColor, color);
}
Aggregations