Skip to content

Commit

Permalink
backport to 1.19.2
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Mar 29, 2023
1 parent 87a33b0 commit 73b4abc
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 55 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ dependencies {
include "dev.onyxstudios.cardinal-components-api:cardinal-components-world:${project.cca}"
include "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cca}"

modImplementation include("com.github.tyap-lyap:fantasy:${project.fantasy}")
// modImplementation include("xyz.nucleoid:fantasy:${project.fantasy}")
// modImplementation include("com.github.tyap-lyap:fantasy:${project.fantasy}")
modImplementation include("xyz.nucleoid:fantasy:${project.fantasy}")
modImplementation include("eu.pb4:placeholder-api:${project.placeholder_api}")
modImplementation include("xyz.nucleoid:server-translations-api:${project.server_translations_api}")
modImplementation include("fr.catcore:server-translations-api:${project.server_translations_api}")
modImplementation include("me.lucko:fabric-permissions-api:0.2-SNAPSHOT")
}

Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ archives_base_name = skylands
mod_version = 0.3.6

# Dependencies | Check these on https://fabricmc.net/develop
minecraft_version = 1.19.4
yarn_mappings = 1.19.4+build.1
fabric_loader = 0.14.17
fabric_api = 0.76.0+1.19.4
minecraft_version = 1.19.2
yarn_mappings = 1.19.2+build.28
fabric_loader = 0.14.18
fabric_api = 0.76.0+1.19.2

# https://github.com/OnyxStudios/Cardinal-Components-API/releases
cca = 5.1.0
cca = 5.0.2
# https://github.com/NucleoidMC/fantasy/releases
fantasy = 15b00d289f
fantasy = 0.4.7+1.19.2
# https://github.com/Patbox/TextPlaceholderAPI/releases
placeholder_api = 2.0.0-rc.1+1.19.3
# https://github.com/NucleoidMC/Server-Translations/releases
server_translations_api = 2.0.0-beta.2+1.19.4-pre2
server_translations_api = 1.4.18+1.19.2
2 changes: 1 addition & 1 deletion src/main/java/skylands/api/SkylandsAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import skylands.SkylandsMod;
import skylands.logic.Island;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/skylands/event/PlayerConnectEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
import net.minecraft.world.World;
import skylands.logic.Member;
import skylands.logic.Skylands;
import skylands.util.TeleportUtil;
import skylands.util.Texts;
import skylands.util.UpdateChecker;
import skylands.util.Worlds;

import java.util.Set;

@SuppressWarnings("unused")
public class PlayerConnectEvent {

Expand Down Expand Up @@ -45,7 +44,7 @@ public static void onJoin(MinecraftServer server, ServerPlayerEntity player) {
player.sendMessage(Texts.prefixed("message.skylands.ban_player.ban", map -> map.put("%owner%", island.owner.name)));
player.sendMessage(Texts.prefixed("message.skylands.hub_visit"));
var pos = Skylands.instance.hub.pos;
player.teleport(server.getOverworld(), pos.getX(), pos.getY(), pos.getZ(), Set.of(), 0, 0);
TeleportUtil.teleport(player, server.getOverworld(), pos.getX(), pos.getY(), pos.getZ(), 0, 0);
}
});

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/skylands/logic/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.Vec3d;
import skylands.api.SkylandsAPI;

import java.util.Set;
import skylands.util.TeleportUtil;

