use of net.minecraft.util.math.BlockPos.Mutable in project Structurize by ldtteam.
the class UpdateSchematicsCommand method update.
private static void update(@NotNull final File input, @NotNull final File globalInputFolder, @NotNull final File globalOutputFolder) {
if (input.isDirectory()) {
for (final File file : input.listFiles()) {
update(file, globalInputFolder, globalOutputFolder);
}
return;
}
if (input.getPath().endsWith(".blueprint")) {
return;
}
try {
final File output = new File(globalOutputFolder, input.toString().replaceAll("\\.nbt", ".blueprint").replace(globalInputFolder.toString(), ""));
output.getParentFile().mkdirs();
CompoundNBT blueprint = CompressedStreamTools.readCompressed(Files.newInputStream(input.toPath()));
if (blueprint == null || blueprint.isEmpty()) {
return;
}
// blueprint = StructureUtils.getFixer().process(FixTypes.STRUCTURE, blueprint);
// TODO: this! (datafixer)
final ListNBT blocks = blueprint.getList("blocks", NBT.TAG_COMPOUND);
final ListNBT pallete = blueprint.getList("palette", NBT.TAG_COMPOUND);
final CompoundNBT bluePrintCompound = new CompoundNBT();
final ListNBT list = blueprint.getList("size", NBT.TAG_INT);
final int[] size = new int[] { list.getInt(0), list.getInt(1), list.getInt(2) };
bluePrintCompound.putShort("size_x", (short) size[0]);
bluePrintCompound.putShort("size_y", (short) size[1]);
bluePrintCompound.putShort("size_z", (short) size[2]);
final boolean addStructureVoid = blocks.size() != size[0] * size[1] * size[2];
short structureVoidID = 0;
if (addStructureVoid) {
structureVoidID = (short) pallete.size();
pallete.add(NBTUtil.writeBlockState(Blocks.STRUCTURE_VOID.defaultBlockState()));
}
final Set<String> mods = new HashSet<>();
for (int i = 0; i < pallete.size(); i++) {
final CompoundNBT blockState = pallete.getCompound(i);
final String modid = blockState.getString("Name").split(":")[0];
mods.add(modid);
}
final ListNBT requiredMods = new ListNBT();
for (final String str : mods) {
requiredMods.add(StringNBT.valueOf(str));
}
bluePrintCompound.put("palette", pallete);
bluePrintCompound.put("required_mods", requiredMods);
final Mutable pos = new Mutable();
final short[][][] dataArray = new short[size[1]][size[2]][size[0]];
if (addStructureVoid) {
for (int i = 0; i < size[1]; i++) {
for (int j = 0; j < size[2]; j++) {
for (int k = 0; k < size[0]; k++) {
dataArray[i][j][k] = structureVoidID;
}
}
}
}
final ListNBT tileEntities = new ListNBT();
for (int i = 0; i < blocks.size(); i++) {
final CompoundNBT comp = blocks.getCompound(i);
updatePos(pos, comp);
dataArray[pos.getY()][pos.getZ()][pos.getX()] = (short) comp.getInt("state");
if (comp.contains("nbt")) {
final CompoundNBT te = comp.getCompound("nbt");
te.putShort("x", (short) pos.getX());
te.putShort("y", (short) pos.getY());
te.putShort("z", (short) pos.getZ());
tileEntities.add(te);
}
}
bluePrintCompound.putIntArray("blocks", convertBlocksToSaveData(dataArray, (short) size[0], (short) size[1], (short) size[2]));
bluePrintCompound.put("tile_entities", tileEntities);
bluePrintCompound.put("architects", new ListNBT());
bluePrintCompound.put("name", (StringNBT.valueOf(input.getName().replaceAll("\\.nbt", ""))));
bluePrintCompound.putInt("version", 1);
final ListNBT newEntities = new ListNBT();
if (blueprint.contains("entities")) {
final ListNBT entities = blueprint.getList("entities", NBT.TAG_COMPOUND);
for (int i = 0; i < entities.size(); i++) {
final CompoundNBT entityData = entities.getCompound(i);
final CompoundNBT entity = entityData.getCompound("nbt");
entity.put("Pos", entityData.get("pos"));
newEntities.add(entity);
}
}
bluePrintCompound.put("entities", newEntities);
output.createNewFile();
CompressedStreamTools.writeCompressed(bluePrintCompound, Files.newOutputStream(output.toPath()));
} catch (final IOException e) {
e.printStackTrace();
}
}
use of net.minecraft.util.math.BlockPos.Mutable in project friends-and-foes by Faboslav.
the class IceologerSpawner method spawn.
@Override
public int spawn(ServerWorld world, boolean spawnMonsters, boolean spawnAnimals) {
if (spawnMonsters == false || FriendsAndFoesConfig.enableIceologerSpawn == false) {
return 0;
}
Random random = world.random;
--this.cooldown;
if (this.cooldown > 0) {
return 0;
}
this.cooldown += 12000 + random.nextInt(1200);
long l = world.getTimeOfDay() / 24000L;
if (l < 5L || world.isDay() == false || random.nextInt(5) != 0) {
return 0;
}
int playerCount = world.getPlayers().size();
if (playerCount == 0) {
return 0;
}
PlayerEntity playerEntity = world.getPlayers().get(random.nextInt(playerCount));
if (playerEntity.isSpectator() || world.isNearOccupiedPointOfInterest(playerEntity.getBlockPos(), 2)) {
return 0;
}
int j = (24 + random.nextInt(24)) * (random.nextBoolean() ? -1 : 1);
int k = (24 + random.nextInt(24)) * (random.nextBoolean() ? -1 : 1);
Mutable mutable = playerEntity.getBlockPos().mutableCopy().move(j, 0, k);
var minX = mutable.getX() - 10;
var minZ = mutable.getZ() - 10;
var maxX = mutable.getX() + 10;
var maxZ = mutable.getZ() + 10;
if (world.isRegionLoaded(minX, minZ, maxX, maxZ) == false) {
return 0;
}
RegistryEntry<Biome> registryEntry = world.getBiome(mutable);
Category category = Biome.getCategory(registryEntry);
var precipitation = registryEntry.value().getPrecipitation();
if (category != Biome.Category.TAIGA || precipitation != Biome.Precipitation.SNOW) {
return 0;
}
mutable.setY(world.getTopPosition(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, mutable).getY());
BlockState blockState = world.getBlockState(mutable);
if (SpawnHelper.isClearForSpawn(world, mutable, blockState, blockState.getFluidState(), ModEntity.ICEOLOGER.get()) == false || PatrolEntity.canSpawn(ModEntity.ICEOLOGER.get(), world, SpawnReason.PATROL, mutable, random) == false) {
return 0;
}
var iceologer = ModEntity.ICEOLOGER.get().create(world);
if (iceologer == null) {
return 0;
}
iceologer.setPatrolLeader(true);
iceologer.setRandomPatrolTarget();
iceologer.setPosition(mutable.getX(), mutable.getY(), mutable.getZ());
iceologer.initialize(world, world.getLocalDifficulty(mutable), SpawnReason.PATROL, null, null);
world.spawnEntityAndPassengers(iceologer);
return 1;
}
use of net.minecraft.util.math.BlockPos.Mutable in project friends-and-foes by Faboslav.
the class IllusionerSpawner method spawn.
@Override
public int spawn(ServerWorld world, boolean spawnMonsters, boolean spawnAnimals) {
if (spawnMonsters == false || FriendsAndFoesConfig.enableIllusionerSpawn == false) {
return 0;
}
Random random = world.random;
--this.cooldown;
if (this.cooldown > 0) {
return 0;
}
this.cooldown += 12000 + random.nextInt(1200);
long l = world.getTimeOfDay() / 24000L;
if (l < 5L || world.isDay() == false || random.nextInt(5) != 0) {
return 0;
}
int playerCount = world.getPlayers().size();
if (playerCount == 0) {
return 0;
}
PlayerEntity playerEntity = world.getPlayers().get(random.nextInt(playerCount));
if (playerEntity.isSpectator() || world.isNearOccupiedPointOfInterest(playerEntity.getBlockPos(), 2)) {
return 0;
}
int j = (24 + random.nextInt(24)) * (random.nextBoolean() ? -1 : 1);
int k = (24 + random.nextInt(24)) * (random.nextBoolean() ? -1 : 1);
Mutable mutable = playerEntity.getBlockPos().mutableCopy().move(j, 0, k);
var minX = mutable.getX() - 10;
var minZ = mutable.getZ() - 10;
var maxX = mutable.getX() + 10;
var maxZ = mutable.getZ() + 10;
if (world.isRegionLoaded(minX, minZ, maxX, maxZ) == false) {
return 0;
}
RegistryEntry<Biome> registryEntry = world.getBiome(mutable);
Category category = Biome.getCategory(registryEntry);
var precipitation = registryEntry.value().getPrecipitation();
if (category != Category.TAIGA || precipitation != Biome.Precipitation.RAIN) {
return 0;
}
mutable.setY(world.getTopPosition(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, mutable).getY());
BlockState blockState = world.getBlockState(mutable);
if (SpawnHelper.isClearForSpawn(world, mutable, blockState, blockState.getFluidState(), EntityType.ILLUSIONER) == false || PatrolEntity.canSpawn(EntityType.ILLUSIONER, world, SpawnReason.PATROL, mutable, random) == false) {
return 0;
}
var illusioner = EntityType.ILLUSIONER.create(world);
if (illusioner == null) {
return 0;
}
illusioner.setPatrolLeader(true);
illusioner.setRandomPatrolTarget();
illusioner.setPosition(mutable.getX(), mutable.getY(), mutable.getZ());
illusioner.initialize(world, world.getLocalDifficulty(mutable), SpawnReason.PATROL, null, null);
world.spawnEntityAndPassengers(illusioner);
return 1;
}
use of net.minecraft.util.math.BlockPos.Mutable in project ChocolateQuestRepoured by TeamChocoQuest.
the class GeneratableMapInfo method updateMapColorAt.
private static void updateMapColorAt(World world, int mapX, int mapZ, MapData data) {
int i = 1 << data.scale;
double d0 = 0.0D;
int k2 = (data.x / i + mapX - 64) * i;
int l2 = (data.z / i + mapZ - 64) * i;
Multiset<MaterialColor> multiset = HashMultiset.create();
Chunk chunk = world.getChunk(k2 >> 4, l2 >> 4);
int i3 = k2 & 15;
int j3 = l2 & 15;
int k3 = 0;
double d1 = 0.0D;
if (world.dimension().equals(World.NETHER)) {
int l3 = k2 + l2 * 231_871;
l3 = l3 * l3 * 31_287_121 + l3 * 11;
if ((l3 >> 20 & 1) == 0) {
multiset.add(Blocks.DIRT.defaultBlockState().getMapColor(world, BlockPos.ZERO), 10);
} else {
multiset.add(Blocks.STONE.defaultBlockState().getMapColor(world, BlockPos.ZERO), 100);
}
d1 = 100.0D;
} else {
Mutable pos = new Mutable();
for (int i4 = 0; i4 < i; ++i4) {
for (int j4 = 0; j4 < i; ++j4) {
// Correct replacement?
int k4 = chunk.getHeight(Type.WORLD_SURFACE, i4 + i3, j4 + j3) + 1;
BlockState state = Blocks.AIR.defaultBlockState();
if (k4 <= 1) {
state = Blocks.BEDROCK.defaultBlockState();
} else {
label175: {
while (true) {
--k4;
state = chunk.getBlockState(new BlockPos(i4 + i3, k4, j4 + j3));
pos.set((chunk.getPos().x << 4) + i4 + i3, k4, (chunk.getPos().z << 4) + j4 + j3);
if (state.getMapColor(world, pos) != MaterialColor.NONE || k4 <= 0) {
break;
}
}
if (k4 > 0 && state.getMaterial().isLiquid()) {
int l4 = k4 - 1;
while (true) {
BlockState iblockstate1 = chunk.getBlockState(new BlockPos(i4 + i3, l4--, j4 + j3));
++k3;
if (l4 <= 0 || !iblockstate1.getMaterial().isLiquid()) {
break label175;
}
}
}
}
}
d1 += (double) k4 / (double) (i * i);
multiset.add(state.getMapColor(world, pos));
}
}
}
k3 = k3 / (i * i);
double d2 = (d1 - d0) * 4.0D / (i + 4) + ((mapX + mapZ & 1) - 0.5D) * 0.4D;
int i5 = 1;
if (d2 > 0.6D) {
i5 = 2;
}
if (d2 < -0.6D) {
i5 = 0;
}
MaterialColor mapcolor = Iterables.getFirst(Multisets.copyHighestCountFirst(multiset), MaterialColor.NONE);
if (mapcolor == MaterialColor.WATER) {
d2 = k3 * 0.1D + (mapX + mapZ & 1) * 0.2D;
i5 = 1;
if (d2 < 0.5D) {
i5 = 2;
}
if (d2 > 0.9D) {
i5 = 0;
}
}
byte b0 = data.colors[mapX + mapZ * 128];
// Correct replacement?
byte b1 = (byte) (mapcolor.col * 4 + i5);
if (b0 != b1) {
data.colors[mapX + mapZ * 128] = b1;
data.setDirty(mapX, mapZ);
}
}
Aggregations