-
Notifications
You must be signed in to change notification settings - Fork 40
Temp PR to leave comments on #321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Mqrius
wants to merge
8
commits into
dev
Choose a base branch
from
feature/customSpawnSelection
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a271a01
the things
BlueBoat29 095c7ac
Merge remote-tracking branch 'upstream/dev' into feature/customSpawnS…
BlueBoat29 031065f
save related stuff
BlueBoat29 d827dd6
Merge remote-tracking branch 'upstream/dev' into feature/customSpawnS…
BlueBoat29 d10e1a5
Merge remote-tracking branch 'upstream/dev' into feature/customSpawnS…
BlueBoat29 1887209
now generates a beneath spawn position
BlueBoat29 3d95922
player respawn works, doesn't check for space to spawn
BlueBoat29 cf39a56
first login works
BlueBoat29 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 217 additions & 0 deletions
217
src/main/java/su/terrafirmagreg/core/common/data/utils/CustomSpawnHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,217 @@ | ||
| package su.terrafirmagreg.core.common.data.utils; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.function.Function; | ||
|
|
||
| import net.dries007.tfc.TerraFirmaCraft; | ||
| import net.dries007.tfc.world.ChunkGeneratorExtension; | ||
| import net.dries007.tfc.world.biome.BiomeExtension; | ||
| import net.dries007.tfc.world.biome.BiomeSourceExtension; | ||
| import net.minecraft.core.BlockPos; | ||
| import net.minecraft.core.GlobalPos; | ||
| import net.minecraft.core.QuartPos; | ||
| import net.minecraft.network.chat.Component; | ||
| import net.minecraft.network.chat.MutableComponent; | ||
| import net.minecraft.resources.ResourceKey; | ||
| import net.minecraft.server.level.ServerLevel; | ||
| import net.minecraft.server.level.ServerPlayer; | ||
| import net.minecraft.util.RandomSource; | ||
| import net.minecraft.world.entity.Entity; | ||
| import net.minecraft.world.level.Level; | ||
| import net.minecraftforge.common.util.ITeleporter; | ||
|
|
||
| import earth.terrarium.adastra.api.planets.Planet; | ||
|
|
||
| import su.terrafirmagreg.core.config.TFGConfig; | ||
|
|
||
| public class CustomSpawnHelper { | ||
|
|
||
| public static final GlobalPos BENEATH_PLACEHOLDER = GlobalPos.of(ServerLevel.NETHER, BlockPos.ZERO); | ||
| public static final GlobalPos MARS_PLACEHOLDER = GlobalPos.of(Planet.MARS, BlockPos.ZERO); | ||
|
|
||
| public static void respawnTeleporter(ServerPlayer player, ServerLevel targetLevel, GlobalPos worldSpawn) { | ||
| System.out.println("attempting to spawn player at: " + worldSpawn); | ||
|
|
||
| player.changeDimension(targetLevel, new ITeleporter() { | ||
|
|
||
| @Override | ||
| public Entity placeEntity(Entity entity, ServerLevel currentWorld, ServerLevel destWorld, float yaw, Function<Boolean, Entity> repositionEntity) { | ||
| BlockPos spawnPos = worldSpawn.pos(); | ||
|
|
||
| entity.teleportTo(destWorld, spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), Set.of(), entity.getYRot(), entity.getXRot()); | ||
|
|
||
| return entity; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean playTeleportSound(ServerPlayer player, ServerLevel sourceWorld, ServerLevel destWorld) { | ||
| return false; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| public static CustomSpawnCondition getFromConfig() { | ||
| return CUSTOM_SPAWN_CONDITIONS.get(TFGConfig.COMMON.NEW_WORLD_SPAWN.get()); | ||
| } | ||
|
|
||
| public static void resetConfigValue() { | ||
| TFGConfig.COMMON.NEW_WORLD_SPAWN.set(DEFAULT_SPAWN.id); | ||
| } | ||
|
|
||
| public static boolean testWithinRanges(float temperature, float rainfall, CustomSpawnCondition condition) { | ||
| float[] tempRange = condition.temperatureRange; | ||
| float[] rainRange = condition.rainfallRange; | ||
|
|
||
| //System.out.println(tempRange[0] + " <= " + temperature + " <= " + tempRange[1]); | ||
| //System.out.println(rainRange[0] + " <= " + rainfall + " <= " + rainRange[1]); | ||
| if (tempRange[0] <= temperature && temperature <= tempRange[1]) { | ||
| //System.out.println("Temp Match"); | ||
| if (rainRange[0] <= rainfall && rainfall <= rainRange[1]) { | ||
| //System.out.println("Rain Match"); | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| //Adapted from TFC code, but with more config | ||
| public static BlockPos findSpawnBiome(int spawnCenterX, int spawnCenterZ, int spawnRadius, RandomSource random, ChunkGeneratorExtension extension) { | ||
| int step = Math.max(1, spawnRadius / 256); | ||
| int centerX = QuartPos.fromBlock(spawnCenterX); | ||
| int centerZ = QuartPos.fromBlock(spawnCenterZ); | ||
| int maxRadius = QuartPos.fromBlock(spawnRadius); | ||
| BlockPos found = null; | ||
| int count = 0; | ||
|
|
||
| for (int radius = maxRadius; radius <= maxRadius; radius += step) { | ||
| for (int dx = -radius; dx <= radius; dx += step) { | ||
| for (int dz = -radius; dz <= radius; dz += step) { | ||
| int quartX = centerX + dz; | ||
| int quartZ = centerZ + dx; | ||
| BiomeExtension biome = ((BiomeSourceExtension) extension.self().getBiomeSource()).getBiomeExtensionNoRiver(quartX, quartZ); | ||
| if (biome.isSpawnable()) { | ||
| if (found == null || random.nextInt(count + 1) == 0) { | ||
| found = new BlockPos(QuartPos.toBlock(quartX), 0, QuartPos.toBlock(quartZ)); | ||
| } | ||
|
|
||
| ++count; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (found == null) { | ||
| TerraFirmaCraft.LOGGER.warn("Unable to find spawn biome!"); | ||
| return new BlockPos(spawnCenterX, 0, spawnCenterZ); | ||
| } else { | ||
| return found; | ||
| } | ||
| } | ||
|
|
||
| public static HashMap<String, CustomSpawnCondition> CUSTOM_SPAWN_CONDITIONS = new HashMap<>(); | ||
|
|
||
| public static HashMap<String, MutableComponent> SPAWN_DIFFICULTIES = new HashMap<>(Map.of( | ||
| "easy", Component.translatable("tfg.gui.spawn_difficulty.easy"), | ||
| "normal", Component.translatable("tfg.gui.spawn_difficulty.normal"), | ||
| "hard", Component.translatable("tfg.gui.spawn_difficulty.hard"), | ||
| "extreme", Component.translatable("tfg.gui.spawn_difficulty.extreme"))); | ||
|
|
||
| public static final CustomSpawnCondition DESERT_SPAWN = new CustomSpawnCondition( | ||
| "desert", | ||
| -10000, | ||
| 10000, | ||
| 1, | ||
| new float[] { 20f, 30f }, | ||
| new float[] { 0f, 90f }, | ||
| Level.OVERWORLD, | ||
| SPAWN_DIFFICULTIES.get("hard")); | ||
|
|
||
| public static final CustomSpawnCondition POLAR_SPAWN = new CustomSpawnCondition( | ||
| "polar", | ||
| -2000, | ||
| -10000, | ||
| 1, | ||
| new float[] { -20f, -10f }, | ||
| new float[] { 100f, 250f }, | ||
| Level.OVERWORLD, | ||
| SPAWN_DIFFICULTIES.get("hard")); | ||
|
|
||
| public static final CustomSpawnCondition TEMPERATE_SPAWN = new CustomSpawnCondition( | ||
| "temperate", | ||
| 2500, | ||
| 1500, | ||
| 1, | ||
| new float[] { 5f, 15f }, | ||
| new float[] { 250f, 350f }, | ||
| Level.OVERWORLD, | ||
| SPAWN_DIFFICULTIES.get("normal")); | ||
|
|
||
| public static final CustomSpawnCondition TROPICAL_SPAWN = new CustomSpawnCondition( | ||
| "tropical", | ||
| 10000, | ||
| 10000, | ||
| 1, | ||
| new float[] { 20f, 30f }, | ||
| new float[] { 350f, 500f }, | ||
| Level.OVERWORLD, | ||
| SPAWN_DIFFICULTIES.get("easy")); | ||
|
|
||
| public static final CustomSpawnCondition BENEATH_SPAWN = new CustomSpawnCondition( | ||
| "beneath", | ||
| 0, | ||
| 0, | ||
| 1, | ||
| new float[] { -20f, 20f }, | ||
| new float[] { 0f, 400f }, | ||
| Level.NETHER, | ||
| SPAWN_DIFFICULTIES.get("extreme")); | ||
|
|
||
| public static final CustomSpawnCondition DEFAULT_SPAWN = new CustomSpawnCondition( | ||
| "default", | ||
| 0, | ||
| 0, | ||
| 1, | ||
| new float[] { -20f, 20f }, | ||
| new float[] { 0f, 400f }, | ||
| Level.OVERWORLD, | ||
| SPAWN_DIFFICULTIES.get("normal")); | ||
|
|
||
| /** | ||
| * Registers a new CustomSpawnCondition in the CUSTOM_SPAWN_CONDITIONS map. | ||
| * @param condition The CustomSpawnCondition to register. | ||
| */ | ||
| private static void initNewType(CustomSpawnCondition condition) { | ||
| CUSTOM_SPAWN_CONDITIONS.put(condition.id, condition); | ||
| } | ||
|
|
||
| static { | ||
| initNewType(DEFAULT_SPAWN); | ||
| initNewType(TEMPERATE_SPAWN); | ||
| initNewType(TROPICAL_SPAWN); | ||
| initNewType(POLAR_SPAWN); | ||
| initNewType(DESERT_SPAWN); | ||
| initNewType(BENEATH_SPAWN); | ||
| } | ||
|
|
||
| /// Holds spawn conditions for a particular custom world spawn | ||
| /// @param id string used for mapping | ||
| /// @param spawnCenterX int block pos estimate on the X axis | ||
| /// @param spawnCenterZ int block pos estimate on the Z axis | ||
| /// @param spawnRadiusMultiplier int multiplier on default radius | ||
| /// @param temperatureRange inclusive range to check for the temperature | ||
| /// @param rainfallRange inclusive range to check for the rainfall | ||
| /// @param dimension level that this spawn occurs in | ||
| /// @param difficulty translatable component that displays the difficulty | ||
| public record CustomSpawnCondition( | ||
| String id, | ||
| int spawnCenterX, | ||
| int spawnCenterZ, | ||
| int spawnRadiusMultiplier, | ||
| float[] temperatureRange, | ||
| float[] rainfallRange, | ||
| ResourceKey<Level> dimension, | ||
| MutableComponent difficulty) { | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The outer loop never iterates, because radius starts at maxRadius. Is that intentional? Can either remove the outer loop, or start close in and loop outwards if that's what you want