public class Hub {
public Vec3d pos = Skylands.config.defaultHubPos.toVec();
Expand All @@ -31,7 +31,7 @@ public void writeToNbt(NbtCompound nbt) {

public void visit(PlayerEntity player) {
var world = Skylands.getServer().getOverworld();
player.teleport(world, pos.getX(), pos.getY(), pos.getZ(), Set.of(), Skylands.config.defaultHubPos.yaw, Skylands.config.defaultHubPos.pitch);
TeleportUtil.teleport((ServerPlayerEntity)player, world, pos.getX(), pos.getY(), pos.getZ(), Skylands.config.defaultHubPos.yaw, Skylands.config.defaultHubPos.pitch);
SkylandsAPI.ON_HUB_VISIT.invoker().invoke(player, world);
}
}
25 changes: 16 additions & 9 deletions src/main/java/skylands/logic/Island.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
package skylands.logic;

import com.mojang.serialization.Lifecycle;
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.minecraft.block.Block;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntryList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.structure.StructurePlacementData;
import net.minecraft.structure.StructureSet;
import net.minecraft.structure.StructureTemplate;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.Identifier;
import net.minecraft.util.WorldSavePath;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.RandomSeed;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.SimpleRegistry;
import net.minecraft.world.Difficulty;
import net.minecraft.world.TeleportTarget;
import net.minecraft.world.biome.BiomeKeys;
import net.minecraft.world.dimension.DimensionTypes;
import net.minecraft.world.gen.chunk.FlatChunkGenerator;
Expand All @@ -25,6 +30,7 @@
import skylands.SkylandsMod;
import skylands.api.SkylandsAPI;
import skylands.util.Players;
import skylands.util.TeleportUtil;
import skylands.util.Texts;
import xyz.nucleoid.fantasy.Fantasy;
import xyz.nucleoid.fantasy.RuntimeWorldConfig;
Expand All @@ -35,6 +41,7 @@
import java.util.*;

public class Island {
public static final Registry<StructureSet> EMPTY_STRUCTURE_REGISTRY = new SimpleRegistry<>(Registry.STRUCTURE_SET_KEY, Lifecycle.stable(), (x) -> null).freeze();
MinecraftServer server = Skylands.instance.server;
Skylands skylands = Skylands.instance;
Fantasy fantasy = Skylands.instance.fantasy;
Expand Down Expand Up @@ -209,9 +216,9 @@ public RuntimeWorldHandle getHandler() {
}

private RuntimeWorldConfig createIslandConfig() {
var biome = this.server.getRegistryManager().get(RegistryKeys.BIOME).getEntry(this.server.getRegistryManager().get(RegistryKeys.BIOME).getOrThrow(BiomeKeys.PLAINS));
FlatChunkGeneratorConfig flat = new FlatChunkGeneratorConfig(Optional.of(RegistryEntryList.of()), biome, List.of());
FlatChunkGenerator generator = new FlatChunkGenerator(flat);
FlatChunkGeneratorConfig flat = new FlatChunkGeneratorConfig(Optional.empty(), BuiltinRegistries.BIOME);
flat.setBiome(this.server.getRegistryManager().get(Registry.BIOME_KEY).getOrCreateEntry(BiomeKeys.PLAINS));
FlatChunkGenerator generator = new FlatChunkGenerator(EMPTY_STRUCTURE_REGISTRY, flat);

return new RuntimeWorldConfig()
.setDimensionType(DimensionTypes.OVERWORLD)
Expand Down Expand Up @@ -247,9 +254,9 @@ void copyNetherTemplate() {
}

private RuntimeWorldConfig createNetherConfig() {
var biome = this.server.getRegistryManager().get(RegistryKeys.BIOME).getEntry(this.server.getRegistryManager().get(RegistryKeys.BIOME).getOrThrow(BiomeKeys.NETHER_WASTES));
FlatChunkGeneratorConfig flat = new FlatChunkGeneratorConfig(Optional.of(RegistryEntryList.of()), biome, List.of());
FlatChunkGenerator generator = new FlatChunkGenerator(flat);
FlatChunkGeneratorConfig flat = new FlatChunkGeneratorConfig(Optional.empty(), BuiltinRegistries.BIOME);
flat.setBiome(this.server.getRegistryManager().get(Registry.BIOME_KEY).getOrCreateEntry(BiomeKeys.NETHER_WASTES));
FlatChunkGenerator generator = new FlatChunkGenerator(EMPTY_STRUCTURE_REGISTRY, flat);

return new RuntimeWorldConfig()
.setDimensionType(DimensionTypes.THE_NETHER)
Expand Down Expand Up @@ -281,7 +288,7 @@ public ServerWorld getWorld() {

public void visit(PlayerEntity player, Vec3d pos, float yaw, float pitch) {
ServerWorld world = this.getWorld();
player.teleport(world, pos.getX(), pos.getY(), pos.getZ(), Set.of(), yaw, pitch);
TeleportUtil.teleport((ServerPlayerEntity)player, world, pos.getX(), pos.getY(), pos.getZ(), yaw, pitch);

if(!isMember(player)) {
Players.get(this.owner.name).ifPresent(owner -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skylands.mixin.block.entity;

import net.minecraft.block.entity.EndGatewayBlockEntity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -11,7 +11,7 @@
@Mixin(EndGatewayBlockEntity.class)
public class EndGatewayBlockEntityMixin {

@Redirect(method = "tryTeleportingEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getRegistryKey()Lnet/minecraft/registry/RegistryKey;"))
@Redirect(method = "tryTeleportingEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getRegistryKey()Lnet/minecraft/util/registry/RegistryKey;"))
private static RegistryKey<World> tryTeleportingEntity_redirectRegistryKey(World instance) {
return Worlds.redirect(instance.getRegistryKey());
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/skylands/mixin/entity/EntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package skylands.mixin.entity;

import net.minecraft.entity.Entity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -37,18 +37,18 @@ public RegistryKey<World> tickPortal_modifyRegistryKey(RegistryKey<World> instan
return instance;
}

@Redirect(method = "getTeleportTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getRegistryKey()Lnet/minecraft/registry/RegistryKey;"))
@Redirect(method = "getTeleportTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getRegistryKey()Lnet/minecraft/util/registry/RegistryKey;"))
public RegistryKey<World> getTeleportTarget_redirectRegistryKey0(ServerWorld instance) {
return Worlds.redirect(instance.getRegistryKey());
}

@Redirect(method = "getTeleportTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getRegistryKey()Lnet/minecraft/registry/RegistryKey;"))
@Redirect(method = "getTeleportTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getRegistryKey()Lnet/minecraft/util/registry/RegistryKey;"))
public RegistryKey<World> getTeleportTarget_redirectRegistryKey(World instance) {
return Worlds.redirect(instance.getRegistryKey());
}


@Redirect(method = "moveToWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getRegistryKey()Lnet/minecraft/registry/RegistryKey;", ordinal = 0))
@Redirect(method = "moveToWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getRegistryKey()Lnet/minecraft/util/registry/RegistryKey;", ordinal = 0))
public RegistryKey<World> moveToWorld_redirectRegistryKey(ServerWorld instance) {
return Worlds.redirect(instance.getRegistryKey());
}
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/skylands/mixin/entity/ServerPlayerEntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
package skylands.mixin.entity;

import com.mojang.authlib.GameProfile;
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.network.encryption.PlayerPublicKey;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.TeleportTarget;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import skylands.logic.Skylands;
import skylands.util.TeleportUtil;
import skylands.util.WorldProtection;
import skylands.util.Worlds;

import java.util.Set;

@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixin extends PlayerEntity {

public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile gameProfile) {
super(world, pos, yaw, gameProfile);

public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile gameProfile, @Nullable PlayerPublicKey publicKey) {
super(world, pos, yaw, gameProfile, publicKey);
}

@Inject(method = "tick", at = @At("TAIL"))
Expand All @@ -33,25 +38,25 @@ void tick(CallbackInfo ci) {
if(player.getPos().getY() < world.getDimension().minY() - 10) {
Worlds.getIsland(world).ifPresentOrElse(island -> {
var pos = island.spawnPos;
player.teleport(island.getWorld(), pos.getX(), pos.getY(), pos.getZ(), Set.of(), 0, 0);
TeleportUtil.teleport(player, island.getWorld(), pos.getX(), pos.getY(), pos.getZ(), 0, 0);
}, () -> {
Skylands.instance.hub.visit(player);
});
}
}
}

@Redirect(method = "moveToWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getRegistryKey()Lnet/minecraft/registry/RegistryKey;"))
@Redirect(method = "moveToWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getRegistryKey()Lnet/minecraft/util/registry/RegistryKey;"))
public RegistryKey<World> moveToWorld_redirectRegistryKey(ServerWorld instance) {
return Worlds.redirect(instance.getRegistryKey());
}

