Skip to content

Commit

Permalink
fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Mar 22, 2023
1 parent 8442b26 commit 71af224
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 42 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repositories {
maven { url "https://maven.nucleoid.xyz" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url "https://ladysnake.jfrog.io/artifactory/mods" }
maven { url "https://jitpack.io" }
}

dependencies {
Expand All @@ -29,7 +30,7 @@ dependencies {
include "dev.onyxstudios.cardinal-components-api:cardinal-components-world:${project.cca}"
include "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cca}"

modImplementation(files("libs/fantasy-${project.fantasy}.jar"))
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}")
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.parallel = true
# Mod Properties
maven_group = ru.pinkgoosik
archives_base_name = skylands
mod_version = 0.3.2
mod_version = 0.3.4

# Dependencies | Check these on https://fabricmc.net/develop
minecraft_version = 1.19.4
Expand All @@ -16,7 +16,7 @@ fabric_api = 0.76.0+1.19.4
# https://github.com/OnyxStudios/Cardinal-Components-API/releases
cca = 5.1.0
# https://github.com/NucleoidMC/fantasy/releases
fantasy = 0.4.10+1.19.4
fantasy = 15b00d289f
# https://github.com/Patbox/TextPlaceholderAPI/releases
placeholder_api = 2.0.0-rc.1+1.19.3
# https://github.com/NucleoidMC/Server-Translations/releases
Expand Down
Binary file removed libs/fantasy-0.4.10+1.19.4-sources.jar
Binary file not shown.
Binary file removed libs/fantasy-0.4.10+1.19.4.jar
Binary file not shown.
5 changes: 1 addition & 4 deletions src/main/java/skylands/command/BanCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.TeleportTarget;
import skylands.logic.Member;
import skylands.logic.Skylands;
import skylands.util.Texts;
Expand Down Expand Up @@ -82,7 +79,7 @@ static void ban(ServerPlayerEntity player, ServerPlayerEntity banned) {
Worlds.getIsland(banned.getWorld()).ifPresent(isl -> {
if(isl.owner.uuid.equals(island.owner.uuid)) {
banned.sendMessage(Texts.prefixed("message.skylands.hub_visit"));
FabricDimensions.teleport(banned, Skylands.instance.server.getOverworld(), new TeleportTarget(Skylands.instance.hub.pos, new Vec3d(0, 0, 0), 0, 0));
Skylands.instance.hub.visit(player);
}
});
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/skylands/command/CreateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ static void run(ServerPlayerEntity player) {
}
else {
Island island = islands.create(player);
island.onFirstLoad();
if(Skylands.config.teleportAfterIslandCreation) {
island.visitAsMember(player);
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/skylands/command/HubCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import com.mojang.brigadier.CommandDispatcher;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.TeleportTarget;
import skylands.logic.Skylands;
import skylands.util.Texts;

Expand Down Expand Up @@ -43,7 +41,7 @@ static void init(CommandDispatcher<ServerCommandSource> dispatcher) {

static void visit(ServerPlayerEntity player, MinecraftServer server) {
player.sendMessage(Texts.prefixed("message.skylands.hub_visit"));
FabricDimensions.teleport(player, server.getOverworld(), new TeleportTarget(Skylands.instance.hub.pos, new Vec3d(0, 0, 0), 0, 0));
Skylands.instance.hub.visit(player);
}

static void setPos(BlockPos pos, ServerCommandSource source) {
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/skylands/command/KickCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import com.mojang.brigadier.CommandDispatcher;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.TeleportTarget;
import skylands.logic.Skylands;
import skylands.util.Texts;
import skylands.util.Worlds;
Expand Down Expand Up @@ -45,7 +42,7 @@ static void run(ServerPlayerEntity player, ServerPlayerEntity kicked) {

kicked.sendMessage(Texts.prefixed("message.skylands.kick_visitor.kick", map -> map.put("%owner%", player.getName().getString())));
kicked.sendMessage(Texts.prefixed("message.skylands.hub_visit"));
FabricDimensions.teleport(kicked, Skylands.instance.server.getOverworld(), new TeleportTarget(Skylands.instance.hub.pos, new Vec3d(0, 0, 0), 0, 0));
Skylands.instance.hub.visit(kicked);
}
else {
player.sendMessage(Texts.prefixed("message.skylands.kick_visitor.fail", map -> map.put("%player%", kicked.getName().getString())));
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/skylands/event/PlayerConnectEvent.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package skylands.event;

import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.stat.Stats;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.TeleportTarget;
import skylands.logic.Island;
import skylands.logic.Member;
import skylands.logic.Skylands;
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 @@ -49,7 +47,8 @@ public static void onJoin(MinecraftServer server, ServerPlayerEntity player) {
if(!island.isMember(player) && island.isBanned(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"));
FabricDimensions.teleport(player, server.getOverworld(), new TeleportTarget(Skylands.instance.hub.pos, new Vec3d(0, 0, 0), 0, 0));
var pos = Skylands.instance.hub.pos;
player.teleport(server.getOverworld(), pos.getX(), pos.getY(), pos.getZ(), Set.of(), 0, 0);
}
});

Expand Down
1 change: 0 additions & 1 deletion src/main/java/skylands/event/ServerStartEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.MinecraftServer;
import net.minecraft.text.Text;
import skylands.logic.Skylands;

public class ServerStartEvent {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/skylands/logic/Hub.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package skylands.logic;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.Vec3d;

import java.util.Set;

public class Hub {
public Vec3d pos = Skylands.config.defaultHubPos;
public boolean hasProtection = Skylands.config.hubProtectedByDefault;
Expand All @@ -24,4 +27,8 @@ public void writeToNbt(NbtCompound nbt) {
hubNbt.putBoolean("hasProtection", this.hasProtection);
nbt.put("hub", hubNbt);
}

public void visit(PlayerEntity player) {
player.teleport(Skylands.instance.server.getOverworld(), pos.getX(), pos.getY(), pos.getZ(), Set.of(), 0, 0);
}
}
27 changes: 17 additions & 10 deletions src/main/java/skylands/logic/Island.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package skylands.logic;

import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.minecraft.block.Block;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
Expand All @@ -16,7 +15,6 @@
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.RandomSeed;
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 @@ -29,10 +27,7 @@
import xyz.nucleoid.fantasy.RuntimeWorldHandle;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.*;

public class Island {
MinecraftServer server = Skylands.instance.server;
Expand All @@ -49,7 +44,10 @@ public class Island {
public Vec3d visitsPos = Skylands.config.defaultVisitsPos;
public boolean hasNether = false;
public long seed = 0L;

/**
* Mark indicates that this island was just created and wasn't visited yet
*/
boolean freshCreated = false;
public Instant created = Instant.now();

public Island(UUID uuid, String name) {
Expand All @@ -70,6 +68,7 @@ public static Island fromNbt(NbtCompound nbt) {
island.created = Instant.parse(nbt.getString("created"));
island.locked = nbt.getBoolean("locked");
island.seed = nbt.getLong("seed");
island.freshCreated = nbt.getBoolean("freshCreated");

var spawnPosNbt = nbt.getCompound("spawnPos");
double spawnPosX = spawnPosNbt.getDouble("x");
Expand Down Expand Up @@ -107,6 +106,7 @@ public NbtCompound toNbt() {
nbt.putString("created", this.created.toString());
nbt.putBoolean("locked", this.locked);
nbt.putLong("seed", this.seed);
nbt.putBoolean("freshCreated", this.freshCreated);

NbtCompound spawnPosNbt = new NbtCompound();
spawnPosNbt.putDouble("x", this.spawnPos.getX());
Expand Down Expand Up @@ -242,13 +242,20 @@ public ServerWorld getWorld() {

public void visitAsMember(PlayerEntity player) {
ServerWorld world = this.getWorld();
FabricDimensions.teleport(player, world, new TeleportTarget(this.spawnPos, new Vec3d(0, 0, 0), 0, 0));
player.teleport(world, this.spawnPos.getX(), this.spawnPos.getY(), this.spawnPos.getZ(), Set.of(), 0, 0);
if (this.freshCreated) {
this.onFirstLoad();
this.freshCreated = false;
}
}

public void visitAsVisitor(PlayerEntity player) {
ServerWorld world = this.getWorld();
FabricDimensions.teleport(player, world, new TeleportTarget(this.visitsPos, new Vec3d(0, 0, 0), 0, 0));

player.teleport(world, this.visitsPos.getX(), this.visitsPos.getY(), this.visitsPos.getZ(), Set.of(), 0, 0);
if (this.freshCreated) {
this.onFirstLoad();
this.freshCreated = false;
}
Players.get(this.owner.name).ifPresent(owner -> {
if(!player.getUuid().equals(owner.getUuid())) {
owner.sendMessage(Texts.prefixed("message.skylands.island_visit.visit", map -> map.put("%visitor%", player.getName().getString())));
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/skylands/logic/IslandStuck.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.jetbrains.annotations.Nullable;
import skylands.SkylandsMod;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -17,6 +19,7 @@ public Island create(PlayerEntity player) {
if(island.owner.uuid.equals(player.getUuid())) return island;
}
var island = new Island(player);
island.freshCreated = true;
this.stuck.add(island);
return island;
}
Expand Down Expand Up @@ -71,19 +74,25 @@ public boolean hasIsland(@Nullable UUID playerUuid) {
public void readFromNbt(NbtCompound nbt) {
NbtCompound islandStuckNbt = nbt.getCompound("islandStuck");
int size = islandStuckNbt.getInt("size");
Instant inst = Instant.now();
for(int i = 0; i < size; i++) {
NbtCompound islandNbt = islandStuckNbt.getCompound(String.valueOf(i));
Island island = Island.fromNbt(islandNbt);
if(!this.hasIsland(island.owner.uuid)) {
this.stuck.add(island);
SkylandsMod.LOGGER.info("Loading " + island.owner.name + "'s Island...");
island.getWorld();

if(island.hasNether) {
SkylandsMod.LOGGER.info("Loading " + island.owner.name + "'s Nether...");
island.getNether();
}
}
}
if (stuck.size() > 0) {
SkylandsMod.LOGGER.info("All Islands got successfully loaded in " + ChronoUnit.MILLIS.between(inst, Instant.now()) + " ms!");
}

}

public void writeToNbt(NbtCompound nbt) {
Expand Down
31 changes: 30 additions & 1 deletion src/main/java/skylands/mixin/entity/ServerPlayerEntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,45 @@
package skylands.mixin.entity;

import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
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.WorldProtection;
import skylands.util.Worlds;

import java.util.Set;

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

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

@Inject(method = "tick", at = @At("TAIL"))
void tick(CallbackInfo ci) {
ServerPlayerEntity player = ServerPlayerEntity.class.cast(this);

if(!WorldProtection.canModify(world, player)) {
if(player.getPos().getY() < -74) {
Worlds.getIsland(world).ifPresentOrElse(island -> {
var pos = island.spawnPos;
player.teleport(island.getWorld(), pos.getX(), pos.getY(), pos.getZ(), Set.of(), 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;"))
public RegistryKey<World> moveToWorld_redirectRegistryKey(ServerWorld instance) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package skylands.mixin.world.protection;

import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.TeleportTarget;
import net.minecraft.world.World;
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.callback.CallbackInfoReturnable;
import skylands.logic.Skylands;
import skylands.util.Texts;
import skylands.util.WorldProtection;

Expand All @@ -32,12 +28,6 @@ void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> c
if(self instanceof PlayerEntity player) {
if(!WorldProtection.canModify(world, player)) {
player.sendMessage(Texts.prefixed("message.skylands.world_protection.damage_take"), true);
if(source.equals(world.getDamageSources().outOfWorld())) {
player.sendMessage(Texts.prefixed("message.skylands.hub_visit"));
FabricDimensions.teleport(player, world.getServer().getOverworld(), new TeleportTarget(Skylands.instance.hub.pos, new Vec3d(0, 0, 0), 0, 0));
// var pos = island.get().spawnPos;
// player.teleport(pos.getX(), pos.getY(), pos.getZ());
}
cir.setReturnValue(false);
}
}
Expand Down
Binary file modified src/main/resources/data/skylands/structures/nether_island.nbt
Binary file not shown.
Binary file modified src/main/resources/data/skylands/structures/start_island.nbt
Binary file not shown.

0 comments on commit 71af224

Please sign in to comment.