1
0
Fork 0

Spawn players at the configured location

This commit is contained in:
Ryan Fox (flewkey) 2020-01-18 20:00:24 +00:00 committed by Ryan Fox
parent c833b625f2
commit 7b66818b79
Signed by: flewkey
GPG Key ID: 94F56ADFD848851E
3 changed files with 53 additions and 0 deletions

View File

@ -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.
}
}

View File

@ -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();
}
}
}

View File

@ -4,6 +4,8 @@
"compatibilityLevel": "JAVA_8",
"server": [
"MixinGameModeCommand",
"MixinPlayerEntity",
"MixinServerPlayerEntity",
"MixinTntBlock",
"MixinTntEntity"
],