@Redirect(method = "getTeleportTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getRegistryKey()Lnet/minecraft/registry/RegistryKey;"))
@Redirect(method = "getTeleportTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getRegistryKey()Lnet/minecraft/util/registry/RegistryKey;"))
public RegistryKey<World> getTeleportTarget_redirectRegistryKey(ServerWorld instance) {
return Worlds.redirect(instance.getRegistryKey());
}

@Redirect(method = "worldChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getRegistryKey()Lnet/minecraft/registry/RegistryKey;"))
@Redirect(method = "worldChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getRegistryKey()Lnet/minecraft/util/registry/RegistryKey;"))
public RegistryKey<World> worldChanged_redirectRegistryKey(ServerWorld instance) {
return Worlds.redirect(instance.getRegistryKey());
}
Expand Down
26 changes: 16 additions & 10 deletions src/main/java/skylands/mixin/world/ServerWorldMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

import com.google.common.collect.ImmutableList;
import net.minecraft.entity.Entity;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.entry.RegistryEntryList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldGenerationProgressListener;
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.server.world.ServerEntityManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.profiler.Profiler;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.village.ZombieSiegeManager;
import net.minecraft.world.MutableWorldProperties;
import net.minecraft.world.StructureWorldAccess;
Expand All @@ -29,6 +28,7 @@
import net.minecraft.world.spawner.PatrolSpawner;
import net.minecraft.world.spawner.PhantomSpawner;
import net.minecraft.world.spawner.Spawner;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
Expand All @@ -37,6 +37,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import skylands.SkylandsMod;
import skylands.logic.Island;

