Skip to content

Commit fc63d53

Browse files
committed
getMinSpawnY
1 parent 4cb9aa1 commit fc63d53

File tree

10 files changed

+82
-9
lines changed

10 files changed

+82
-9
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ org.gradle.jvmargs=-Xmx1G
66
loader_version=5ce86c8
77

88
# Mod Properties
9-
mod_version = 1.0.4
9+
mod_version = 1.0.5
1010
maven_group = io.github.minecraftcursedlegacy
1111
archives_base_name = cursed-legacy-api

legacy-terrain-v1/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
archivesBaseName = 'legacy-terrain-v1'
2-
version = getSubprojectVersion(project, '1.0.4')
2+
version = getSubprojectVersion(project, '1.0.5')
33

44
moduleDependencies(project, 'legacy-api-base')
55
dependencies {

legacy-terrain-v1/src/main/java/io/github/minecraftcursedlegacy/api/terrain/ChunkGenerator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,21 @@ protected void generateCarvers(int chunkX, int chunkZ, byte[] tiles, Biome[] bio
6161
* @param x the block x position to spawn the player at.
6262
* @param z the block z position to spawn the player at.
6363
* @return whether the player is allowed to spawn here.
64+
* @since 1.0.4
6465
*/
6566
public boolean isValidSpawnPos(int x, int z) {
6667
int surfaceTile = this.level.method_152(x, z);
6768
return surfaceTile == Tile.SAND.id;
6869
}
6970

71+
/**
72+
* @return the minimum y value at which the player can spawn naturally.
73+
* @since 1.0.5
74+
*/
75+
public int getMinSpawnY() {
76+
return 63;
77+
}
78+
7079
@Override
7180
public Chunk loadChunk(int x, int z) {
7281
return this.getChunk(x, z);
@@ -116,5 +125,4 @@ public final boolean method_1801() {
116125
public final boolean method_1805() {
117126
return true;
118127
}
119-
120128
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@
3030
* Because a certain way they implemented cancellable head injects is very annoying.
3131
* And messing with priorities didn't fix it.
3232
*/
33-
public interface InternalLevelSourceSetter {
33+
public interface InternalLevelSourceAccess {
3434
/**
3535
* Sets the internal api level source field on the class implementing this (i.e. Dimension).
3636
* @param source the level source.
3737
* @return the given source.
3838
*/
3939
LevelSource setInternalLevelSource(LevelSource source);
40+
41+
/**
42+
* Much much much more "impl" than the above method.
43+
* @return the internal api level source.
44+
*/
45+
LevelSource getInternalLevelSource();
4046
}

legacy-terrain-v1/src/main/java/io/github/minecraftcursedlegacy/mixin/terrain/MixinDimension.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
3030

3131
import io.github.minecraftcursedlegacy.api.terrain.ChunkGenerator;
32-
import io.github.minecraftcursedlegacy.impl.terrain.InternalLevelSourceSetter;
32+
import io.github.minecraftcursedlegacy.impl.terrain.InternalLevelSourceAccess;
3333
import net.minecraft.level.dimension.Dimension;
3434
import net.minecraft.level.source.LevelSource;
3535

3636
@Mixin(Dimension.class)
37-
public class MixinDimension implements InternalLevelSourceSetter {
37+
public class MixinDimension implements InternalLevelSourceAccess {
3838
private LevelSource api_level_source;
3939

4040
@Inject(at = @At("HEAD"), method = "method_1770", cancellable = true)
@@ -54,4 +54,9 @@ private void onCreateLevelSource(CallbackInfoReturnable<LevelSource> info) {
5454
public LevelSource setInternalLevelSource(LevelSource source) {
5555
return this.api_level_source = source;
5656
}
57+
58+
@Override
59+
public LevelSource getInternalLevelSource() {
60+
return this.api_level_source;
61+
}
5762
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2020 The Cursed Legacy Team.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
package io.github.minecraftcursedlegacy.mixin.terrain;
25+
26+
import org.spongepowered.asm.mixin.Mixin;
27+
import org.spongepowered.asm.mixin.injection.Constant;
28+
import org.spongepowered.asm.mixin.injection.ModifyConstant;
29+
30+
import io.github.minecraftcursedlegacy.api.terrain.ChunkGenerator;
31+
import io.github.minecraftcursedlegacy.impl.terrain.InternalLevelSourceAccess;
32+
import net.minecraft.level.Level;
33+
import net.minecraft.level.source.LevelSource;
34+
35+
@Mixin(Level.class)
36+
public class MixinLevel {
37+
@ModifyConstant(constant = @Constant(intValue = 63), method = "method_152")
38+
public int alterMinY(int original) {
39+
Level self = (Level) (Object) this;
40+
LevelSource cg = ((InternalLevelSourceAccess) self.dimension).getInternalLevelSource();
41+
42+
if (cg instanceof ChunkGenerator) {
43+
return ((ChunkGenerator) cg).getMinSpawnY();
44+
}
45+
46+
return original;
47+
}
48+
}

legacy-terrain-v1/src/main/resources/legacy-terrain.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"mixins": [
66
"MixinBiome",
77
"MixinDimension",
8+
"MixinLevel",
89
"MixinNetherLevelSource",
910
"MixinOverworldLevelSource"
1011
],

legacy-worldtypes-v1/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
archivesBaseName = 'legacy-worldtypes-v1'
2-
version = getSubprojectVersion(project, '1.0.4')
2+
version = getSubprojectVersion(project, '1.0.5')
33

44
moduleDependencies(project, 'legacy-api-base', 'legacy-attached-data-v1', 'legacy-terrain-v1', 'legacy-translations-v0')
55
dependencies {

legacy-worldtypes-v1/src/main/java/io/github/minecraftcursedlegacy/mixin/worldtype/MixinDimension.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import io.github.minecraftcursedlegacy.api.attacheddata.v1.DataManager;
3333
import io.github.minecraftcursedlegacy.api.worldtype.WorldType;
34-
import io.github.minecraftcursedlegacy.impl.terrain.InternalLevelSourceSetter;
34+
import io.github.minecraftcursedlegacy.impl.terrain.InternalLevelSourceAccess;
3535
import io.github.minecraftcursedlegacy.impl.worldtype.WorldTypeData;
3636
import io.github.minecraftcursedlegacy.impl.worldtype.WorldTypeImpl;
3737
import net.minecraft.level.LevelProperties;
@@ -61,7 +61,7 @@ private void api_createLevelSource(CallbackInfoReturnable<LevelSource> info) {
6161
WorldType type = WorldType.getById(data.getTypeId()); // retrieve the world type
6262

6363
if (type != WorldType.DEFAULT) { // only mess with non default in case another mod wants to mixin here for some reason
64-
info.setReturnValue(((InternalLevelSourceSetter) this).setInternalLevelSource( // set the custom chunk generator
64+
info.setReturnValue(((InternalLevelSourceAccess) this).setInternalLevelSource( // set the custom chunk generator
6565
type.createChunkGenerator(self.level, data.getOrCreateLoadedData(type.storesAdditionalData()))
6666
));
6767
}

legacy-worldtypes-v1/src/test/java/io/github/minecraftcursedlegacy/test/RandomChunkGenerator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ protected void buildSurface(int chunkX, int chunkZ, byte[] tiles, Biome[] biomes
4343
this.surface.buildSurface(chunkX, chunkZ, tiles, biomes);
4444
}
4545

46+
@Override
47+
public int getMinSpawnY() {
48+
return 67;
49+
}
50+
4651
@Override
4752
public boolean isValidSpawnPos(int x, int z) {
4853
int surfaceTile = this.level.method_152(x, z);

0 commit comments

Comments
 (0)