Spawn players at the configured location
This commit is contained in:
parent
c833b625f2
commit
7b66818b79
25
src/main/java/party/_2a03/mc/mixin/MixinPlayerEntity.java
Normal file
25
src/main/java/party/_2a03/mc/mixin/MixinPlayerEntity.java
Normal 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.
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"server": [
|
||||
"MixinGameModeCommand",
|
||||
"MixinPlayerEntity",
|
||||
"MixinServerPlayerEntity",
|
||||
"MixinTntBlock",
|
||||
"MixinTntEntity"
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user