Continue mapping migration

This commit is contained in:
Aleksey 2021-04-12 21:38:22 +03:00
parent 99ade39404
commit f03fd03bd0
499 changed files with 12567 additions and 12723 deletions

View file

@ -5,24 +5,22 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FallingBlock;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Property;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.BlockMirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FallingBlock;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.Property;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import ru.betterend.blocks.BlueVineBlock;
import ru.betterend.blocks.basis.DoublePlantBlock;
import ru.betterend.blocks.basis.FurBlock;
@ -32,9 +30,9 @@ import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndTags;
public class BlocksHelper {
public static final BooleanProperty ROOTS = BooleanProperty.of("roots");
public static final BooleanProperty ROOTS = BooleanProperty.create("roots");
private static final Map<Block, Integer> COLOR_BY_BLOCK = Maps.newHashMap();
public static final int FLAG_UPDATE_BLOCK = 1;
public static final int FLAG_SEND_CLIENT_CHANGES = 2;
public static final int FLAG_NO_RERENDER = 4;
@ -45,92 +43,97 @@ public class BlocksHelper {
public static final int SET_OBSERV = FLAG_UPDATE_BLOCK | FLAG_SEND_CLIENT_CHANGES;
public static final Direction[] HORIZONTAL = makeHorizontal();
public static final Direction[] DIRECTIONS = Direction.values();
private static final MutableBlockPos POS = new MutableBlockPos();
protected static final BlockState AIR = Blocks.AIR.defaultBlockState();
protected static final BlockState WATER = Blocks.WATER.defaultBlockState();
private static final Vec3i[] OFFSETS = new Vec3i[] { new Vec3i(-1, -1, -1), new Vec3i(-1, -1, 0),
new Vec3i(-1, -1, 1), new Vec3i(-1, 0, -1), new Vec3i(-1, 0, 0), new Vec3i(-1, 0, 1), new Vec3i(-1, 1, -1),
new Vec3i(-1, 1, 0), new Vec3i(-1, 1, 1),
private static final Vec3i[] OFFSETS = new Vec3i[] {
new Vec3i(-1, -1, -1), new Vec3i(-1, -1, 0), new Vec3i(-1, -1, 1),
new Vec3i(-1, 0, -1), new Vec3i(-1, 0, 0), new Vec3i(-1, 0, 1),
new Vec3i(-1, 1, -1), new Vec3i(-1, 1, 0), new Vec3i(-1, 1, 1),
new Vec3i(0, -1, -1), new Vec3i(0, -1, 0), new Vec3i(0, -1, 1), new Vec3i(0, 0, -1), new Vec3i(0, 0, 0),
new Vec3i(0, 0, 1), new Vec3i(0, 1, -1), new Vec3i(0, 1, 0), new Vec3i(0, 1, 1),
new Vec3i(1, -1, -1), new Vec3i(1, -1, 0), new Vec3i(1, -1, 1), new Vec3i(1, 0, -1), new Vec3i(1, 0, 0),
new Vec3i(1, 0, 1), new Vec3i(1, 1, -1), new Vec3i(1, 1, 0), new Vec3i(1, 1, 1) };
new Vec3i(0, -1, -1), new Vec3i(0, -1, 0), new Vec3i(0, -1, 1),
new Vec3i(0, 0, -1), new Vec3i(0, 0, 0), new Vec3i(0, 0, 1),
new Vec3i(0, 1, -1), new Vec3i(0, 1, 0), new Vec3i(0, 1, 1),
new Vec3i(1, -1, -1), new Vec3i(1, -1, 0), new Vec3i(1, -1, 1),
new Vec3i(1, 0, -1), new Vec3i(1, 0, 0), new Vec3i(1, 0, 1),
new Vec3i(1, 1, -1), new Vec3i(1, 1, 0), new Vec3i(1, 1, 1)
};
public static void addBlockColor(Block block, int color) {
COLOR_BY_BLOCK.put(block, color);
}
public static int getBlockColor(Block block) {
return COLOR_BY_BLOCK.getOrDefault(block, 0xFF000000);
}
public static void setWithoutUpdate(LevelAccessor world, BlockPos pos, BlockState state) {
world.setBlockAndUpdate(pos, state, SET_SILENT);
world.setBlock(pos, state, SET_SILENT);
}
public static void setWithoutUpdate(LevelAccessor world, BlockPos pos, Block block) {
world.setBlockAndUpdate(pos, block.defaultBlockState(), SET_SILENT);
world.setBlock(pos, block.defaultBlockState(), SET_SILENT);
}
public static void setWithUpdate(LevelAccessor world, BlockPos pos, BlockState state) {
world.setBlockAndUpdate(pos, state, SET_OBSERV);
world.setBlock(pos, state, SET_OBSERV);
}
public static void setWithUpdate(LevelAccessor world, BlockPos pos, Block block) {
world.setBlockAndUpdate(pos, block.defaultBlockState(), SET_OBSERV);
world.setBlock(pos, block.defaultBlockState(), SET_OBSERV);
}
public static int upRay(LevelAccessor world, BlockPos pos, int maxDist) {
int length = 0;
for (int j = 1; j < maxDist && (world.isAir(pos.up(j))); j++)
for (int j = 1; j < maxDist && (world.isEmptyBlock(pos.above(j))); j++)
length++;
return length;
}
public static int downRay(LevelAccessor world, BlockPos pos, int maxDist) {
int length = 0;
for (int j = 1; j < maxDist && (world.isAir(pos.down(j))); j++)
for (int j = 1; j < maxDist && (world.isEmptyBlock(pos.below(j))); j++)
length++;
return length;
}
public static int downRayRep(LevelAccessor world, BlockPos pos, int maxDist) {
POS.set(pos);
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) {
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++)
{
POS.setY(POS.getY() - 1);
}
return pos.getY() - POS.getY();
}
public static int raycastSqr(LevelAccessor world, BlockPos pos, int dx, int dy, int dz, int maxDist) {
POS.set(pos);
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) {
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++)
{
POS.move(dx, dy, dz);
}
return (int) pos.getSquaredDistance(POS);
return (int) pos.distSqr(POS);
}
public static BlockState rotateHorizontal(BlockState state, Rotation rotation, Property<Direction> facing) {
return state.with(facing, rotation.rotate(state.getValue(facing)));
return state.setValue(facing, rotation.rotate(state.getValue(facing)));
}
public static BlockState mirrorHorizontal(BlockState state, BlockMirror mirror, Property<Direction> facing) {
public static BlockState mirrorHorizontal(BlockState state, Mirror mirror, Property<Direction> facing) {
return state.rotate(mirror.getRotation(state.getValue(facing)));
}
public static int getLengthDown(LevelAccessor world, BlockPos pos, Block block) {
int count = 1;
while (world.getBlockState(pos.down(count)).getBlock() == block)
while (world.getBlockState(pos.below(count)).getBlock() == block)
count++;
return count;
}
public static void cover(LevelAccessor world, BlockPos center, Block ground, BlockState cover, int radius,
Random random) {
public static void cover(LevelAccessor world, BlockPos center, Block ground, BlockState cover, int radius, Random random) {
HashSet<BlockPos> points = new HashSet<BlockPos>();
HashSet<BlockPos> points2 = new HashSet<BlockPos>();
if (world.getBlockState(center).getBlock() == ground) {
@ -159,7 +162,7 @@ public class BlocksHelper {
}
}
}
public static void fixBlocks(LevelAccessor world, BlockPos start, BlockPos end) {
BlockState state;
Set<BlockPos> doubleCheck = Sets.newHashSet();
@ -170,17 +173,17 @@ public class BlocksHelper {
for (int y = start.getY(); y <= end.getY(); y++) {
POS.setY(y);
state = world.getBlockState(POS);
if (state.getBlock() instanceof FurBlock) {
doubleCheck.add(POS.immutable());
}
// Liquids
else if (!state.getFluidState().isEmpty()) {
if (!state.canPlaceAt(world, POS)) {
if (!state.canSurvive(world, POS)) {
setWithoutUpdate(world, POS, WATER);
POS.setY(POS.getY() - 1);
state = world.getBlockState(POS);
while (!state.canPlaceAt(world, POS)) {
while (!state.canSurvive(world, POS)) {
state = state.getFluidState().isEmpty() ? AIR : WATER;
setWithoutUpdate(world, POS, state);
POS.setY(POS.getY() - 1);
@ -188,7 +191,7 @@ public class BlocksHelper {
}
}
POS.setY(y - 1);
if (world.isAir(POS)) {
if (world.isEmptyBlock(POS)) {
POS.setY(y);
while (!world.getFluidState(POS).isEmpty()) {
setWithoutUpdate(world, POS, AIR);
@ -197,14 +200,15 @@ public class BlocksHelper {
continue;
}
for (Direction dir : HORIZONTAL) {
if (world.isAir(POS.offset(dir))) {
world.getFluidTickScheduler().schedule(POS, state.getFluidState().getFluid(), 0);
if (world.isEmptyBlock(POS.relative(dir))) {
world.getLiquidTicks().scheduleTick(POS, state.getFluidState().getType(), 0);
break;
}
}
} else if (state.is(EndBlocks.SMARAGDANT_CRYSTAL)) {
}
else if (state.is(EndBlocks.SMARAGDANT_CRYSTAL)) {
POS.setY(POS.getY() - 1);
if (world.isAir(POS)) {
if (world.isEmptyBlock(POS)) {
POS.setY(POS.getY() + 1);
while (state.is(EndBlocks.SMARAGDANT_CRYSTAL)) {
setWithoutUpdate(world, POS, AIR);
@ -212,15 +216,17 @@ public class BlocksHelper {
state = world.getBlockState(POS);
}
}
} else if (state.getBlock() instanceof StalactiteBlock) {
if (!state.canPlaceAt(world, POS)) {
if (world.getBlockState(POS.up()).getBlock() instanceof StalactiteBlock) {
}
else if (state.getBlock() instanceof StalactiteBlock) {
if (!state.canSurvive(world, POS)) {
if (world.getBlockState(POS.above()).getBlock() instanceof StalactiteBlock) {
while (state.getBlock() instanceof StalactiteBlock) {
setWithoutUpdate(world, POS, AIR);
POS.setY(POS.getY() + 1);
state = world.getBlockState(POS);
}
} else {
}
else {
while (state.getBlock() instanceof StalactiteBlock) {
setWithoutUpdate(world, POS, AIR);
POS.setY(POS.getY() - 1);
@ -228,11 +234,13 @@ public class BlocksHelper {
}
}
}
} else if (state.is(EndBlocks.CAVE_PUMPKIN)) {
if (!world.getBlockState(POS.up()).is(EndBlocks.CAVE_PUMPKIN_SEED)) {
}
else if (state.is(EndBlocks.CAVE_PUMPKIN)) {
if (!world.getBlockState(POS.above()).is(EndBlocks.CAVE_PUMPKIN_SEED)) {
setWithoutUpdate(world, POS, AIR);
}
} else if (!state.canPlaceAt(world, POS)) {
}
else if (!state.canSurvive(world, POS)) {
// Chorus
if (state.is(Blocks.CHORUS_PLANT)) {
Set<BlockPos> ends = Sets.newHashSet();
@ -245,15 +253,13 @@ public class BlocksHelper {
for (Direction dir : HORIZONTAL) {
BlockPos p = pos.relative(dir);
BlockState st = world.getBlockState(p);
if ((st.is(Blocks.CHORUS_PLANT) || st.is(Blocks.CHORUS_FLOWER))
&& !st.canPlaceAt(world, p)) {
if ((st.is(Blocks.CHORUS_PLANT) || st.is(Blocks.CHORUS_FLOWER)) && !st.canSurvive(world, p)) {
add.add(p);
}
}
BlockPos p = pos.up();
BlockPos p = pos.above();
BlockState st = world.getBlockState(p);
if ((st.is(Blocks.CHORUS_PLANT) || st.is(Blocks.CHORUS_FLOWER))
&& !st.canPlaceAt(world, p)) {
if ((st.is(Blocks.CHORUS_PLANT) || st.is(Blocks.CHORUS_FLOWER)) && !st.canSurvive(world, p)) {
add.add(p);
}
});
@ -284,11 +290,12 @@ public class BlocksHelper {
state = world.getBlockState(POS);
BlocksHelper.setWithoutUpdate(world, POS, Blocks.END_STONE.defaultBlockState());
}
} else {
}
else {
POS.setY(y);
BlockState replacement = AIR;
for (Direction dir : HORIZONTAL) {
state = world.getBlockState(POS.offset(dir));
state = world.getBlockState(POS.relative(dir));
if (!state.getFluidState().isEmpty()) {
replacement = state;
break;
@ -303,8 +310,7 @@ public class BlocksHelper {
else {
// Blue Vine
if (state.getBlock() instanceof BlueVineBlock) {
while (state.is(EndBlocks.BLUE_VINE) || state.is(EndBlocks.BLUE_VINE_LANTERN)
|| state.is(EndBlocks.BLUE_VINE_FUR)) {
while (state.is(EndBlocks.BLUE_VINE) || state.is(EndBlocks.BLUE_VINE_LANTERN) || state.is(EndBlocks.BLUE_VINE_FUR)) {
BlocksHelper.setWithoutUpdate(world, POS, AIR);
POS.setY(POS.getY() + 1);
state = world.getBlockState(POS);
@ -325,34 +331,34 @@ public class BlocksHelper {
}
}
}
doubleCheck.forEach((pos) -> {
if (!world.getBlockState(pos).canPlaceAt(world, pos)) {
if (!world.getBlockState(pos).canSurvive(world, pos)) {
BlocksHelper.setWithoutUpdate(world, pos, AIR);
}
});
}
private static BlockState getAirOrFluid(BlockState state) {
return state.getFluidState().isEmpty() ? AIR : state.getFluidState().getBlockState();
return state.getFluidState().isEmpty() ? AIR : state.getFluidState().createLegacyBlock();
}
public static boolean isEndNylium(Block block) {
return block.isIn(BlockTags.NYLIUM) && block.isIn(EndTags.END_GROUND);
return block.is(BlockTags.NYLIUM) && block.is(EndTags.END_GROUND);
}
public static boolean isEndNylium(BlockState state) {
return isEndNylium(state.getBlock());
}
public static Direction[] makeHorizontal() {
return new Direction[] { Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST };
}
public static Direction randomHorizontal(Random random) {
return HORIZONTAL[random.nextInt(4)];
}
public static Direction randomDirection(Random random) {
return DIRECTIONS[random.nextInt(6)];
}

View file

@ -3,12 +3,10 @@ package ru.betterend.util;
import java.util.List;
import java.util.Map;
import java.util.Random;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.minecraft.world.level.block.Block;
import net.minecraft.resources.ResourceLocation;
import ru.betterend.registry.EndBiomes;
import ru.betterend.registry.EndBlocks;
import ru.betterend.world.biome.EndBiome;
@ -16,59 +14,59 @@ import ru.betterend.world.biome.EndBiome;
public class BonemealUtil {
private static final Map<ResourceLocation, Map<Block, GrassList>> GRASS_BIOMES = Maps.newHashMap();
private static final Map<Block, GrassList> GRASS_TYPES = Maps.newHashMap();
public static void init() {
addBonemealGrass(EndBlocks.END_MOSS, EndBlocks.CREEPING_MOSS);
addBonemealGrass(EndBlocks.END_MOSS, EndBlocks.UMBRELLA_MOSS);
addBonemealGrass(EndBlocks.END_MYCELIUM, EndBlocks.CREEPING_MOSS);
addBonemealGrass(EndBlocks.END_MYCELIUM, EndBlocks.UMBRELLA_MOSS);
addBonemealGrass(EndBlocks.CAVE_MOSS, EndBlocks.CAVE_GRASS);
addBonemealGrass(EndBlocks.CHORUS_NYLIUM, EndBlocks.CHORUS_GRASS);
addBonemealGrass(EndBlocks.CRYSTAL_MOSS, EndBlocks.CRYSTAL_GRASS);
addBonemealGrass(EndBlocks.SHADOW_GRASS, EndBlocks.SHADOW_PLANT);
addBonemealGrass(EndBlocks.PINK_MOSS, EndBlocks.BUSHY_GRASS);
addBonemealGrass(EndBlocks.AMBER_MOSS, EndBlocks.AMBER_GRASS);
addBonemealGrass(EndBlocks.JUNGLE_MOSS, EndBlocks.JUNGLE_GRASS);
addBonemealGrass(EndBlocks.JUNGLE_MOSS, EndBlocks.TWISTED_UMBRELLA_MOSS);
addBonemealGrass(EndBlocks.JUNGLE_MOSS, EndBlocks.SMALL_JELLYSHROOM, 0.1F);
addBonemealGrass(EndBiomes.GLOWING_GRASSLANDS, EndBlocks.END_MOSS, EndBlocks.BLOOMING_COOKSONIA);
addBonemealGrass(EndBiomes.GLOWING_GRASSLANDS, EndBlocks.END_MOSS, EndBlocks.VAIOLUSH_FERN);
addBonemealGrass(EndBiomes.GLOWING_GRASSLANDS, EndBlocks.END_MOSS, EndBlocks.FRACTURN);
addBonemealGrass(EndBiomes.GLOWING_GRASSLANDS, EndBlocks.END_MOSS, EndBlocks.SALTEAGO);
addBonemealGrass(EndBiomes.GLOWING_GRASSLANDS, EndBlocks.END_MOSS, EndBlocks.CREEPING_MOSS, 0.1F);
addBonemealGrass(EndBiomes.GLOWING_GRASSLANDS, EndBlocks.END_MOSS, EndBlocks.UMBRELLA_MOSS, 0.1F);
addBonemealGrass(EndBiomes.GLOWING_GRASSLANDS, EndBlocks.END_MOSS, EndBlocks.TWISTED_UMBRELLA_MOSS, 0.1F);
addBonemealGrass(EndBlocks.RUTISCUS, EndBlocks.ORANGO);
addBonemealGrass(EndBlocks.RUTISCUS, EndBlocks.AERIDIUM, 0.2F);
addBonemealGrass(EndBlocks.RUTISCUS, EndBlocks.LUTEBUS, 0.2F);
addBonemealGrass(EndBlocks.RUTISCUS, EndBlocks.LAMELLARIUM);
addBonemealGrass(EndBiomes.LANTERN_WOODS, EndBlocks.RUTISCUS, EndBlocks.AERIDIUM, 0.2F);
addBonemealGrass(EndBiomes.LANTERN_WOODS, EndBlocks.RUTISCUS, EndBlocks.LAMELLARIUM);
addBonemealGrass(EndBiomes.LANTERN_WOODS, EndBlocks.RUTISCUS, EndBlocks.BOLUX_MUSHROOM, 0.05F);
addBonemealGrass(EndBlocks.SANGNUM, EndBlocks.GLOBULAGUS);
addBonemealGrass(EndBlocks.SANGNUM, EndBlocks.CLAWFERN);
addBonemealGrass(EndBlocks.SANGNUM, EndBlocks.SMALL_AMARANITA_MUSHROOM, 0.1F);
addBonemealGrass(EndBlocks.MOSSY_DRAGON_BONE, EndBlocks.GLOBULAGUS);
addBonemealGrass(EndBlocks.MOSSY_DRAGON_BONE, EndBlocks.CLAWFERN);
addBonemealGrass(EndBlocks.MOSSY_DRAGON_BONE, EndBlocks.SMALL_AMARANITA_MUSHROOM, 0.1F);
addBonemealGrass(EndBlocks.MOSSY_OBSIDIAN, EndBlocks.GLOBULAGUS);
addBonemealGrass(EndBlocks.MOSSY_OBSIDIAN, EndBlocks.CLAWFERN);
addBonemealGrass(EndBlocks.MOSSY_OBSIDIAN, EndBlocks.SMALL_AMARANITA_MUSHROOM, 0.1F);
}
public static void addBonemealGrass(Block terrain, Block plant) {
addBonemealGrass(terrain, plant, 1F);
}
public static void addBonemealGrass(Block terrain, Block plant, float chance) {
GrassList list = GRASS_TYPES.get(terrain);
if (list == null) {
@ -77,11 +75,11 @@ public class BonemealUtil {
}
list.addGrass(plant, chance);
}
public static void addBonemealGrass(EndBiome biome, Block terrain, Block plant) {
addBonemealGrass(biome, terrain, plant, 1F);
}
public static void addBonemealGrass(EndBiome biome, Block terrain, Block plant, float chance) {
Map<Block, GrassList> map = GRASS_BIOMES.get(biome.getID());
if (map == null) {
@ -95,7 +93,7 @@ public class BonemealUtil {
}
list.addGrass(plant, chance);
}
public static Block getGrass(ResourceLocation biomeID, Block terrain, Random random) {
Map<Block, GrassList> map = GRASS_BIOMES.get(biomeID);
GrassList list = null;
@ -104,43 +102,44 @@ public class BonemealUtil {
if (list == null) {
list = GRASS_TYPES.get(terrain);
}
} else {
}
else {
list = GRASS_TYPES.get(terrain);
}
return list == null ? null : list.getGrass(random);
}
private static final class GrassInfo {
final Block grass;
float chance;
public GrassInfo(Block grass, float chance) {
this.grass = grass;
this.chance = chance;
}
public float addChance(float chance) {
this.chance += chance;
return this.chance;
}
}
private static final class GrassList {
final List<GrassInfo> list = Lists.newArrayList();
float maxChance = 0;
public void addGrass(Block grass, float chance) {
GrassInfo info = new GrassInfo(grass, chance);
maxChance = info.addChance(maxChance);
list.add(info);
}
public Block getGrass(Random random) {
if (maxChance == 0 || list.isEmpty()) {
return null;
}
float chance = random.nextFloat() * maxChance;
for (GrassInfo info : list) {
for (GrassInfo info: list) {
if (chance <= info.chance) {
return info.grass;
}

View file

@ -6,50 +6,52 @@ import java.util.List;
import java.util.Map;
import com.google.common.collect.Maps;
import com.mojang.blaze3d.platform.NativeImage;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.impl.client.indigo.renderer.helper.ColorHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.Mth;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.core.Registry;
import ru.betterend.BetterEnd;
@Environment(EnvType.CLIENT)
public class ColorUtil {
private static float[] floatBuffer = new float[4];
public static int[] toIntArray(int color) {
return new int[] { (color >> 24) & 255, (color >> 16) & 255, (color >> 8) & 255, color & 255 };
return new int[] {
(color >> 24) & 255,
(color >> 16) & 255,
(color >> 8) & 255,
color & 255
};
}
public static float[] toFloatArray(int color) {
floatBuffer[0] = ((color >> 16 & 255) / 255.0F);
floatBuffer[1] = ((color >> 8 & 255) / 255.0F);
floatBuffer[2] = ((color & 255) / 255.0F);
floatBuffer[3] = ((color >> 24 & 255) / 255.0F);
return floatBuffer;
}
public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals) {
float hue, saturation, brightness;
if (hsbvals == null) {
hsbvals = floatBuffer;
}
int cmax = (r > g) ? r : g;
if (b > cmax)
cmax = b;
if (b > cmax) cmax = b;
int cmin = (r < g) ? r : g;
if (b < cmin)
cmin = b;
if (b < cmin) cmin = b;
brightness = ((float) cmax) / 255.0F;
if (cmax != 0)
@ -77,14 +79,14 @@ public class ColorUtil {
hsbvals[2] = brightness;
return hsbvals;
}
public static int HSBtoRGB(float hue, float saturation, float brightness) {
int r = 0, g = 0, b = 0;
if (saturation == 0) {
r = g = b = (int) (brightness * 255.0F + 0.5F);
} else {
float h = (hue - (float) Math.floor(hue)) * 6.0F;
float f = h - (float) java.lang.Math.floor(h);
float h = (hue - (float)Math.floor(hue)) * 6.0F;
float f = h - (float)java.lang.Math.floor(h);
float p = brightness * (1.0F - saturation);
float q = brightness * (1.0F - saturation * f);
float t = brightness * (1.0F - (saturation * (1.0F - f)));
@ -123,43 +125,41 @@ public class ColorUtil {
}
return 0xFF000000 | (r << 16) | (g << 8) | (b << 0);
}
public static int parseHex(String hexColor) {
int len = hexColor.length();
if (len < 6 || len > 8 || len % 2 > 0) {
return -1;
}
int color, shift;
if (len == 6) {
color = 0xFF000000;
shift = 16;
if(len == 6) {
color = 0xFF000000; shift = 16;
} else {
color = 0;
shift = 24;
color = 0; shift = 24;
}
try {
String[] splited = hexColor.split("(?<=\\G.{2})");
for (String digit : splited) {
color |= Integer.valueOf(digit, 16) << shift;
shift -= 8;
}
} catch (NumberFormatException ex) {
} catch(NumberFormatException ex) {
BetterEnd.LOGGER.catching(ex);
return -1;
}
return color;
}
public static int toABGR(int color) {
int r = (color >> 16) & 255;
int g = (color >> 8) & 255;
int b = color & 255;
return 0xFF000000 | b << 16 | g << 8 | r;
}
public static int ABGRtoARGB(int color) {
int a = (color >> 24) & 255;
int b = (color >> 16) & 255;
@ -167,18 +167,18 @@ public class ColorUtil {
int r = color & 255;
return a << 24 | r << 16 | g << 8 | b;
}
public static int colorBrigtness(int color, float val) {
RGBtoHSB((color >> 16) & 255, (color >> 8) & 255, color & 255, floatBuffer);
floatBuffer[2] += val / 10.0F;
floatBuffer[2] = Mth.clamp(floatBuffer[2], 0.0F, 1.0F);
return HSBtoRGB(floatBuffer[0], floatBuffer[1], floatBuffer[2]);
}
public static int applyTint(int color, int tint) {
return colorBrigtness(ColorHelper.multiplyColor(color, tint), 1.5F);
}
public static int colorDistance(int color1, int color2) {
int r1 = (color1 >> 16) & 255;
int g1 = (color1 >> 8) & 255;
@ -188,13 +188,12 @@ public class ColorUtil {
int b2 = color2 & 255;
return MHelper.pow2(r1 - r2) + MHelper.pow2(g1 - g2) + MHelper.pow2(b1 - b2);
}
private static Map<ResourceLocation, Integer> colorPalette = Maps.newHashMap();
public static int extractColor(Item item) {
ResourceLocation id = Registry.ITEM.getId(item);
if (id.equals(Registry.ITEM.getDefaultKey()))
return -1;
ResourceLocation id = Registry.ITEM.getKey(item);
if (id.equals(Registry.ITEM.getDefaultKey())) return -1;
if (colorPalette.containsKey(id)) {
return colorPalette.get(id);
}
@ -208,35 +207,34 @@ public class ColorUtil {
List<Integer> colors = new ArrayList<>();
for (int i = 0; i < image.getWidth(); i++) {
for (int j = 0; j < 16; j++) {
int col = image.getPixelColor(i, j);
int col = image.getPixelRGBA(i, j);
if (((col >> 24) & 255) > 0) {
colors.add(ABGRtoARGB(col));
}
}
}
image.close();
if (colors.size() == 0)
return -1;
if (colors.size() == 0) return -1;
ColorExtractor extractor = new ColorExtractor(colors);
int color = extractor.analize();
colorPalette.put(id, color);
return color;
}
public static NativeImage loadImage(ResourceLocation image, int w, int h) {
Minecraft minecraft = Minecraft.getInstance();
ResourceManager resourceManager = minecraft.getResourceManager();
if (resourceManager.containsResource(image)) {
if (resourceManager.hasResource(image)) {
try (Resource resource = resourceManager.getResource(image)) {
return NativeImage.read(resource.getInputStream());
return NativeImage.read(resource.getInputStream());
} catch (IOException e) {
BetterEnd.LOGGER.warning("Can't load texture image: {}. Will be created empty image.", image);
BetterEnd.LOGGER.warning("Cause: {}.", e.getMessage());
}
}
}
return new NativeImage(w, h, false);
}
}

View file

@ -12,8 +12,8 @@ import com.google.common.collect.Maps;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.storage.RegionFile;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.storage.RegionFile;
public class DataFixerUtil {
private static final Map<String, String> REPLACEMENT = Maps.newHashMap();
@ -38,7 +38,7 @@ public class DataFixerUtil {
ChunkPos pos = new ChunkPos(x, z);
changed[0] = false;
if (region.hasChunk(pos)) {
DataInputStream input = region.getChunkInputStream(pos);
DataInputStream input = region.getChunkDataInputStream(pos);
CompoundTag root = NbtIo.read(input);
input.close();
ListTag sections = root.getCompound("Level").getList("Sections", 10);
@ -56,7 +56,7 @@ public class DataFixerUtil {
});
if (changed[0]) {
System.out.println("Write!");
DataOutputStream output = region.getChunkOutputStream(pos);
DataOutputStream output = region.getChunkDataOutputStream(pos);
NbtIo.write(root, output);
output.close();
}

View file

@ -4,14 +4,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import net.minecraft.core.Registry;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import ru.betterend.mixin.common.GenerationSettingsAccessor;
import ru.betterend.registry.EndFeatures;
import ru.betterend.registry.EndStructures;
@ -21,24 +19,22 @@ public class FeaturesHelper {
public static void addFeatures(Registry<Biome> biomeRegistry) {
biomeRegistry.forEach((biome) -> {
if (biome.getCategory() == Biome.Category.THEEND && !INJECTED.contains(biome)) {
if (biome.getBiomeCategory() == Biome.BiomeCategory.THEEND && !INJECTED.contains(biome)) {
GenerationSettingsAccessor accessor = (GenerationSettingsAccessor) biome.getGenerationSettings();
List<Supplier<ConfiguredStructureFeature<?, ?>>> structures = Lists
.newArrayList(accessor.beGetStructures());
List<Supplier<ConfiguredStructureFeature<?, ?>>> structures = Lists.newArrayList(accessor.beGetStructures());
List<List<Supplier<ConfiguredFeature<?, ?>>>> preFeatures = accessor.beGetFeatures();
List<List<Supplier<ConfiguredFeature<?, ?>>>> features = new ArrayList<List<Supplier<ConfiguredFeature<?, ?>>>>(
preFeatures.size());
List<List<Supplier<ConfiguredFeature<?, ?>>>> features = new ArrayList<List<Supplier<ConfiguredFeature<?, ?>>>>(preFeatures.size());
preFeatures.forEach((list) -> {
features.add(Lists.newArrayList(list));
});
EndFeatures.registerBiomeFeatures(biomeRegistry.getId(biome), biome, features);
EndStructures.registerBiomeStructures(biomeRegistry.getId(biome), biome, structures);
EndFeatures.registerBiomeFeatures(biomeRegistry.getKey(biome), biome, features);
EndStructures.registerBiomeStructures(biomeRegistry.getKey(biome), biome, structures);
accessor.beSetFeatures(features);
accessor.beSetStructures(structures);
INJECTED.add(biome);
}
});
});
}
}

View file

@ -4,29 +4,28 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.google.gson.JsonObject;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.JsonHelper;
import net.minecraft.core.Registry;
import ru.betterend.BetterEnd;
public class ItemUtil {
public static String toStackString(@NotNull ItemStack stack) {
try {
if (stack == null) {
throw new IllegalStateException("Stack can't be null!");
}
Item item = stack.getItem();
return Registry.ITEM.getId(item) + ":" + stack.getCount();
return Registry.ITEM.getKey(item) + ":" + stack.getCount();
} catch (Exception ex) {
BetterEnd.LOGGER.error("ItemStack serialization error!", ex);
}
return "";
}
@Nullable
public static ItemStack fromStackString(String stackString) {
if (stackString == null || stackString.equals("")) {
@ -34,17 +33,16 @@ public class ItemUtil {
}
try {
String[] parts = stackString.split(":");
if (parts.length < 2)
return null;
if (parts.length < 2) return null;
if (parts.length == 2) {
ResourceLocation itemId = new ResourceLocation(stackString);
Item item = Registry.ITEM.getOrEmpty(itemId).orElseThrow(() -> {
Item item = Registry.ITEM.getOptional(itemId).orElseThrow(() -> {
return new IllegalStateException("Output item " + itemId + " does not exists!");
});
return new ItemStack(item);
}
ResourceLocation itemId = new ResourceLocation(parts[0], parts[1]);
Item item = Registry.ITEM.getOrEmpty(itemId).orElseThrow(() -> {
Item item = Registry.ITEM.getOptional(itemId).orElseThrow(() -> {
return new IllegalStateException("Output item " + itemId + " does not exists!");
});
return new ItemStack(item, Integer.valueOf(parts[2]));
@ -53,18 +51,18 @@ public class ItemUtil {
}
return null;
}
@Nullable
public static ItemStack fromJsonRecipe(JsonObject recipe) {
try {
if (!recipe.has("item")) {
throw new IllegalStateException("Invalid JsonObject. Entry 'item' does not exists!");
}
ResourceLocation itemId = new ResourceLocation(JsonHelper.getString(recipe, "item"));
Item item = Registry.ITEM.getOrEmpty(itemId).orElseThrow(() -> {
ResourceLocation itemId = new ResourceLocation(GsonHelper.getAsString(recipe, "item"));
Item item = Registry.ITEM.getOptional(itemId).orElseThrow(() -> {
return new IllegalStateException("Output item " + itemId + " does not exists!");
});
int count = JsonHelper.getInt(recipe, "count", 1);
int count = GsonHelper.getAsInt(recipe, "count", 1);
return new ItemStack(item, count);
} catch (Exception ex) {
BetterEnd.LOGGER.error("ItemStack deserialization error!", ex);

View file

@ -1,7 +1,7 @@
package ru.betterend.util;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.text.TranslatableText;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.TranslatableComponent;
public class LangUtil {
public final static String CONFIG_ELEMENT = "configuration";
@ -20,19 +20,19 @@ public class LangUtil {
return getString(element, key);
}
public TranslatableText getText(String key) {
public TranslatableComponent getText(String key) {
return getText(element, key);
}
public static String translate(String key) {
return I18n.translate(key);
return I18n.get(key);
}
public static String getString(String element, String key) {
return translate(String.format("%s.%s", element, key));
}
public static TranslatableText getText(String element, String key) {
return new TranslatableText(getString(element, key));
public static TranslatableComponent getText(String element, String key) {
return new TranslatableComponent(getString(element, key));
}
}

View file

@ -2,11 +2,11 @@ package ru.betterend.util;
import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder;
import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback;
import net.minecraft.world.item.Items;
import net.minecraft.loot.UniformLootTableRange;
import net.minecraft.loot.condition.RandomChanceLootCondition;
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.storage.loot.RandomValueBounds;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceCondition;
import ru.betterend.registry.EndItems;
public class LootTableUtil {
@ -16,11 +16,11 @@ public class LootTableUtil {
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> {
if (END_CITY_TREASURE_ID.equals(id)) {
FabricLootPoolBuilder builder = FabricLootPoolBuilder.builder();
builder.rolls(UniformLootTableRange.between(0, 5));
builder.withCondition(RandomChanceLootCondition.builder(0.5f).build());
builder.withEntry(ItemEntry.builder(Items.GHAST_TEAR).build());
builder.withEntry(ItemEntry.builder(EndItems.MUSIC_DISC_STRANGE_AND_ALIEN).build());
supplier.pool(builder);
builder.setRolls(RandomValueBounds.between(0, 5));
builder.withCondition(LootItemRandomChanceCondition.randomChance(0.5f).build());
builder.withEntry(LootItem.lootTableItem(Items.GHAST_TEAR).build());
builder.withEntry(LootItem.lootTableItem(EndItems.MUSIC_DISC_STRANGE_AND_ALIEN).build());
supplier.withPool(builder);
}
});
}

View file

@ -1,9 +1,8 @@
package ru.betterend.util;
import java.util.Random;
import com.mojang.math.Vector3f;
import net.minecraft.util.math.Vec3d;
import java.util.Random;
import net.minecraft.world.phys.Vec3;
public class MHelper {
public static final float PI2 = (float) (Math.PI * 2);
@ -15,7 +14,7 @@ public class MHelper {
public static int color(int r, int g, int b) {
return ALPHA | (r << 16) | (g << 8) | b;
}
public static int color(String hex) {
int r = Integer.parseInt(hex.substring(0, 2), 16);
int g = Integer.parseInt(hex.substring(2, 4), 16);
@ -26,7 +25,7 @@ public class MHelper {
public static int randRange(int min, int max, Random random) {
return min + random.nextInt(max - min + 1);
}
public static double randRange(double min, double max, Random random) {
return min + random.nextDouble() * (max - min);
}
@ -68,81 +67,81 @@ public class MHelper {
public static int min(int a, int b) {
return a < b ? a : b;
}
public static int min(int a, int b, int c) {
return min(a, min(b, c));
}
public static int max(int a, int b) {
return a > b ? a : b;
}
public static float min(float a, float b) {
return a < b ? a : b;
}
public static float max(float a, float b) {
return a > b ? a : b;
}
public static float max(float a, float b, float c) {
return max(a, max(b, c));
}
public static int max(int a, int b, int c) {
return max(a, max(b, c));
}
public static boolean isEven(int num) {
return (num & 1) == 0;
}
public static float lengthSqr(float x, float y, float z) {
return x * x + y * y + z * z;
}
public static double lengthSqr(double x, double y, double z) {
return x * x + y * y + z * z;
}
public static float length(float x, float y, float z) {
return (float) Math.sqrt(lengthSqr(x, y, z));
}
public static double length(double x, double y, double z) {
return Math.sqrt(lengthSqr(x, y, z));
}
public static float lengthSqr(float x, float y) {
return x * x + y * y;
}
public static double lengthSqr(double x, double y) {
return x * x + y * y;
}
public static float length(float x, float y) {
return (float) Math.sqrt(lengthSqr(x, y));
}
public static double length(double x, double y) {
return Math.sqrt(lengthSqr(x, y));
}
public static float dot(float x1, float y1, float z1, float x2, float y2, float z2) {
return x1 * x2 + y1 * y2 + z1 * z2;
}
public static float dot(float x1, float y1, float x2, float y2) {
return x1 * x2 + y1 * y2;
}
public static int getRandom(int x, int z) {
int h = x * 374761393 + z * 668265263;
h = (h ^ (h >> 13)) * 1274126177;
return h ^ (h >> 16);
}
public static int getSeed(int seed, int x, int y) {
int h = seed + x * 374761393 + y * 668265263;
h = (h ^ (h >> 13)) * 1274126177;
@ -154,7 +153,7 @@ public class MHelper {
h = (h ^ (h >> 13)) * 1274126177;
return h ^ (h >> 16);
}
public static <T> void shuffle(T[] array, Random random) {
for (int i = 0; i < array.length; i++) {
int i2 = random.nextInt(array.length);
@ -167,15 +166,15 @@ public class MHelper {
public static int pow2(int i) {
return i * i;
}
public static float pow2(float f) {
return f * f;
}
public static double pow2(double d) {
return d * d;
}
public static int fromHSBtoRGB(float hue, float saturation, float brightness) {
int red = 0;
int green = 0;
@ -189,35 +188,35 @@ public class MHelper {
float var9 = brightness * (1.0F - saturation * var7);
float var10 = brightness * (1.0F - saturation * (1.0F - var7));
switch ((int) var6) {
case 0:
red = (int) (brightness * 255.0F + 0.5F);
green = (int) (var10 * 255.0F + 0.5F);
blue = (int) (var8 * 255.0F + 0.5F);
break;
case 1:
red = (int) (var9 * 255.0F + 0.5F);
green = (int) (brightness * 255.0F + 0.5F);
blue = (int) (var8 * 255.0F + 0.5F);
break;
case 2:
red = (int) (var8 * 255.0F + 0.5F);
green = (int) (brightness * 255.0F + 0.5F);
blue = (int) (var10 * 255.0F + 0.5F);
break;
case 3:
red = (int) (var8 * 255.0F + 0.5F);
green = (int) (var9 * 255.0F + 0.5F);
blue = (int) (brightness * 255.0F + 0.5F);
break;
case 4:
red = (int) (var10 * 255.0F + 0.5F);
green = (int) (var8 * 255.0F + 0.5F);
blue = (int) (brightness * 255.0F + 0.5F);
break;
case 5:
red = (int) (brightness * 255.0F + 0.5F);
green = (int) (var8 * 255.0F + 0.5F);
blue = (int) (var9 * 255.0F + 0.5F);
case 0 :
red = (int) (brightness * 255.0F + 0.5F);
green = (int) (var10 * 255.0F + 0.5F);
blue = (int) (var8 * 255.0F + 0.5F);
break;
case 1 :
red = (int) (var9 * 255.0F + 0.5F);
green = (int) (brightness * 255.0F + 0.5F);
blue = (int) (var8 * 255.0F + 0.5F);
break;
case 2 :
red = (int) (var8 * 255.0F + 0.5F);
green = (int) (brightness * 255.0F + 0.5F);
blue = (int) (var10 * 255.0F + 0.5F);
break;
case 3 :
red = (int) (var8 * 255.0F + 0.5F);
green = (int) (var9 * 255.0F + 0.5F);
blue = (int) (brightness * 255.0F + 0.5F);
break;
case 4 :
red = (int) (var10 * 255.0F + 0.5F);
green = (int) (var8 * 255.0F + 0.5F);
blue = (int) (brightness * 255.0F + 0.5F);
break;
case 5 :
red = (int) (brightness * 255.0F + 0.5F);
green = (int) (var8 * 255.0F + 0.5F);
blue = (int) (var9 * 255.0F + 0.5F);
}
}
@ -241,7 +240,8 @@ public class MHelper {
float hue;
if (saturation == 0.0F) {
hue = 0.0F;
} else {
}
else {
float var9 = (float) (max - r) / (float) (max - min);
float var10 = (float) (max - g) / (float) (max - min);
float var11 = (float) (max - b) / (float) (max - min);
@ -262,11 +262,11 @@ public class MHelper {
values[0] = hue;
values[1] = saturation;
values[2] = brightness;
return values;
}
public static Vec3d fromRGBtoHSBV(int r, int g, int b) {
public static Vec3 fromRGBtoHSBV(int r, int g, int b) {
int max = max(r, g, b);
int min = min(r, g, b);
@ -281,7 +281,8 @@ public class MHelper {
float hue;
if (saturation == 0.0F) {
hue = 0.0F;
} else {
}
else {
float var9 = (float) (max - r) / (float) (max - min);
float var10 = (float) (max - g) / (float) (max - min);
float var11 = (float) (max - b) / (float) (max - min);
@ -298,25 +299,26 @@ public class MHelper {
++hue;
}
}
return new Vec3d(hue, saturation, brightness);
return new Vec3(hue, saturation, brightness);
}
public static final float radiansToDegrees(float value) {
return value * RAD_TO_DEG;
}
public static final float degreesToRadians(float value) {
return value / RAD_TO_DEG;
}
public static Vector3f cross(Vector3f vec1, Vector3f vec2) {
float cx = vec1.getY() * vec2.getZ() - vec1.getZ() * vec2.getY();
float cy = vec1.getZ() * vec2.getX() - vec1.getX() * vec2.getZ();
float cz = vec1.getX() * vec2.getY() - vec1.getY() * vec2.getX();
public static Vector3f cross(Vector3f vec1, Vector3f vec2)
{
float cx = vec1.y() * vec2.z() - vec1.z() * vec2.y();
float cy = vec1.z() * vec2.x() - vec1.x() * vec2.z();
float cz = vec1.x() * vec2.y() - vec1.y() * vec2.x();
return new Vector3f(cx, cy, cz);
}
public static Vector3f normalize(Vector3f vec) {
float length = lengthSqr(vec.x(), vec.y(), vec.z());
if (length > 0) {
@ -328,14 +330,14 @@ public class MHelper {
}
return vec;
}
public static float angle(Vector3f vec1, Vector3f vec2) {
float dot = vec1.getX() * vec2.getX() + vec1.getY() * vec2.getY() + vec1.getZ() * vec2.getZ();
float length1 = lengthSqr(vec1.getX(), vec1.getY(), vec1.getZ());
float length2 = lengthSqr(vec2.getX(), vec2.getY(), vec2.getZ());
float dot = vec1.x() * vec2.x() + vec1.y() * vec2.y() + vec1.z() * vec2.z();
float length1 = lengthSqr(vec1.x(), vec1.y(), vec1.z());
float length2 = lengthSqr(vec2.x(), vec2.y(), vec2.z());
return (float) Math.acos(dot / Math.sqrt(length1 * length2));
}
public static Vector3f randomHorizontal(Random random) {
float angleY = MHelper.randRange(0, MHelper.PI2, random);
float vx = (float) Math.sin(angleY);

View file

@ -1,18 +1,18 @@
package ru.betterend.util;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.ItemLike;
import net.minecraft.core.Registry;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block;
public class RecipeHelper {
public static boolean exists(ItemLike item) {
if (item instanceof Block) {
return Registry.BLOCK.getKey((Block) item) != Registry.BLOCK.getDefaultKey();
} else {
return Registry.ITEM.getId(item.asItem()) != Registry.ITEM.getDefaultKey();
return Registry.ITEM.getKey(item.asItem()) != Registry.ITEM.getDefaultKey();
}
}
public static boolean exists(ItemLike... items) {
for (ItemLike item : items) {
if (!exists(item)) {

View file

@ -2,21 +2,21 @@ package ru.betterend.util;
import net.fabricmc.fabric.mixin.object.builder.SpawnRestrictionAccessor;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.SpawnRestriction.Location;
import net.minecraft.world.entity.SpawnRestriction.SpawnPredicate;
import net.minecraft.world.entity.mob.MobEntity;
import net.minecraft.world.Heightmap.Type;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.SpawnPlacements.SpawnPredicate;
import net.minecraft.world.entity.SpawnPlacements.Type;
import net.minecraft.world.level.levelgen.Heightmap.Types;
public class SpawnHelper {
public static <T extends MobEntity> void restrictionAir(EntityType<T> entity, SpawnPredicate<T> predicate) {
SpawnRestrictionAccessor.callRegister(entity, Location.NO_RESTRICTIONS, Type.MOTION_BLOCKING, predicate);
public static <T extends Mob> void restrictionAir(EntityType<T> entity, SpawnPredicate<T> predicate) {
SpawnRestrictionAccessor.callRegister(entity, Type.NO_RESTRICTIONS, Types.MOTION_BLOCKING, predicate);
}
public static <T extends MobEntity> void restrictionLand(EntityType<T> entity, SpawnPredicate<T> predicate) {
SpawnRestrictionAccessor.callRegister(entity, Location.ON_GROUND, Type.MOTION_BLOCKING, predicate);
public static <T extends Mob> void restrictionLand(EntityType<T> entity, SpawnPredicate<T> predicate) {
SpawnRestrictionAccessor.callRegister(entity, Type.ON_GROUND, Types.MOTION_BLOCKING, predicate);
}
public static <T extends MobEntity> void restrictionWater(EntityType<T> entity, SpawnPredicate<T> predicate) {
SpawnRestrictionAccessor.callRegister(entity, Location.IN_WATER, Type.MOTION_BLOCKING, predicate);
public static <T extends Mob> void restrictionWater(EntityType<T> entity, SpawnPredicate<T> predicate) {
SpawnRestrictionAccessor.callRegister(entity, Type.IN_WATER, Types.MOTION_BLOCKING, predicate);
}
}

View file

@ -4,15 +4,13 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.function.Function;
import com.google.common.collect.Lists;
import net.minecraft.world.level.block.state.BlockState;
import com.mojang.math.Vector3f;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.state.BlockState;
import com.google.common.collect.Lists;
import com.mojang.math.Vector3f;
import ru.betterend.util.sdf.SDF;
import ru.betterend.util.sdf.operator.SDFUnion;
import ru.betterend.util.sdf.primitive.SDFLine;
@ -32,7 +30,7 @@ public class SplineHelper {
spline.add(new Vector3f(x2, y2, z2));
return spline;
}
public static List<Vector3f> smoothSpline(List<Vector3f> spline, int segmentPoints) {
List<Vector3f> result = Lists.newArrayList();
Vector3f start = spline.get(0);
@ -48,38 +46,37 @@ public class SplineHelper {
result.add(start);
return result;
}
private static Vector3f lerp(Vector3f start, Vector3f end, float delta) {
float x = Mth.lerp(delta, start.getX(), end.getX());
float y = Mth.lerp(delta, start.getY(), end.getY());
float z = Mth.lerp(delta, start.getZ(), end.getZ());
float x = Mth.lerp(delta, start.x(), end.x());
float y = Mth.lerp(delta, start.y(), end.y());
float z = Mth.lerp(delta, start.z(), end.z());
return new Vector3f(x, y, z);
}
public static void offsetParts(List<Vector3f> spline, Random random, float dx, float dy, float dz) {
int count = spline.size();
for (int i = 1; i < count; i++) {
Vector3f pos = spline.get(i);
float x = pos.getX() + (float) random.nextGaussian() * dx;
float y = pos.getY() + (float) random.nextGaussian() * dy;
float z = pos.getZ() + (float) random.nextGaussian() * dz;
float x = pos.x() + (float) random.nextGaussian() * dx;
float y = pos.y() + (float) random.nextGaussian() * dy;
float z = pos.z() + (float) random.nextGaussian() * dz;
pos.set(x, y, z);
}
}
public static void powerOffset(List<Vector3f> spline, float distance, float power) {
int count = spline.size();
float max = count + 1;
for (int i = 1; i < count; i++) {
Vector3f pos = spline.get(i);
float x = (float) i / max;
float y = pos.getY() + (float) Math.pow(x, power) * distance;
pos.set(pos.getX(), y, pos.getZ());
float y = pos.y() + (float) Math.pow(x, power) * distance;
pos.set(pos.x(), y, pos.z());
}
}
public static SDF buildSDF(List<Vector3f> spline, float radius1, float radius2,
Function<BlockPos, BlockState> placerFunction) {
public static SDF buildSDF(List<Vector3f> spline, float radius1, float radius2, Function<BlockPos, BlockState> placerFunction) {
int count = spline.size();
float max = count - 2;
SDF result = null;
@ -87,17 +84,18 @@ public class SplineHelper {
for (int i = 1; i < count; i++) {
Vector3f pos = spline.get(i);
float delta = (float) (i - 1) / max;
SDF line = new SDFLine().setRadius(Mth.lerp(delta, radius1, radius2))
.setStart(start.getX(), start.getY(), start.getZ()).setEnd(pos.getX(), pos.getY(), pos.getZ())
SDF line = new SDFLine()
.setRadius(Mth.lerp(delta, radius1, radius2))
.setStart(start.x(), start.y(), start.z())
.setEnd(pos.x(), pos.y(), pos.z())
.setBlock(placerFunction);
result = result == null ? line : new SDFUnion().setSourceA(result).setSourceB(line);
start = pos;
}
return result;
}
public static SDF buildSDF(List<Vector3f> spline, Function<Float, Float> radiusFunction,
Function<BlockPos, BlockState> placerFunction) {
public static SDF buildSDF(List<Vector3f> spline, Function<Float, Float> radiusFunction, Function<BlockPos, BlockState> placerFunction) {
int count = spline.size();
float max = count - 2;
SDF result = null;
@ -105,17 +103,18 @@ public class SplineHelper {
for (int i = 1; i < count; i++) {
Vector3f pos = spline.get(i);
float delta = (float) (i - 1) / max;
SDF line = new SDFLine().setRadius(radiusFunction.apply(delta))
.setStart(start.getX(), start.getY(), start.getZ()).setEnd(pos.getX(), pos.getY(), pos.getZ())
SDF line = new SDFLine()
.setRadius(radiusFunction.apply(delta))
.setStart(start.x(), start.y(), start.z())
.setEnd(pos.x(), pos.y(), pos.z())
.setBlock(placerFunction);
result = result == null ? line : new SDFUnion().setSourceA(result).setSourceB(line);
start = pos;
}
return result;
}
public static boolean fillSpline(List<Vector3f> spline, WorldGenLevel world, BlockState state, BlockPos pos,
Function<BlockState, Boolean> replace) {
public static boolean fillSpline(List<Vector3f> spline, WorldGenLevel world, BlockState state, BlockPos pos, Function<BlockState, Boolean> replace) {
Vector3f startPos = spline.get(0);
for (int i = 1; i < spline.size(); i++) {
Vector3f endPos = spline.get(i);
@ -124,12 +123,11 @@ public class SplineHelper {
}
startPos = endPos;
}
return true;
}
public static void fillSplineForce(List<Vector3f> spline, WorldGenLevel world, BlockState state, BlockPos pos,
Function<BlockState, Boolean> replace) {
public static void fillSplineForce(List<Vector3f> spline, WorldGenLevel world, BlockState state, BlockPos pos, Function<BlockState, Boolean> replace) {
Vector3f startPos = spline.get(0);
for (int i = 1; i < spline.size(); i++) {
Vector3f endPos = spline.get(i);
@ -137,22 +135,21 @@ public class SplineHelper {
startPos = endPos;
}
}
public static boolean fillLine(Vector3f start, Vector3f end, WorldGenLevel world, BlockState state, BlockPos pos,
Function<BlockState, Boolean> replace) {
float dx = end.getX() - start.getX();
float dy = end.getY() - start.getY();
float dz = end.getZ() - start.getZ();
public static boolean fillLine(Vector3f start, Vector3f end, WorldGenLevel world, BlockState state, BlockPos pos, Function<BlockState, Boolean> replace) {
float dx = end.x() - start.x();
float dy = end.y() - start.y();
float dz = end.z() - start.z();
float max = MHelper.max(Math.abs(dx), Math.abs(dy), Math.abs(dz));
int count = MHelper.floor(max + 1);
dx /= max;
dy /= max;
dz /= max;
float x = start.getX();
float y = start.getY();
float z = start.getZ();
float x = start.x();
float y = start.y();
float z = start.z();
boolean down = Math.abs(dy) > 0.2;
BlockState bState;
MutableBlockPos bPos = new MutableBlockPos();
for (int i = 0; i < count; i++) {
@ -165,14 +162,15 @@ public class SplineHelper {
if (down && bState.equals(state) || replace.apply(bState)) {
BlocksHelper.setWithoutUpdate(world, bPos, state);
}
} else {
}
else {
return false;
}
x += dx;
y += dy;
z += dz;
}
bPos.set(end.getX() + pos.getX(), end.getY() + pos.getY(), end.getZ() + pos.getZ());
bPos.set(end.x() + pos.getX(), end.y() + pos.getY(), end.z() + pos.getZ());
bState = world.getBlockState(bPos);
if (bState.equals(state) || replace.apply(bState)) {
BlocksHelper.setWithoutUpdate(world, bPos, state);
@ -182,26 +180,26 @@ public class SplineHelper {
BlocksHelper.setWithoutUpdate(world, bPos, state);
}
return true;
} else {
}
else {
return false;
}
}
public static void fillLineForce(Vector3f start, Vector3f end, WorldGenLevel world, BlockState state, BlockPos pos,
Function<BlockState, Boolean> replace) {
float dx = end.getX() - start.getX();
float dy = end.getY() - start.getY();
float dz = end.getZ() - start.getZ();
public static void fillLineForce(Vector3f start, Vector3f end, WorldGenLevel world, BlockState state, BlockPos pos, Function<BlockState, Boolean> replace) {
float dx = end.x() - start.x();
float dy = end.y() - start.y();
float dz = end.z() - start.z();
float max = MHelper.max(Math.abs(dx), Math.abs(dy), Math.abs(dz));
int count = MHelper.floor(max + 1);
dx /= max;
dy /= max;
dz /= max;
float x = start.getX();
float y = start.getY();
float z = start.getZ();
float x = start.x();
float y = start.y();
float z = start.z();
boolean down = Math.abs(dy) > 0.2;
BlockState bState;
MutableBlockPos bPos = new MutableBlockPos();
for (int i = 0; i < count; i++) {
@ -219,7 +217,7 @@ public class SplineHelper {
y += dy;
z += dz;
}
bPos.set(end.getX() + pos.getX(), end.getY() + pos.getY(), end.getZ() + pos.getZ());
bPos.set(end.x() + pos.getX(), end.y() + pos.getY(), end.z() + pos.getZ());
bState = world.getBlockState(bPos);
if (replace.apply(bState)) {
BlocksHelper.setWithoutUpdate(world, bPos, state);
@ -230,9 +228,8 @@ public class SplineHelper {
}
}
}
public static boolean canGenerate(List<Vector3f> spline, float scale, BlockPos start, WorldGenLevel world,
Function<BlockState, Boolean> canReplace) {
public static boolean canGenerate(List<Vector3f> spline, float scale, BlockPos start, WorldGenLevel world, Function<BlockState, Boolean> canReplace) {
int count = spline.size();
Vector3f vec = spline.get(0);
MutableBlockPos mut = new MutableBlockPos();
@ -244,10 +241,9 @@ public class SplineHelper {
float x2 = start.getX() + vec.x() * scale;
float y2 = start.getY() + vec.y() * scale;
float z2 = start.getZ() + vec.z() * scale;
for (float py = y1; py < y2; py += 3) {
if (py - start.getY() < 10)
continue;
if (py - start.getY() < 10) continue;
float lerp = (py - y1) / (y2 - y1);
float x = Mth.lerp(lerp, x1, x2);
float z = Mth.lerp(lerp, z1, z2);
@ -256,16 +252,15 @@ public class SplineHelper {
return false;
}
}
x1 = x2;
y1 = y2;
z1 = z2;
}
return true;
}
public static boolean canGenerate(List<Vector3f> spline, BlockPos start, WorldGenLevel world,
Function<BlockState, Boolean> canReplace) {
public static boolean canGenerate(List<Vector3f> spline, BlockPos start, WorldGenLevel world, Function<BlockState, Boolean> canReplace) {
int count = spline.size();
Vector3f vec = spline.get(0);
MutableBlockPos mut = new MutableBlockPos();
@ -277,10 +272,9 @@ public class SplineHelper {
float x2 = start.getX() + vec.x();
float y2 = start.getY() + vec.y();
float z2 = start.getZ() + vec.z();
for (float py = y1; py < y2; py += 3) {
if (py - start.getY() < 10)
continue;
if (py - start.getY() < 10) continue;
float lerp = (py - y1) / (y2 - y1);
float x = Mth.lerp(lerp, x1, x2);
float z = Mth.lerp(lerp, z1, z2);
@ -289,14 +283,14 @@ public class SplineHelper {
return false;
}
}
x1 = x2;
y1 = y2;
z1 = z2;
}
return true;
}
public static Vector3f getPos(List<Vector3f> spline, float index) {
int i = (int) index;
int last = spline.size() - 1;
@ -306,43 +300,43 @@ public class SplineHelper {
float delta = index - i;
Vector3f p1 = spline.get(i);
Vector3f p2 = spline.get(i + 1);
float x = Mth.lerp(delta, p1.getX(), p2.getX());
float y = Mth.lerp(delta, p1.getY(), p2.getY());
float z = Mth.lerp(delta, p1.getZ(), p2.getZ());
float x = Mth.lerp(delta, p1.x(), p2.x());
float y = Mth.lerp(delta, p1.y(), p2.y());
float z = Mth.lerp(delta, p1.z(), p2.z());
return new Vector3f(x, y, z);
}
public static void rotateSpline(List<Vector3f> spline, float angle) {
for (Vector3f v : spline) {
for (Vector3f v: spline) {
float sin = (float) Math.sin(angle);
float cos = (float) Math.cos(angle);
float x = v.getX() * cos + v.getZ() * sin;
float z = v.getX() * sin + v.getZ() * cos;
v.set(x, v.getY(), z);
float x = v.x() * cos + v.z() * sin;
float z = v.x() * sin + v.z() * cos;
v.set(x, v.y(), z);
}
}
public static List<Vector3f> copySpline(List<Vector3f> spline) {
List<Vector3f> result = new ArrayList<Vector3f>(spline.size());
for (Vector3f v : spline) {
result.add(new Vector3f(v.getX(), v.getY(), v.getZ()));
for (Vector3f v: spline) {
result.add(new Vector3f(v.x(), v.y(), v.z()));
}
return result;
}
public static void scale(List<Vector3f> spline, float scale) {
scale(spline, scale, scale, scale);
}
public static void scale(List<Vector3f> spline, float x, float y, float z) {
for (Vector3f v : spline) {
v.set(v.getX() * x, v.getY() * y, v.getZ() * z);
for (Vector3f v: spline) {
v.set(v.x() * x, v.y() * y, v.z() * z);
}
}
public static void offset(List<Vector3f> spline, Vector3f offset) {
for (Vector3f v : spline) {
v.set(offset.getX() + v.getX(), offset.getY() + v.getY(), offset.getZ() + v.getZ());
for (Vector3f v: spline) {
v.set(offset.x() + v.x(), offset.y() + v.y(), offset.z() + v.z());
}
}
}

View file

@ -10,39 +10,39 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import com.google.common.collect.Sets;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Material;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.structure.Structure;
import net.minecraft.structure.StructurePlacementData;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.BlockMirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraft.world.level.material.Material;
import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndTags;
public class StructureHelper {
private static final Direction[] DIR = BlocksHelper.makeHorizontal();
public static Structure readStructure(ResourceLocation resource) {
public static StructureTemplate readStructure(ResourceLocation resource) {
String ns = resource.getNamespace();
String nm = resource.getPath();
return readStructure("/data/" + ns + "/structures/" + nm + ".nbt");
}
public static Structure readStructure(File datapack, String path) {
public static StructureTemplate readStructure(File datapack, String path) {
if (datapack.isDirectory()) {
return readStructure(datapack.toString() + "/" + path);
} else if (datapack.isFile() && datapack.getName().endsWith(".zip")) {
}
else if (datapack.isFile() && datapack.getName().endsWith(".zip")) {
try {
ZipFile zipFile = new ZipFile(datapack);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
@ -57,91 +57,88 @@ public class StructureHelper {
System.out.format("\t %s - %d - %d\n", type, compressedSize, normalSize);
}
zipFile.close();
} catch (IOException e) {
}
catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
public static Structure readStructure(String path) {
public static StructureTemplate readStructure(String path) {
try {
InputStream inputstream = StructureHelper.class.getResourceAsStream(path);
return readStructureFromStream(inputstream);
} catch (IOException e) {
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}
private static Structure readStructureFromStream(InputStream stream) throws IOException {
private static StructureTemplate readStructureFromStream(InputStream stream) throws IOException {
CompoundTag nbttagcompound = NbtIo.readCompressed(stream);
Structure template = new Structure();
template.fromTag(nbttagcompound);
StructureTemplate template = new StructureTemplate();
template.load(nbttagcompound);
return template;
}
public static BlockPos offsetPos(BlockPos pos, Structure structure, Rotation rotation, BlockMirror mirror) {
BlockPos offset = Structure.transformAround(structure.getSize(), mirror, rotation, BlockPos.ORIGIN);
public static BlockPos offsetPos(BlockPos pos, StructureTemplate structure, Rotation rotation, Mirror mirror) {
BlockPos offset = StructureTemplate.transform(structure.getSize(), mirror, rotation, BlockPos.ZERO);
return pos.offset(-offset.getX() * 0.5, 0, -offset.getZ() * 0.5);
}
public static void placeCenteredBottom(WorldGenLevel world, BlockPos pos, Structure structure, Rotation rotation,
BlockMirror mirror, Random random) {
public static void placeCenteredBottom(WorldGenLevel world, BlockPos pos, StructureTemplate structure, Rotation rotation, Mirror mirror, Random random) {
placeCenteredBottom(world, pos, structure, rotation, mirror, makeBox(pos), random);
}
public static void placeCenteredBottom(WorldGenLevel world, BlockPos pos, Structure structure, Rotation rotation,
BlockMirror mirror, BlockBox bounds, Random random) {
public static void placeCenteredBottom(WorldGenLevel world, BlockPos pos, StructureTemplate structure, Rotation rotation, Mirror mirror, BoundingBox bounds, Random random) {
BlockPos offset = offsetPos(pos, structure, rotation, mirror);
StructurePlacementData placementData = new StructurePlacementData().setRotation(rotation).setMirror(mirror)
.setBoundingBox(bounds);
structure.place(world, offset, placementData, random);
StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation).setMirror(mirror).setBoundingBox(bounds);
structure.placeInWorldChunk(world, offset, placementData, random);
}
private static BlockBox makeBox(BlockPos pos) {
private static BoundingBox makeBox(BlockPos pos) {
int sx = ((pos.getX() >> 4) << 4) - 16;
int sz = ((pos.getZ() >> 4) << 4) - 16;
int ex = sx + 47;
int ez = sz + 47;
return BlockBox.create(sx, 0, sz, ex, 255, ez);
return BoundingBox.createProper(sx, 0, sz, ex, 255, ez);
}
public static BlockBox getStructureBounds(BlockPos pos, Structure structure, Rotation rotation,
BlockMirror mirror) {
public static BoundingBox getStructureBounds(BlockPos pos, StructureTemplate structure, Rotation rotation, Mirror mirror) {
BlockPos max = structure.getSize();
BlockPos min = Structure.transformAround(structure.getSize(), mirror, rotation, BlockPos.ORIGIN);
BlockPos min = StructureTemplate.transform(structure.getSize(), mirror, rotation, BlockPos.ZERO);
max = max.subtract(min);
return new BlockBox(min.add(pos), max.add(pos));
return new BoundingBox(min.offset(pos), max.offset(pos));
}
public static BlockBox intersectBoxes(BlockBox box1, BlockBox box2) {
int x1 = MHelper.max(box1.minX, box2.minX);
int y1 = MHelper.max(box1.minY, box2.minY);
int z1 = MHelper.max(box1.minZ, box2.minZ);
int x2 = MHelper.min(box1.maxX, box2.maxX);
int y2 = MHelper.min(box1.maxY, box2.maxY);
int z2 = MHelper.min(box1.maxZ, box2.maxZ);
return BlockBox.create(x1, y1, z1, x2, y2, z2);
public static BoundingBox intersectBoxes(BoundingBox box1, BoundingBox box2) {
int x1 = MHelper.max(box1.x0, box2.x0);
int y1 = MHelper.max(box1.y0, box2.y0);
int z1 = MHelper.max(box1.z0, box2.z0);
int x2 = MHelper.min(box1.x1, box2.x1);
int y2 = MHelper.min(box1.y1, box2.y1);
int z2 = MHelper.min(box1.z1, box2.z1);
return BoundingBox.createProper(x1, y1, z1, x2, y2, z2);
}
public static void erode(WorldGenLevel world, BlockBox bounds, int iterations, Random random) {
public static void erode(WorldGenLevel world, BoundingBox bounds, int iterations, Random random) {
MutableBlockPos mut = new MutableBlockPos();
boolean canDestruct = true;
for (int i = 0; i < iterations; i++) {
for (int x = bounds.minX; x <= bounds.maxX; x++) {
for (int x = bounds.x0; x <= bounds.x1; x++) {
mut.setX(x);
for (int z = bounds.minZ; z <= bounds.maxZ; z++) {
for (int z = bounds.z0; z <= bounds.z1; z++) {
mut.setZ(z);
for (int y = bounds.maxY; y >= bounds.minY; y--) {
for (int y = bounds.y1; y >= bounds.y0; y--) {
mut.setY(y);
BlockState state = world.getBlockState(mut);
if (canDestruct && state.is(EndBlocks.FLAVOLITE_RUNED_ETERNAL) && random.nextInt(8) == 0
&& world.isAir(mut.down(2))) {
if (canDestruct && state.is(EndBlocks.FLAVOLITE_RUNED_ETERNAL) && random.nextInt(8) == 0 && world.isEmptyBlock(mut.below(2))) {
int r = MHelper.randRange(1, 4, random);
int cx = mut.getX();
int cy = mut.getY();
@ -164,8 +161,7 @@ public class StructureHelper {
int dz = pz - cz;
dz *= dz;
mut.setZ(pz);
if (dx + dy + dz <= r
&& world.getBlockState(mut).is(EndBlocks.FLAVOLITE_RUNED_ETERNAL)) {
if (dx + dy + dz <= r && world.getBlockState(mut).is(EndBlocks.FLAVOLITE_RUNED_ETERNAL)) {
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
}
}
@ -176,18 +172,19 @@ public class StructureHelper {
mut.setZ(cz);
canDestruct = false;
continue;
} else if (ignore(state)) {
}
else if (ignore(state)) {
continue;
}
if (!state.isAir() && random.nextBoolean()) {
shuffle(random);
for (Direction dir : DIR) {
if (world.isAir(mut.offset(dir)) && world.isAir(mut.below().offset(dir))) {
for (Direction dir: DIR) {
if (world.isEmptyBlock(mut.relative(dir)) && world.isEmptyBlock(mut.below().relative(dir))) {
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
mut.move(dir).move(Direction.DOWN);
for (int py = mut.getY(); y >= bounds.minY - 10; y--) {
for (int py = mut.getY(); y >= bounds.y0 - 10; y--) {
mut.setY(py - 1);
if (!world.isAir(mut)) {
if (!world.isEmptyBlock(mut)) {
mut.setY(py);
BlocksHelper.setWithoutUpdate(world, mut, state);
break;
@ -196,26 +193,26 @@ public class StructureHelper {
}
}
break;
} else if (random.nextInt(8) == 0
&& !world.getBlockState(mut.up()).is(EndBlocks.ETERNAL_PEDESTAL)) {
}
else if (random.nextInt(8) == 0 && !world.getBlockState(mut.above()).is(EndBlocks.ETERNAL_PEDESTAL)) {
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
}
}
}
}
}
for (int x = bounds.minX; x <= bounds.maxX; x++) {
for (int x = bounds.x0; x <= bounds.x1; x++) {
mut.setX(x);
for (int z = bounds.minZ; z <= bounds.maxZ; z++) {
for (int z = bounds.z0; z <= bounds.z1; z++) {
mut.setZ(z);
for (int y = bounds.maxY; y >= bounds.minY; y--) {
for (int y = bounds.y1; y >= bounds.y0; y--) {
mut.setY(y);
BlockState state = world.getBlockState(mut);
if (!ignore(state) && world.isAir(mut.below())) {
if (!ignore(state) && world.isEmptyBlock(mut.below())) {
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
for (int py = mut.getY(); py >= bounds.minY - 10; py--) {
for (int py = mut.getY(); py >= bounds.y0 - 10; py--) {
mut.setY(py - 1);
if (!world.isAir(mut)) {
if (!world.isEmptyBlock(mut)) {
mut.setY(py);
BlocksHelper.setWithoutUpdate(world, mut, state);
break;
@ -227,15 +224,15 @@ public class StructureHelper {
}
}
public static void erodeIntense(WorldGenLevel world, BlockBox bounds, Random random) {
public static void erodeIntense(WorldGenLevel world, BoundingBox bounds, Random random) {
MutableBlockPos mut = new MutableBlockPos();
MutableBlockPos mut2 = new MutableBlockPos();
int minY = bounds.minY - 10;
for (int x = bounds.minX; x <= bounds.maxX; x++) {
int minY = bounds.y0 - 10;
for (int x = bounds.x0; x <= bounds.x1; x++) {
mut.setX(x);
for (int z = bounds.minZ; z <= bounds.maxZ; z++) {
for (int z = bounds.z0; z <= bounds.z1; z++) {
mut.setZ(z);
for (int y = bounds.maxY; y >= bounds.minY; y--) {
for (int y = bounds.y1; y >= bounds.y0; y--) {
mut.setY(y);
BlockState state = world.getBlockState(mut);
if (!ignore(state)) {
@ -248,12 +245,13 @@ public class StructureHelper {
while (world.getBlockState(mut2).getMaterial().isReplaceable() && mut2.getY() > minY) {
mut2.setY(mut2.getY() - 1);
}
if (!world.getBlockState(mut2).isAir() && state.canPlaceAt(world, mut2)) {
if (!world.getBlockState(mut2).isAir() && state.canSurvive(world, mut2)) {
mut2.setY(mut2.getY() + 1);
BlocksHelper.setWithoutUpdate(world, mut2, state);
}
}
} else if (random.nextInt(8) == 0) {
}
else if (random.nextInt(8) == 0) {
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
}
}
@ -263,28 +261,28 @@ public class StructureHelper {
drop(world, bounds);
}
private static boolean isTerrainNear(WorldGenLevel world, BlockPos pos) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
if (world.getBlockState(pos.relative(dir)).isIn(EndTags.GEN_TERRAIN)) {
for (Direction dir: BlocksHelper.DIRECTIONS) {
if (world.getBlockState(pos.relative(dir)).is(EndTags.GEN_TERRAIN)) {
return true;
}
}
return false;
}
private static void drop(WorldGenLevel world, BlockBox bounds) {
private static void drop(WorldGenLevel world, BoundingBox bounds) {
MutableBlockPos mut = new MutableBlockPos();
Set<BlockPos> blocks = Sets.newHashSet();
Set<BlockPos> edge = Sets.newHashSet();
Set<BlockPos> add = Sets.newHashSet();
for (int x = bounds.minX; x <= bounds.maxX; x++) {
for (int x = bounds.x0; x <= bounds.x1; x++) {
mut.setX(x);
for (int z = bounds.minZ; z <= bounds.maxZ; z++) {
for (int z = bounds.z0; z <= bounds.z1; z++) {
mut.setZ(z);
for (int y = bounds.minY; y <= bounds.maxY; y++) {
for (int y = bounds.y0; y <= bounds.y1; y++) {
mut.setY(y);
BlockState state = world.getBlockState(mut);
if (!ignore(state) && isTerrainNear(world, mut)) {
@ -293,18 +291,18 @@ public class StructureHelper {
}
}
}
if (edge.isEmpty()) {
return;
}
while (!edge.isEmpty()) {
for (BlockPos center : edge) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
for (BlockPos center: edge) {
for (Direction dir: BlocksHelper.DIRECTIONS) {
BlockState state = world.getBlockState(center);
if (state.isFullCube(world, center)) {
if (state.isCollisionShapeFullBlock(world, center)) {
mut.set(center).move(dir);
if (bounds.contains(mut)) {
if (bounds.isInside(mut)) {
state = world.getBlockState(mut);
if (!ignore(state) && !blocks.contains(mut)) {
add.add(mut.immutable());
@ -313,19 +311,19 @@ public class StructureHelper {
}
}
}
blocks.addAll(edge);
edge.clear();
edge.addAll(add);
add.clear();
}
int minY = bounds.minY - 10;
for (int x = bounds.minX; x <= bounds.maxX; x++) {
int minY = bounds.y0 - 10;
for (int x = bounds.x0; x <= bounds.x1; x++) {
mut.setX(x);
for (int z = bounds.minZ; z <= bounds.maxZ; z++) {
for (int z = bounds.z0; z <= bounds.z1; z++) {
mut.setZ(z);
for (int y = bounds.minY; y <= bounds.maxY; y++) {
for (int y = bounds.y0; y <= bounds.y1; y++) {
mut.setY(y);
BlockState state = world.getBlockState(mut);
if (!ignore(state) && !blocks.contains(mut)) {
@ -344,12 +342,17 @@ public class StructureHelper {
}
private static boolean ignore(BlockState state) {
return state.getMaterial().isReplaceable() || !state.getFluidState().isEmpty() || state.isIn(EndTags.END_GROUND)
|| state.is(EndBlocks.ETERNAL_PEDESTAL) || state.is(EndBlocks.FLAVOLITE_RUNED_ETERNAL)
|| state.isIn(BlockTags.LOGS) || state.isIn(BlockTags.LEAVES)
|| state.getMaterial().equals(Material.PLANT) || state.getMaterial().equals(Material.LEAVES);
return state.getMaterial().isReplaceable()
|| !state.getFluidState().isEmpty()
|| state.is(EndTags.END_GROUND)
|| state.is(EndBlocks.ETERNAL_PEDESTAL)
|| state.is(EndBlocks.FLAVOLITE_RUNED_ETERNAL)
|| state.is(BlockTags.LOGS)
|| state.is(BlockTags.LEAVES)
|| state.getMaterial().equals(Material.PLANT)
|| state.getMaterial().equals(Material.LEAVES);
}
private static void shuffle(Random random) {
for (int i = 0; i < 4; i++) {
int j = random.nextInt(4);
@ -358,18 +361,18 @@ public class StructureHelper {
DIR[j] = d;
}
}
public static void cover(WorldGenLevel world, BlockBox bounds, Random random) {
public static void cover(WorldGenLevel world, BoundingBox bounds, Random random) {
MutableBlockPos mut = new MutableBlockPos();
for (int x = bounds.minX; x <= bounds.maxX; x++) {
for (int x = bounds.x0; x <= bounds.x1; x++) {
mut.setX(x);
for (int z = bounds.minZ; z <= bounds.maxZ; z++) {
for (int z = bounds.z0; z <= bounds.z1; z++) {
mut.setZ(z);
BlockState top = world.getBiome(mut).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
for (int y = bounds.maxY; y >= bounds.minY; y--) {
for (int y = bounds.y1; y >= bounds.y0; y--) {
mut.setY(y);
BlockState state = world.getBlockState(mut);
if (state.isIn(EndTags.END_GROUND) && !world.getBlockState(mut.up()).getMaterial().blocksLight()) {
if (state.is(EndTags.END_GROUND) && !world.getBlockState(mut.above()).getMaterial().isSolidBlocking()) {
BlocksHelper.setWithoutUpdate(world, mut, top);
}
}

View file

@ -2,64 +2,70 @@ package ru.betterend.util;
import java.util.Map;
import java.util.Set;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.item.Item;
import net.minecraft.tags.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
public class TagHelper {
private static final Map<ResourceLocation, Set<ResourceLocation>> TAGS_BLOCK = Maps.newHashMap();
private static final Map<ResourceLocation, Set<ResourceLocation>> TAGS_ITEM = Maps.newHashMap();
public static void addTag(Tag.Named<Block> tag, Block... blocks) {
ResourceLocation tagID = tag.getName();
Set<ResourceLocation> set = TAGS_BLOCK.computeIfAbsent(tagID, k -> Sets.newHashSet());
for (Block block : blocks) {
Set<ResourceLocation> set = TAGS_BLOCK.get(tagID);
if (set == null) {
set = Sets.newHashSet();
TAGS_BLOCK.put(tagID, set);
}
for (Block block: blocks) {
ResourceLocation id = Registry.BLOCK.getKey(block);
if (id != Registry.BLOCK.getDefaultKey()) {
set.add(id);
}
}
}
public static void addTag(Tag.Named<Item> tag, ItemLike... items) {
ResourceLocation tagID = tag.getName();
Set<ResourceLocation> set = TAGS_ITEM.computeIfAbsent(tagID, k -> Sets.newHashSet());
for (ItemLike item : items) {
Set<ResourceLocation> set = TAGS_ITEM.get(tagID);
if (set == null) {
set = Sets.newHashSet();
TAGS_ITEM.put(tagID, set);
}
for (ItemLike item: items) {
ResourceLocation id = Registry.ITEM.getKey(item.asItem());
if (id != Registry.ITEM.getDefaultKey()) {
set.add(id);
}
}
}
@SafeVarargs
public static void addTags(ItemLike item, Tag.Named<Item>... tags) {
for (Tag.Named<Item> tag : tags) {
for (Tag.Named<Item> tag: tags) {
addTag(tag, item);
}
}
@SafeVarargs
public static void addTags(Block block, Tag.Named<Block>... tags) {
for (Tag.Named<Block> tag : tags) {
for (Tag.Named<Block> tag: tags) {
addTag(tag, block);
}
}
public static Tag.Builder apply(Tag.Builder builder, Set<ResourceLocation> ids) {
ids.forEach(value -> {
builder.addTag(value, "Better End Code");
ids.forEach((value) -> {
builder.addElement(value, "Better End Code");
});
return builder;
}
public static void apply(String entry, Map<ResourceLocation, Tag.Builder> tagsMap) {
Map<ResourceLocation, Set<ResourceLocation>> endTags = null;
if (entry.equals("block")) {

View file

@ -4,13 +4,11 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.List;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import ru.betterend.BetterEnd;
import ru.betterend.registry.EndBiomes;
import ru.betterend.registry.EndItems;
@ -19,13 +17,13 @@ public class TranslationHelper {
public static void printMissingNames() {
List<String> missingNamesEn = Lists.newArrayList();
List<String> missingNamesRu = Lists.newArrayList();
Gson gson = new Gson();
InputStream streamEn = BetterEnd.class.getResourceAsStream("/assets/betterend/lang/en_us.json");
InputStream streamRu = BetterEnd.class.getResourceAsStream("/assets/betterend/lang/ru_ru.json");
JsonObject translationEn = gson.fromJson(new InputStreamReader(streamEn), JsonObject.class);
JsonObject translationRu = gson.fromJson(new InputStreamReader(streamRu), JsonObject.class);
Registry.BLOCK.forEach((block) -> {
if (Registry.BLOCK.getKey(block).getNamespace().equals(BetterEnd.MOD_ID)) {
String name = block.getName().getString();
@ -37,9 +35,9 @@ public class TranslationHelper {
}
}
});
EndItems.getModItems().forEach((item) -> {
String name = item.getName().getString();
String name = item.getDescription().getString();
if (!translationEn.has(name)) {
missingNamesEn.add(name);
}
@ -47,7 +45,7 @@ public class TranslationHelper {
missingNamesRu.add(name);
}
});
EndBiomes.getModBiomes().forEach((endBiome) -> {
if (endBiome.getID().getNamespace().equals(BetterEnd.MOD_ID)) {
String name = "biome." + BetterEnd.MOD_ID + "." + endBiome.getID().getPath();
@ -59,9 +57,9 @@ public class TranslationHelper {
}
}
});
Registry.ENTITY_TYPE.forEach((entity) -> {
ResourceLocation id = Registry.ENTITY_TYPE.getId(entity);
ResourceLocation id = Registry.ENTITY_TYPE.getKey(entity);
if (id.getNamespace().equals(BetterEnd.MOD_ID)) {
String name = "entity." + BetterEnd.MOD_ID + "." + id.getPath();
if (!translationEn.has(name)) {
@ -72,12 +70,12 @@ public class TranslationHelper {
}
}
});
if (!missingNamesEn.isEmpty() || !missingNamesRu.isEmpty()) {
System.out.println("========================================");
System.out.println(" MISSING NAMES LIST");
if (!missingNamesEn.isEmpty()) {
Collections.sort(missingNamesEn);
System.out.println("========================================");
@ -87,7 +85,7 @@ public class TranslationHelper {
System.out.println(" \"" + name + "\": \"" + fastTranslateEn(name) + "\",");
});
}
if (!missingNamesRu.isEmpty()) {
Collections.sort(missingNamesRu);
System.out.println("========================================");
@ -97,11 +95,11 @@ public class TranslationHelper {
System.out.println(" \"" + name + "\": \"\",");
});
}
System.out.println("========================================");
}
}
public static String fastTranslateEn(String text) {
String[] words = text.substring(text.lastIndexOf('.') + 1).split("_");
StringBuilder builder = new StringBuilder();

View file

@ -10,32 +10,34 @@ import ru.betterend.BetterEnd;
public class WorldDataUtil {
private static CompoundTag root;
private static File saveFile;
public static void load(File file) {
saveFile = file;
if (file.exists()) {
try {
root = NbtIo.readCompressed(file);
} catch (IOException e) {
BetterEnd.LOGGER.error("Level data loading failed", e);
}
catch (IOException e) {
BetterEnd.LOGGER.error("World data loading failed", e);
root = new CompoundTag();
}
return;
}
root = new CompoundTag();
}
public static CompoundTag getRootTag() {
return root;
}
public static CompoundTag getCompoundTag(String path) {
String[] parts = path.split("\\.");
CompoundTag tag = root;
for (String part : parts) {
for (String part: parts) {
if (tag.contains(part)) {
tag = tag.getCompound(part);
} else {
}
else {
CompoundTag t = new CompoundTag();
tag.put(part, t);
tag = t;
@ -43,12 +45,13 @@ public class WorldDataUtil {
}
return tag;
}
public static void saveFile() {
try {
NbtIo.writeCompressed(root, saveFile);
} catch (IOException e) {
BetterEnd.LOGGER.error("Level data saving failed", e);
}
catch (IOException e) {
BetterEnd.LOGGER.error("World data saving failed", e);
}
}
}

View file

@ -1,11 +1,10 @@
package ru.betterend.util.sdf;
import java.util.Map;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
public class PosInfo implements Comparable<PosInfo> {
private static final BlockState AIR = Blocks.AIR.defaultBlockState();
@ -13,22 +12,22 @@ public class PosInfo implements Comparable<PosInfo> {
private final Map<BlockPos, PosInfo> add;
private final BlockPos pos;
private BlockState state;
public static PosInfo create(Map<BlockPos, PosInfo> blocks, Map<BlockPos, PosInfo> add, BlockPos pos) {
return new PosInfo(blocks, add, pos);
}
private PosInfo(Map<BlockPos, PosInfo> blocks, Map<BlockPos, PosInfo> add, BlockPos pos) {
this.blocks = blocks;
this.add = add;
this.pos = pos;
blocks.put(pos, this);
}
public BlockState getState() {
return state;
}
public BlockState getState(BlockPos pos) {
PosInfo info = blocks.get(pos);
if (info == null) {
@ -37,18 +36,18 @@ public class PosInfo implements Comparable<PosInfo> {
}
return info.getState();
}
public void setState(BlockState state) {
this.state = state;
}
public void setState(BlockPos pos, BlockState state) {
PosInfo info = blocks.get(pos);
if (info != null) {
info.setState(state);
}
}
public BlockState getState(Direction dir) {
PosInfo info = blocks.get(pos.relative(dir));
if (info == null) {
@ -57,7 +56,7 @@ public class PosInfo implements Comparable<PosInfo> {
}
return info.getState();
}
public BlockState getState(Direction dir, int distance) {
PosInfo info = blocks.get(pos.relative(dir, distance));
if (info == null) {
@ -65,20 +64,20 @@ public class PosInfo implements Comparable<PosInfo> {
}
return info.getState();
}
public BlockState getStateUp() {
return getState(Direction.UP);
}
public BlockState getStateDown() {
return getState(Direction.DOWN);
}
@Override
public int hashCode() {
return pos.hashCode();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof PosInfo)) {
@ -95,7 +94,7 @@ public class PosInfo implements Comparable<PosInfo> {
public BlockPos getPos() {
return pos;
}
public void setBlockPos(BlockPos pos, BlockState state) {
PosInfo info = new PosInfo(blocks, add, pos);
info.state = state;

View file

@ -6,17 +6,15 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.world.phys.AABB;
import net.minecraft.core.Direction;
import ru.betterend.util.BlocksHelper;
import ru.betterend.world.structures.StructureWorld;
@ -27,19 +25,19 @@ public abstract class SDF {
};
public abstract float getDistance(float x, float y, float z);
public abstract BlockState getBlockState(BlockPos pos);
public SDF addPostProcess(Function<PosInfo, BlockState> postProcess) {
this.postProcesses.add(postProcess);
return this;
}
public SDF setReplaceFunction(Function<BlockState, Boolean> canReplace) {
this.canReplace = canReplace;
return this;
}
public void fillRecursive(ServerLevelAccessor world, BlockPos start) {
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
Map<BlockPos, PosInfo> addInfo = Maps.newHashMap();
@ -48,15 +46,15 @@ public abstract class SDF {
Set<BlockPos> add = Sets.newHashSet();
ends.add(new BlockPos(0, 0, 0));
boolean run = true;
MutableBlockPos bPos = new MutableBlockPos();
while (run) {
for (BlockPos center : ends) {
for (Direction dir : Direction.values()) {
for (BlockPos center: ends) {
for (Direction dir: Direction.values()) {
bPos.set(center).move(dir);
BlockPos wpos = bPos.offset(start);
if (!blocks.contains(bPos) && canReplace.apply(world.getBlockState(wpos))) {
if (this.getDistance(bPos.getX(), bPos.getY(), bPos.getZ()) < 0) {
BlockState state = getBlockState(wpos);
@ -66,15 +64,15 @@ public abstract class SDF {
}
}
}
blocks.addAll(ends);
ends.clear();
ends.addAll(add);
add.clear();
run &= !ends.isEmpty();
}
List<PosInfo> infos = new ArrayList<PosInfo>(mapWorld.values());
if (infos.size() > 0) {
Collections.sort(infos);
@ -102,11 +100,11 @@ public abstract class SDF {
});
}
}
public void fillArea(ServerLevelAccessor world, BlockPos center, AABB box) {
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
Map<BlockPos, PosInfo> addInfo = Maps.newHashMap();
MutableBlockPos mut = new MutableBlockPos();
for (int y = (int) box.minY; y <= box.maxY; y++) {
mut.setY(y);
@ -123,7 +121,7 @@ public abstract class SDF {
}
}
}
List<PosInfo> infos = new ArrayList<PosInfo>(mapWorld.values());
if (infos.size() > 0) {
Collections.sort(infos);
@ -151,7 +149,7 @@ public abstract class SDF {
});
}
}
public void fillRecursiveIgnore(ServerLevelAccessor world, BlockPos start, Function<BlockState, Boolean> ignore) {
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
Map<BlockPos, PosInfo> addInfo = Maps.newHashMap();
@ -160,12 +158,12 @@ public abstract class SDF {
Set<BlockPos> add = Sets.newHashSet();
ends.add(new BlockPos(0, 0, 0));
boolean run = true;
MutableBlockPos bPos = new MutableBlockPos();
while (run) {
for (BlockPos center : ends) {
for (Direction dir : Direction.values()) {
for (BlockPos center: ends) {
for (Direction dir: Direction.values()) {
bPos.set(center).move(dir);
BlockPos wpos = bPos.offset(start);
BlockState state = world.getBlockState(wpos);
@ -178,15 +176,15 @@ public abstract class SDF {
}
}
}
blocks.addAll(ends);
ends.clear();
ends.addAll(add);
add.clear();
run &= !ends.isEmpty();
}
List<PosInfo> infos = new ArrayList<PosInfo>(mapWorld.values());
if (infos.size() > 0) {
Collections.sort(infos);
@ -214,7 +212,7 @@ public abstract class SDF {
});
}
}
public void fillRecursive(StructureWorld world, BlockPos start) {
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
Map<BlockPos, PosInfo> addInfo = Maps.newHashMap();
@ -223,15 +221,15 @@ public abstract class SDF {
Set<BlockPos> add = Sets.newHashSet();
ends.add(new BlockPos(0, 0, 0));
boolean run = true;
MutableBlockPos bPos = new MutableBlockPos();
while (run) {
for (BlockPos center : ends) {
for (Direction dir : Direction.values()) {
for (BlockPos center: ends) {
for (Direction dir: Direction.values()) {
bPos.set(center).move(dir);
BlockPos wpos = bPos.offset(start);
if (!blocks.contains(bPos)) {
if (this.getDistance(bPos.getX(), bPos.getY(), bPos.getZ()) < 0) {
BlockState state = getBlockState(wpos);
@ -241,15 +239,15 @@ public abstract class SDF {
}
}
}
blocks.addAll(ends);
ends.clear();
ends.addAll(add);
add.clear();
run &= !ends.isEmpty();
}
List<PosInfo> infos = new ArrayList<PosInfo>(mapWorld.values());
Collections.sort(infos);
postProcesses.forEach((postProcess) -> {
@ -260,7 +258,7 @@ public abstract class SDF {
infos.forEach((info) -> {
world.setBlock(info.getPos(), info.getState());
});
infos.clear();
infos.addAll(addInfo.values());
Collections.sort(infos);
@ -273,19 +271,19 @@ public abstract class SDF {
world.setBlock(info.getPos(), info.getState());
});
}
public Set<BlockPos> getPositions(ServerLevelAccessor world, BlockPos start) {
Set<BlockPos> blocks = Sets.newHashSet();
Set<BlockPos> ends = Sets.newHashSet();
Set<BlockPos> add = Sets.newHashSet();
ends.add(new BlockPos(0, 0, 0));
boolean run = true;
MutableBlockPos bPos = new MutableBlockPos();
while (run) {
for (BlockPos center : ends) {
for (Direction dir : Direction.values()) {
for (BlockPos center: ends) {
for (Direction dir: Direction.values()) {
bPos.set(center).move(dir);
BlockPos wpos = bPos.offset(start);
BlockState state = world.getBlockState(wpos);
@ -296,15 +294,15 @@ public abstract class SDF {
}
}
}
ends.forEach((end) -> blocks.add(end.offset(start)));
ends.clear();
ends.addAll(add);
add.clear();
run &= !ends.isEmpty();
}
return blocks;
}
}

View file

@ -1,28 +1,28 @@
package ru.betterend.util.sdf.operator;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
import ru.betterend.util.sdf.SDF;
public abstract class SDFBinary extends SDF {
protected SDF sourceA;
protected SDF sourceB;
protected boolean firstValue;
public SDFBinary setSourceA(SDF sourceA) {
this.sourceA = sourceA;
return this;
}
public SDFBinary setSourceB(SDF sourceB) {
this.sourceB = sourceB;
return this;
}
protected void selectValue(float a, float b) {
firstValue = a < b;
}
@Override
public BlockState getBlockState(BlockPos pos) {
if (firstValue) {

View file

@ -1,22 +1,21 @@
package ru.betterend.util.sdf.operator;
import java.util.function.Consumer;
import com.mojang.math.Vector3f;
import java.util.function.Consumer;
public class SDFCoordModify extends SDFUnary {
private static final Vector3f POS = new Vector3f();
private Consumer<Vector3f> function;
public SDFCoordModify setFunction(Consumer<Vector3f> function) {
this.function = function;
return this;
}
@Override
public float getDistance(float x, float y, float z) {
POS.set(x, y, z);
function.accept(POS);
return this.source.getDistance(POS.getX(), POS.getY(), POS.getZ());
return this.source.getDistance(POS.x(), POS.y(), POS.z());
}
}

View file

@ -1,18 +1,17 @@
package ru.betterend.util.sdf.operator;
import java.util.function.Function;
import com.mojang.math.Vector3f;
import java.util.function.Function;
public class SDFDisplacement extends SDFUnary {
private static final Vector3f POS = new Vector3f();
private Function<Vector3f, Float> displace;
public SDFDisplacement setFunction(Function<Vector3f, Float> displace) {
this.displace = displace;
return this;
}
@Override
public float getDistance(float x, float y, float z) {
POS.set(x, y, z);

View file

@ -7,7 +7,7 @@ public class SDFFlatWave extends SDFDisplacement {
public SDFFlatWave() {
setFunction((pos) -> {
return (float) Math.cos(Math.atan2(pos.getX(), pos.getZ()) * rayCount + angle) * intensity;
return (float) Math.cos(Math.atan2(pos.x(), pos.z()) * rayCount + angle) * intensity;
});
}

View file

@ -1,6 +1,6 @@
package ru.betterend.util.sdf.operator;
import net.minecraft.client.texture.NativeImage;
import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.util.Mth;
public class SDFHeightmap extends SDFDisplacement {
@ -11,14 +11,14 @@ public class SDFHeightmap extends SDFDisplacement {
private float scale;
private float cos = 1;
private float sin = 0;
public SDFHeightmap() {
setFunction((pos) -> {
if (map == null) {
return 0F;
}
float px = Mth.clamp(pos.getX() * scale + offsetX, 0, map.getWidth() - 2);
float pz = Mth.clamp(pos.getZ() * scale + offsetZ, 0, map.getHeight() - 2);
float px = Mth.clamp(pos.x() * scale + offsetX, 0, map.getWidth() - 2);
float pz = Mth.clamp(pos.z() * scale + offsetZ, 0, map.getHeight() - 2);
float dx = (px * cos - pz * sin);
float dz = (pz * cos + px * sin);
int x1 = Mth.floor(dx);
@ -27,16 +27,16 @@ public class SDFHeightmap extends SDFDisplacement {
int z2 = z1 + 1;
dx = dx - x1;
dz = dz - z1;
float a = (map.getPixelColor(x1, z1) & 255) / 255F;
float b = (map.getPixelColor(x2, z1) & 255) / 255F;
float c = (map.getPixelColor(x1, z2) & 255) / 255F;
float d = (map.getPixelColor(x2, z2) & 255) / 255F;
float a = (map.getPixelRGBA(x1, z1) & 255) / 255F;
float b = (map.getPixelRGBA(x2, z1) & 255) / 255F;
float c = (map.getPixelRGBA(x1, z2) & 255) / 255F;
float d = (map.getPixelRGBA(x2, z2) & 255) / 255F;
a = Mth.lerp(dx, a, b);
b = Mth.lerp(dx, c, d);
return -Mth.lerp(dz, a, b) * intensity;
});
}
public SDFHeightmap setMap(NativeImage map) {
this.map = map;
offsetX = map.getWidth() * 0.5F;
@ -44,18 +44,18 @@ public class SDFHeightmap extends SDFDisplacement {
scale = map.getWidth();
return this;
}
public SDFHeightmap setAngle(float angle) {
sin = Mth.sin(angle);
cos = Mth.cos(angle);
return this;
}
public SDFHeightmap setScale(float scale) {
this.scale = map.getWidth() * scale;
return this;
}
public SDFHeightmap setIntensity(float intensity) {
this.intensity = intensity;
return this;

View file

@ -7,20 +7,20 @@ import ru.betterend.util.MHelper;
public class SDFRadialNoiseMap extends SDFDisplacement {
private static final float SIN = Mth.sin(0.5F);
private static final float COS = Mth.cos(0.5F);
private OpenSimplexNoise noise;
private float intensity = 1F;
private float radius = 1F;
private short offsetX;
private short offsetZ;
public SDFRadialNoiseMap() {
setFunction((pos) -> {
if (intensity == 0) {
return 0F;
}
float px = pos.getX() / radius;
float pz = pos.getZ() / radius;
float px = pos.x() / radius;
float pz = pos.z() / radius;
float distance = MHelper.lengthSqr(px, pz);
if (distance > 1) {
return 0F;
@ -32,27 +32,26 @@ public class SDFRadialNoiseMap extends SDFDisplacement {
return distance * intensity;
});
}
private float getNoise(double x, double z) {
return (float) noise.eval(x, z) + (float) noise.eval(x * 3 + 1000, z * 3) * 0.5F
+ (float) noise.eval(x * 9 + 1000, z * 9) * 0.2F;
return (float) noise.eval(x, z) + (float) noise.eval(x * 3 + 1000, z * 3) * 0.5F + (float) noise.eval(x * 9 + 1000, z * 9) * 0.2F;
}
public SDFRadialNoiseMap setSeed(long seed) {
noise = new OpenSimplexNoise(seed);
return this;
}
public SDFRadialNoiseMap setIntensity(float intensity) {
this.intensity = intensity;
return this;
}
public SDFRadialNoiseMap setRadius(float radius) {
this.radius = radius;
return this;
}
public SDFRadialNoiseMap setOffset(int x, int z) {
offsetX = (short) (x & 32767);
offsetZ = (short) (z & 32767);

View file

@ -1,21 +1,21 @@
package ru.betterend.util.sdf.operator;
import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
import net.minecraft.util.math.Quaternion;
public class SDFRotation extends SDFUnary {
private static final Vector3f POS = new Vector3f();
private Quaternion rotation;
public SDFRotation setRotation(Vector3f axis, float rotationAngle) {
rotation = new Quaternion(axis, rotationAngle, false);
return this;
}
@Override
public float getDistance(float x, float y, float z) {
POS.set(x, y, z);
POS.rotate(rotation);
return source.getDistance(POS.getX(), POS.getY(), POS.getZ());
POS.transform(rotation);
return source.getDistance(POS.x(), POS.y(), POS.z());
}
}

View file

@ -9,7 +9,7 @@ public class SDFSmoothIntersection extends SDFBinary {
this.radius = radius;
return this;
}
@Override
public float getDistance(float x, float y, float z) {
float a = this.sourceA.getDistance(x, y, z);

View file

@ -9,7 +9,7 @@ public class SDFSmoothSubtraction extends SDFBinary {
this.radius = radius;
return this;
}
@Override
public float getDistance(float x, float y, float z) {
float a = this.sourceA.getDistance(x, y, z);

View file

@ -1,17 +1,17 @@
package ru.betterend.util.sdf.operator;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
import ru.betterend.util.sdf.SDF;
public abstract class SDFUnary extends SDF {
protected SDF source;
public SDFUnary setSource(SDF source) {
this.source = source;
return this;
}
@Override
public BlockState getBlockState(BlockPos pos) {
return source.getBlockState(pos);

View file

@ -7,17 +7,17 @@ public class SDFCappedCone extends SDFPrimitive {
private float radius1;
private float radius2;
private float height;
public SDFCappedCone setRadius1(float radius) {
this.radius1 = radius;
return this;
}
public SDFCappedCone setRadius2(float radius) {
this.radius2 = radius;
return this;
}
public SDFCappedCone setHeight(float height) {
this.height = height;
return this;
@ -30,8 +30,7 @@ public class SDFCappedCone extends SDFPrimitive {
float k2y = 2 * height;
float cax = qx - MHelper.min(qx, (y < 0F) ? radius1 : radius2);
float cay = Math.abs(y) - height;
float mlt = Mth.clamp(MHelper.dot(radius2 - qx, height - y, k2x, k2y) / MHelper.dot(k2x, k2y, k2x, k2y), 0F,
1F);
float mlt = Mth.clamp(MHelper.dot(radius2 - qx, height - y, k2x, k2y) / MHelper.dot(k2x, k2y, k2x, k2y), 0F, 1F);
float cbx = qx - radius2 + k2x * mlt;
float cby = y - height + k2y * mlt;
float s = (cbx < 0F && cay < 0F) ? -1F : 1F;

View file

@ -6,17 +6,17 @@ import ru.betterend.util.MHelper;
public class SDFCapsule extends SDFPrimitive {
private float radius;
private float height;
public SDFCapsule setRadius(float radius) {
this.radius = radius;
return this;
}
public SDFCapsule setHeight(float height) {
this.height = height;
return this;
}
@Override
public float getDistance(float x, float y, float z) {
return MHelper.length(x, y - Mth.clamp(y, 0, height), z) - radius;

View file

@ -11,19 +11,19 @@ public class SDFLine extends SDFPrimitive {
private float x2;
private float y2;
private float z2;
public SDFLine setRadius(float radius) {
this.radius = radius;
return this;
}
public SDFLine setStart(float x, float y, float z) {
this.x1 = x;
this.y1 = y;
this.z1 = z;
return this;
}
public SDFLine setEnd(float x, float y, float z) {
this.x2 = x;
this.y2 = y;

View file

@ -7,25 +7,25 @@ public class SDFPie extends SDFPrimitive {
private float sin;
private float cos;
private float radius;
public SDFPie setAngle(float angle) {
this.sin = (float) Math.sin(angle);
this.cos = (float) Math.cos(angle);
return this;
}
public SDFPie setRadius(float radius) {
this.radius = radius;
return this;
}
@Override
public float getDistance(float x, float y, float z) {
float px = Math.abs(x);
float l = MHelper.length(px, y, z) - radius;
float m = MHelper.dot(px, z, sin, cos);
m = Mth.clamp(m, 0, radius);
float l = MHelper.length(px, y, z) - radius;
float m = MHelper.dot(px, z, sin, cos);
m = Mth.clamp(m, 0, radius);
m = MHelper.length(px - sin * m, z - cos * m);
return MHelper.max(l, m * (float) Math.signum(cos * px - sin * z));
return MHelper.max(l, m * (float) Math.signum(cos * px - sin * z));
}
}

View file

@ -1,41 +1,38 @@
package ru.betterend.util.sdf.primitive;
import java.util.function.Function;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import ru.betterend.util.sdf.SDF;
public abstract class SDFPrimitive extends SDF {
protected Function<BlockPos, BlockState> placerFunction;
public SDFPrimitive setBlock(Function<BlockPos, BlockState> placerFunction) {
this.placerFunction = placerFunction;
return this;
}
public SDFPrimitive setBlock(BlockState state) {
this.placerFunction = (pos) -> {
return state;
};
return this;
}
public SDFPrimitive setBlock(Block block) {
this.placerFunction = (pos) -> {
return block.defaultBlockState();
};
return this;
}
public BlockState getBlockState(BlockPos pos) {
return placerFunction.apply(pos);
}
/*
* public abstract CompoundTag toNBT(CompoundTag root) {
*
* }
*/
/*public abstract CompoundTag toNBT(CompoundTag root) {
}*/
}