Skip to content

Commit

Permalink
Moved java.util.random to Minecraft random
Browse files Browse the repository at this point in the history
  • Loading branch information
LudoCrypt committed Jul 8, 2022
1 parent 79f1047 commit b4222d3
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ satin_version=1.8.0
sodium_version=mc1.19-0.4.2
iris_version=1.19.x-v1.2.5

mod_version = 5.3.0
mod_version = 5.3.1
maven_group = net.ludocrypt
archives_base_name = limlib
58 changes: 49 additions & 9 deletions src/main/java/net/ludocrypt/limlib/api/LiminalUtil.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package net.ludocrypt.limlib.api;

import java.util.EnumSet;
import java.util.List;

import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementProgress;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ChunkTicketType;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.TeleportTarget;
import net.minecraft.world.World;
import net.minecraft.world.biome.source.util.MultiNoiseUtil.MultiNoiseSampler;
import net.minecraft.world.gen.densityfunction.DensityFunctionTypes;

Expand All @@ -22,15 +30,47 @@ public class LiminalUtil {
public static float travelingPitch = 1.0F;

public static <E extends Entity> E travelTo(E teleported, ServerWorld destination, TeleportTarget target, SoundEvent sound, float volume, float pitch) {
try {
travelingSound = sound;
travelingVolume = volume;
travelingPitch = pitch;
return FabricDimensions.teleport(teleported, destination, target);
} finally {
travelingSound = null;
travelingVolume = 0.0F;
travelingPitch = 0.0F;
if (destination.equals(teleported.getWorld())) {

BlockPos blockPos = new BlockPos(target.position);
if (!World.isValid(blockPos)) {
throw new UnsupportedOperationException("Position " + blockPos.toString() + " is out of this world!");
}

float f = MathHelper.wrapDegrees(target.pitch);
float g = MathHelper.wrapDegrees(target.yaw);

if (teleported instanceof ServerPlayerEntity) {
ChunkPos chunkPos = new ChunkPos(blockPos);
destination.getChunkManager().addTicket(ChunkTicketType.POST_TELEPORT, chunkPos, 1, teleported.getId());
teleported.stopRiding();
if (((ServerPlayerEntity) teleported).isSleeping()) {
((ServerPlayerEntity) teleported).wakeUp(true, true);
}
((ServerPlayerEntity) teleported).networkHandler.requestTeleport(target.position.x, target.position.y, target.position.z, f, g, EnumSet.noneOf(PlayerPositionLookS2CPacket.Flag.class));

teleported.setHeadYaw(f);
} else {
float h = MathHelper.clamp(g, -90.0f, 90.0f);
teleported.refreshPositionAndAngles(target.position.x, target.position.y, target.position.z, f, h);
teleported.setHeadYaw(f);
}

teleported.setVelocity(target.velocity);
teleported.world.playSound(null, teleported.getX(), teleported.getY(), teleported.getZ(), sound, SoundCategory.AMBIENT, volume, pitch);

return teleported;
} else {
try {
travelingSound = sound;
travelingVolume = volume;
travelingPitch = pitch;
return FabricDimensions.teleport(teleported, destination, target);
} finally {
travelingSound = null;
travelingVolume = 0.0F;
travelingPitch = 0.0F;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package net.ludocrypt.limlib.api.world.maze;

import java.util.List;
import java.util.Random;
import java.util.Stack;

import com.google.common.collect.Lists;

import net.minecraft.util.math.random.Random;

public class DepthFirstMaze extends MazeComponent {

public Stack<Vec2i> stack = new Stack<Vec2i>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package net.ludocrypt.limlib.api.world.maze;

import java.util.List;
import java.util.Random;
import java.util.Stack;

import com.google.common.collect.Lists;

import net.minecraft.util.math.random.Random;

public class DepthFirstMazeSolver extends MazeComponent {

private final MazeComponent mazeToSolve;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package net.ludocrypt.limlib.api.world.maze;

import java.util.HashMap;
import java.util.Random;
import java.util.function.Function;

import com.mojang.serialization.Codec;

import net.ludocrypt.limlib.api.world.maze.MazeComponent.CellState;
import net.ludocrypt.limlib.impl.LimlibRegistries;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.chunk.ChunkGenerator;
Expand Down Expand Up @@ -44,7 +44,7 @@ public void generateMaze(BlockPos pos, Chunk chunk, ChunkRegion region, C chunkG
if (this.mazes.containsKey(mazePos)) {
maze = this.mazes.get(mazePos);
} else {
maze = this.newMaze(mazePos, region, chunk, chunkGenerator, redundancy ? width + 4 : width, redundancy ? height + 4 : height, new Random(blockSeed(mazePos.getX(), mazePos.getZ(), seedModifier)));
maze = this.newMaze(mazePos, region, chunk, chunkGenerator, redundancy ? width + 4 : width, redundancy ? height + 4 : height, Random.create(blockSeed(mazePos.getX(), mazePos.getZ(), seedModifier)));
this.mazes.put(mazePos, maze);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package net.ludocrypt.limlib.api.world.maze;

import java.util.Random;

import com.mojang.datafixers.util.Pair;

import net.ludocrypt.limlib.api.world.maze.MazeComponent.CellState;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.random.Random;

public enum MazePiece {
T_PIECE, F_PIECE, I_PIECE, L_PIECE, NUB, BLANK;
Expand Down

0 comments on commit b4222d3

Please sign in to comment.