diff --git a/src/main/java/party/_2a03/mc/mixin/MixinPlayerEntity.java b/src/main/java/party/_2a03/mc/mixin/MixinPlayerEntity.java new file mode 100644 index 0000000..2118ca1 --- /dev/null +++ b/src/main/java/party/_2a03/mc/mixin/MixinPlayerEntity.java @@ -0,0 +1,25 @@ +package party._2a03.mc.mixin; + +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.Mixin; +import party._2a03.mc.server.Config; +import party._2a03.mc.server.PlayerPosition; + +@Mixin(PlayerEntity.class) +public abstract class MixinPlayerEntity extends LivingEntity { + public MixinPlayerEntity() { + super(null, null); + } + + @Inject(method = "getSpawnPosition", at = @At("RETURN"), cancellable = true) + public void OnGetSpawnPosition(CallbackInfoReturnable cir) { + PlayerPosition position = new PlayerPosition(Config.getData("spawn")); + if (position.dimensiontype == this.dimension) + cir.setReturnValue(null); // Don't override the world spawn. + } +} diff --git a/src/main/java/party/_2a03/mc/mixin/MixinServerPlayerEntity.java b/src/main/java/party/_2a03/mc/mixin/MixinServerPlayerEntity.java new file mode 100644 index 0000000..7c829ae --- /dev/null +++ b/src/main/java/party/_2a03/mc/mixin/MixinServerPlayerEntity.java @@ -0,0 +1,26 @@ +package party._2a03.mc.mixin; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.network.ServerPlayerEntity; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.Mixin; +import party._2a03.mc.server.Config; +import party._2a03.mc.server.PlayerPosition; + +@Mixin(ServerPlayerEntity.class) +public abstract class MixinServerPlayerEntity extends PlayerEntity { + public MixinServerPlayerEntity() { + super(null, null); + } + + @Inject(method = "moveToSpawn", at = @At("HEAD"), cancellable = true) + private void OnServerPlayerSpawn(CallbackInfo ci) { + PlayerPosition position = new PlayerPosition(Config.getData("spawn")); + if (position.dimensiontype == this.dimension) { + this.setPositionAndAngles(position.x, position.y, position.z, position.yaw, position.pitch); + ci.cancel(); + } + } +} diff --git a/src/main/resources/minecraft-tweaks-2a03.mixins.json b/src/main/resources/minecraft-tweaks-2a03.mixins.json index bd96e48..0773a7c 100644 --- a/src/main/resources/minecraft-tweaks-2a03.mixins.json +++ b/src/main/resources/minecraft-tweaks-2a03.mixins.json @@ -4,6 +4,8 @@ "compatibilityLevel": "JAVA_8", "server": [ "MixinGameModeCommand", + "MixinPlayerEntity", + "MixinServerPlayerEntity", "MixinTntBlock", "MixinTntEntity" ],