Skip to content

Commit

Permalink
getMinSpawnY
Browse files Browse the repository at this point in the history
  • Loading branch information
valoeghese committed Apr 30, 2021
1 parent 4cb9aa1 commit fc63d53
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ org.gradle.jvmargs=-Xmx1G
loader_version=5ce86c8

# Mod Properties
mod_version = 1.0.4
mod_version = 1.0.5
maven_group = io.github.minecraftcursedlegacy
archives_base_name = cursed-legacy-api
2 changes: 1 addition & 1 deletion legacy-terrain-v1/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
archivesBaseName = 'legacy-terrain-v1'
version = getSubprojectVersion(project, '1.0.4')
version = getSubprojectVersion(project, '1.0.5')

moduleDependencies(project, 'legacy-api-base')
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,21 @@ protected void generateCarvers(int chunkX, int chunkZ, byte[] tiles, Biome[] bio
* @param x the block x position to spawn the player at.
* @param z the block z position to spawn the player at.
* @return whether the player is allowed to spawn here.
* @since 1.0.4
*/
public boolean isValidSpawnPos(int x, int z) {
int surfaceTile = this.level.method_152(x, z);
return surfaceTile == Tile.SAND.id;
}

/**
* @return the minimum y value at which the player can spawn naturally.
* @since 1.0.5
*/
public int getMinSpawnY() {
return 63;
}

@Override
public Chunk loadChunk(int x, int z) {
return this.getChunk(x, z);
Expand Down Expand Up @@ -116,5 +125,4 @@ public final boolean method_1801() {
public final boolean method_1805() {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@
* Because a certain way they implemented cancellable head injects is very annoying.
* And messing with priorities didn't fix it.
*/
public interface InternalLevelSourceSetter {
public interface InternalLevelSourceAccess {
/**
* Sets the internal api level source field on the class implementing this (i.e. Dimension).
* @param source the level source.
* @return the given source.
*/
LevelSource setInternalLevelSource(LevelSource source);

/**
* Much much much more "impl" than the above method.
* @return the internal api level source.
*/
LevelSource getInternalLevelSource();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import io.github.minecraftcursedlegacy.api.terrain.ChunkGenerator;
import io.github.minecraftcursedlegacy.impl.terrain.InternalLevelSourceSetter;
import io.github.minecraftcursedlegacy.impl.terrain.InternalLevelSourceAccess;
import net.minecraft.level.dimension.Dimension;
import net.minecraft.level.source.LevelSource;

@Mixin(Dimension.class)
public class MixinDimension implements InternalLevelSourceSetter {
public class MixinDimension implements InternalLevelSourceAccess {
private LevelSource api_level_source;

@Inject(at = @At("HEAD"), method = "method_1770", cancellable = true)
Expand All @@ -54,4 +54,9 @@ private void onCreateLevelSource(CallbackInfoReturnable<LevelSource> info) {
public LevelSource setInternalLevelSource(LevelSource source) {
return this.api_level_source = source;
}

@Override
public LevelSource getInternalLevelSource() {
return this.api_level_source;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2020 The Cursed Legacy Team.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package io.github.minecraftcursedlegacy.mixin.terrain;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

import io.github.minecraftcursedlegacy.api.terrain.ChunkGenerator;
import io.github.minecraftcursedlegacy.impl.terrain.InternalLevelSourceAccess;
import net.minecraft.level.Level;
import net.minecraft.level.source.LevelSource;

@Mixin(Level.class)
public class MixinLevel {
@ModifyConstant(constant = @Constant(intValue = 63), method = "method_152")
public int alterMinY(int original) {
Level self = (Level) (Object) this;
LevelSource cg = ((InternalLevelSourceAccess) self.dimension).getInternalLevelSource();

if (cg instanceof ChunkGenerator) {
return ((ChunkGenerator) cg).getMinSpawnY();
}

return original;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"mixins": [
"MixinBiome",
"MixinDimension",
"MixinLevel",
"MixinNetherLevelSource",
"MixinOverworldLevelSource"
],
Expand Down
2 changes: 1 addition & 1 deletion legacy-worldtypes-v1/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
archivesBaseName = 'legacy-worldtypes-v1'
version = getSubprojectVersion(project, '1.0.4')
version = getSubprojectVersion(project, '1.0.5')

moduleDependencies(project, 'legacy-api-base', 'legacy-attached-data-v1', 'legacy-terrain-v1', 'legacy-translations-v0')
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

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

if (type != WorldType.DEFAULT) { // only mess with non default in case another mod wants to mixin here for some reason
info.setReturnValue(((InternalLevelSourceSetter) this).setInternalLevelSource( // set the custom chunk generator
info.setReturnValue(((InternalLevelSourceAccess) this).setInternalLevelSource( // set the custom chunk generator
type.createChunkGenerator(self.level, data.getOrCreateLoadedData(type.storesAdditionalData()))
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ protected void buildSurface(int chunkX, int chunkZ, byte[] tiles, Biome[] biomes
this.surface.buildSurface(chunkX, chunkZ, tiles, biomes);
}

@Override
public int getMinSpawnY() {
return 67;
}

@Override
public boolean isValidSpawnPos(int x, int z) {
int surfaceTile = this.level.method_152(x, z);
Expand Down

0 comments on commit fc63d53

Please sign in to comment.