import java.util.List;
import java.util.Optional;
Expand All @@ -50,10 +51,15 @@ public abstract class ServerWorldMixin extends World implements StructureWorldAc
@Shadow @Final private ServerEntityManager<Entity> entityManager;
@Mutable @Shadow @Final private List<Spawner> spawners;

protected ServerWorldMixin(MutableWorldProperties properties, RegistryKey<World> registryRef, DynamicRegistryManager registryManager, RegistryEntry<DimensionType> dimensionEntry, Supplier<Profiler> profiler, boolean isClient, boolean debugWorld, long biomeAccess, int maxChainedNeighborUpdates) {
super(properties, registryRef, registryManager, dimensionEntry, profiler, isClient, debugWorld, biomeAccess, maxChainedNeighborUpdates);
@Shadow
@NotNull
public abstract MinecraftServer getServer();

protected ServerWorldMixin(MutableWorldProperties properties, RegistryKey<World> registryRef, RegistryEntry<DimensionType> dimension, Supplier<Profiler> profiler, boolean isClient, boolean debugWorld, long seed, int maxChainedNeighborUpdates) {
super(properties, registryRef, dimension, profiler, isClient, debugWorld, seed, maxChainedNeighborUpdates);
}


@Inject(method = "<init>", at = @At("TAIL"))
void init(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<World> worldKey, DimensionOptions dimensionOptions, WorldGenerationProgressListener worldGenerationProgressListener, boolean debugWorld, long seed, List<Spawner> spawners, boolean shouldTickTime, CallbackInfo ci) {

Expand All @@ -62,9 +68,9 @@ void init(MinecraftServer server, Executor workerExecutor, LevelStorage.Session
}

if(worldKey.equals(World.OVERWORLD) && server.getFile("hub_template").exists()) {
var biome = server.getRegistryManager().get(RegistryKeys.BIOME).getEntry(server.getRegistryManager().get(RegistryKeys.BIOME).getOrThrow(BiomeKeys.PLAINS));
FlatChunkGeneratorConfig flat = new FlatChunkGeneratorConfig(Optional.of(RegistryEntryList.of()), biome, List.of());
FlatChunkGenerator generator = new FlatChunkGenerator(flat);
FlatChunkGeneratorConfig flat = new FlatChunkGeneratorConfig(Optional.empty(), BuiltinRegistries.BIOME);
flat.setBiome(getServer().getRegistryManager().get(Registry.BIOME_KEY).getOrCreateEntry(BiomeKeys.PLAINS));
FlatChunkGenerator generator = new FlatChunkGenerator(Island.EMPTY_STRUCTURE_REGISTRY, flat);

chunkManager = new ServerChunkManager(
this.toServerWorld(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skylands.mixin.world.protection;

import net.minecraft.block.AbstractButtonBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.ButtonBlock;
import net.minecraft.block.WallMountedBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
Expand All @@ -16,7 +16,7 @@
import skylands.util.Texts;
import skylands.util.WorldProtection;

@Mixin(ButtonBlock.class)
@Mixin(AbstractButtonBlock.class)
public abstract class ButtonMixin extends WallMountedBlock {

public ButtonMixin(Settings settings) {
Expand Down
Loading

0 comments on commit 73b4abc

Please sign in to comment.