Skip to content

Commit

Permalink
refactor(next): world
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Sep 27, 2022
1 parent 82e4a40 commit 12371ef
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 77 deletions.
Expand Up @@ -2,7 +2,7 @@

import org.auioc.mcmod.arnicalib.base.phys.Shape;
import org.auioc.mcmod.arnicalib.game.nbt.NbtUtils;
import org.auioc.mcmod.arnicalib.utils.game.AABBUtils;
import org.auioc.mcmod.arnicalib.game.world.phys.AABBUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Mth;
Expand Down
@@ -1,4 +1,4 @@
package org.auioc.mcmod.arnicalib.utils.game;
package org.auioc.mcmod.arnicalib.game.world;

import java.util.function.Function;
import net.minecraft.core.Registry;
Expand All @@ -13,18 +13,18 @@
import net.minecraftforge.common.util.ITeleporter;
import net.minecraftforge.server.ServerLifecycleHooks;

public interface LevelUtils {
public class LevelUtils {

static ResourceKey<Level> createKey(ResourceLocation id) {
public static ResourceKey<Level> createKey(ResourceLocation id) {
return ResourceKey.create(Registry.DIMENSION_REGISTRY, id);
}

static ServerLevel getLevel(ResourceKey<Level> key) {
public static ServerLevel getLevel(ResourceKey<Level> key) {
return ServerLifecycleHooks.getCurrentServer().getLevel(key);
}


static ITeleporter createSimpleTeleporter(Vec3 pos, boolean playTeleportSound) {
public static ITeleporter createSimpleTeleporter(Vec3 pos, boolean playTeleportSound) {
return new ITeleporter() {
@Override
public Entity placeEntity(Entity entity, ServerLevel currentWorld, ServerLevel destWorld, float yaw, Function<Boolean, Entity> repositionEntity) {
Expand All @@ -40,19 +40,19 @@ public boolean playTeleportSound(ServerPlayer player, ServerLevel sourceWorld, S
};
}

static ITeleporter createSimpleTeleporter(Vec3i pos, boolean playTeleportSound) {
public static ITeleporter createSimpleTeleporter(Vec3i pos, boolean playTeleportSound) {
return createSimpleTeleporter(Vec3.atCenterOf(pos), playTeleportSound);
}

static ITeleporter createSimpleTeleporter(Vec3i pos) {
public static ITeleporter createSimpleTeleporter(Vec3i pos) {
return createSimpleTeleporter(Vec3.atCenterOf(pos), false);
}

static ITeleporter createSimpleTeleporter(Vec3 pos) {
public static ITeleporter createSimpleTeleporter(Vec3 pos) {
return createSimpleTeleporter(pos, false);
}

static ITeleporter createSimpleTeleporter(double x, double y, double z) {
public static ITeleporter createSimpleTeleporter(double x, double y, double z) {
return createSimpleTeleporter(new Vec3(x, y, z), false);
}

Expand Down
@@ -0,0 +1,48 @@
package org.auioc.mcmod.arnicalib.game.world;

import net.minecraft.world.level.Level;

public class MCTimeUtils {

public static final int SUNRISE = 23000;
public static final int DAY_BEGIN = 0;
public static final int DAY = 1000;
public static final int NOON = 6000;
public static final int SUNSET = 12000;
public static final int NIGHT = 13000;
public static final int MIDNIGHT = 18000;
public static final int DAY_END = 24000;

public static final int TICKS_PER_DAY = 24000;
public static final int TICKS_PER_HOUR = 1000;
public static final double TICKS_PER_MINUTE = 1000D / 60D;
public static final double TICKS_PER_SECOND = TICKS_PER_MINUTE / 60D;
public static final double TICKS_PER_MILLISECOND = TICKS_PER_SECOND / 1000D;

public static long[] getTime(Level level) {
return new long[] {level.getDayTime(), level.getGameTime(), System.currentTimeMillis()};
}

public static int getDayTime(Level level) {
return (int) (level.getDayTime() % 24000L);
}

public static int[] formatDayTime(long rawDayTime) {
int dayTime = (int) (rawDayTime % 2147483647L);

int day = dayTime / TICKS_PER_DAY;

int ticks = dayTime - day * TICKS_PER_DAY;
int hour = (int) (ticks / TICKS_PER_HOUR + 6) % 24;
int min = (int) (ticks / TICKS_PER_MINUTE) % 60;
int sec = (int) (ticks / TICKS_PER_SECOND) % 60;
int msec = (int) (ticks / TICKS_PER_MILLISECOND) % 1000;

return new int[] {day, hour, min, sec, msec};
}

public static int getDay(long dayTime) {
return ((int) (dayTime % 2147483647L)) / TICKS_PER_DAY;
}

}
@@ -1,4 +1,4 @@
package org.auioc.mcmod.arnicalib.utils.game;
package org.auioc.mcmod.arnicalib.game.world.phys;

import net.minecraft.core.Position;
import net.minecraft.core.Vec3i;
Expand All @@ -7,41 +7,41 @@
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.AABB;

public interface AABBUtils {
public class AABBUtils {

static AABB moveTo(AABB aabb, double x, double y, double z) {
public static AABB moveTo(AABB aabb, double x, double y, double z) {
return aabb.move(
x - ((aabb.minX + aabb.maxX) / 2), // (x+0.5)-(min+(max-min)/2)
y - aabb.minY,
z - ((aabb.minZ + aabb.maxZ) / 2)
);
}

static AABB moveTo(AABB aabb, Position pos) {
public static AABB moveTo(AABB aabb, Position pos) {
return moveTo(aabb, pos.x(), pos.y(), pos.z());
}

static AABB moveTo(AABB aabb, int x, int y, int z) {
public static AABB moveTo(AABB aabb, int x, int y, int z) {
return moveTo(aabb, x + 0.5D, y, x + 0.5D);
}

static AABB moveTo(AABB aabb, Vec3i pos) {
public static AABB moveTo(AABB aabb, Vec3i pos) {
return moveTo(aabb, pos.getX() + 0.5D, pos.getY(), pos.getZ() + 0.5D);
}

static boolean isEmpty(AABB aabb, Level level) {
public static boolean isEmpty(AABB aabb, Level level) {
return level.getBlockStates(aabb).allMatch(BlockState::isAir);
}

static boolean containsSolid(AABB aabb, Level level) {
public static boolean containsSolid(AABB aabb, Level level) {
return level.getBlockStates(aabb).map(BlockState::getMaterial).anyMatch(Material::isSolid);
}

static boolean containsLiquid(AABB aabb, Level level) {
public static boolean containsLiquid(AABB aabb, Level level) {
return level.getBlockStates(aabb).map(BlockState::getMaterial).anyMatch(Material::isLiquid);
}

static double[][] getEdges(AABB aabb) {
public static double[][] getEdges(AABB aabb) {
return new double[][] {
{aabb.minX, aabb.minY, aabb.minZ, aabb.minX, aabb.minY, aabb.maxZ},
{aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.minY, aabb.minZ},
Expand All @@ -62,4 +62,5 @@ static double[][] getEdges(AABB aabb) {
{aabb.minX, aabb.minY, aabb.maxZ, aabb.minX, aabb.maxY, aabb.maxZ},
};
}

}
@@ -1,4 +1,4 @@
package org.auioc.mcmod.arnicalib.utils.game;
package org.auioc.mcmod.arnicalib.game.world.phys;

import java.util.Optional;
import java.util.function.Function;
Expand Down
@@ -1,8 +1,9 @@
package org.auioc.mcmod.arnicalib.utils.game;
package org.auioc.mcmod.arnicalib.game.world.position;

import java.util.Optional;
import java.util.Random;
import org.auioc.mcmod.arnicalib.base.random.RandomUtils;
import org.auioc.mcmod.arnicalib.utils.game.BlockUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
Expand All @@ -11,23 +12,23 @@
import net.minecraft.world.phys.Vec3;


public interface PositionUtils {
public class PositionUtils {

static boolean isInWorldBounds(BlockPos pos, Level level) {
public static boolean isInWorldBounds(BlockPos pos, Level level) {
return level.getWorldBorder().isWithinBounds(pos)
&& pos.getY() < level.getMaxBuildHeight()
&& pos.getY() >= level.getMinBuildHeight();
}

static boolean canStandOn(BlockPos pos, Level level) {
public static boolean canStandOn(BlockPos pos, Level level) {
return BlockUtils.canStandOn(level.getBlockState(pos));
}

static boolean canStand(BlockPos pos, Level level) {
public static boolean canStand(BlockPos pos, Level level) {
return canStandOn(pos.below(), level);
}

static Optional<Integer> findStandableY(Level level, int x, int z, int minY, int maxY) {
public static Optional<Integer> findStandableY(Level level, int x, int z, int minY, int maxY) {
minY = Math.max(minY, level.getMinBuildHeight());
maxY = Math.min(maxY, level.getMaxBuildHeight() - 1);
var pos = new MutableBlockPos(x, maxY, z);
Expand All @@ -40,11 +41,11 @@ static Optional<Integer> findStandableY(Level level, int x, int z, int minY, int
return Optional.empty();
}

static Optional<Integer> findStandableY(Level level, int x, int z) {
public static Optional<Integer> findStandableY(Level level, int x, int z) {
return findStandableY(level, x, z, level.getMinBuildHeight(), level.getMaxBuildHeight() - 1);
}

static Vec3i random(Vec3i center, int radius, Random random) {
public static Vec3i random(Vec3i center, int radius, Random random) {
radius += 1;
return new Vec3i(
center.getX() + RandomUtils.offset(radius, random),
Expand All @@ -53,7 +54,7 @@ static Vec3i random(Vec3i center, int radius, Random random) {
);
}

static Vec3 random(Vec3 center, double radius, Random random) {
public static Vec3 random(Vec3 center, double radius, Random random) {
radius += 1.0D;
return new Vec3(
center.x + RandomUtils.offset(radius, random),
Expand All @@ -62,7 +63,7 @@ static Vec3 random(Vec3 center, double radius, Random random) {
);
}

static BlockPos random(BlockPos center, int radius, Random random) {
public static BlockPos random(BlockPos center, int radius, Random random) {
return new BlockPos(random((Vec3i) center, radius, random));
}

Expand Down
@@ -1,7 +1,9 @@
package org.auioc.mcmod.arnicalib.utils.game;
package org.auioc.mcmod.arnicalib.game.world.position;

import java.util.Optional;
import java.util.Random;
import org.auioc.mcmod.arnicalib.game.world.phys.AABBUtils;
import org.auioc.mcmod.arnicalib.utils.game.EntityUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
Expand Down
Expand Up @@ -5,8 +5,8 @@
import java.util.List;
import java.util.Optional;
import org.auioc.mcmod.arnicalib.game.command.CommandSourceUtils;
import org.auioc.mcmod.arnicalib.game.world.position.RandomTeleporter;
import org.auioc.mcmod.arnicalib.utils.game.EntityUtils;
import org.auioc.mcmod.arnicalib.utils.game.RandomTeleporter;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.DoubleArgumentType;
Expand Down
Expand Up @@ -3,6 +3,8 @@
import java.util.function.Function;
import java.util.function.Predicate;
import javax.annotation.Nullable;
import org.auioc.mcmod.arnicalib.game.world.LevelUtils;
import org.auioc.mcmod.arnicalib.game.world.phys.RayTraceUtils;
import net.minecraft.core.Vec3i;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.Entity;
Expand Down

This file was deleted.

0 comments on commit 12371ef

Please sign in to comment.