Fix a small bug with the home command where your rotation was set wrong

Fixes an issue where changing dimensions via /home would reset the flight ability
This commit is contained in:
Zontreck 2022-10-04 03:54:34 -07:00
parent 883d41ecc9
commit c5e8f1cc54
5 changed files with 35 additions and 49 deletions

View file

@ -7,7 +7,7 @@ plugins {
version = '1.2.3'
version = '1.3.0'
group = 'dev.zontreck.otemod' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'otemod'
@ -156,7 +156,7 @@ jar {
attributes([
"Specification-Title" : "otemod",
"Specification-Vendor" : "Zontreck",
"Specification-Version" : "1.2.3", // We are version 1 of ourselves
"Specification-Version" : "1.3.0", // We are version 1 of ourselves
"Implementation-Title" : project.name,
"Implementation-Version" : project.jar.archiveVersion,
"Implementation-Vendor" : "Zontreck",

View file

@ -1,21 +1,13 @@
package dev.zontreck.otemod.commands;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.math.Vector3d;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatColor;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.contents.TranslatableContents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.server.command.TextComponentHelper;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;

View file

@ -16,6 +16,7 @@ import com.mojang.math.Vector3d;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatColor;
import dev.zontreck.otemod.configs.PlayerFlyCache;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.contents.TranslatableContents;
@ -124,12 +125,14 @@ public class HomeCommand {
MobEffectInstance inst = new MobEffectInstance(MobEffects.DARKNESS, 10000, 3, true, true);
MobEffectInstance regen = new MobEffectInstance(MobEffects.REGENERATION, 5000, 1, true, true);
MobEffectInstance inst = new MobEffectInstance(MobEffects.DARKNESS, 200, 1, true, true);
MobEffectInstance regen = new MobEffectInstance(MobEffects.REGENERATION, 200, 1, true, true);
MobEffectInstance invul = new MobEffectInstance(MobEffects.LEVITATION, 200, 1, true, true);
p.addEffect(inst);
p.addEffect(regen);
p.addEffect(invul); // ensure the player can't fall into lava in the short time we are not in control (if the player was silly enough to make a home above lava!!!)
// Send boss bar
@ -147,50 +150,19 @@ public class HomeCommand {
// TODO Auto-generated catch block
e1.printStackTrace();
}
boolean dimensionNeedsChanging = false;
if(!f_p.level.dimension().location().getNamespace().equals(f_dim.dimension().location().getNamespace())) dimensionNeedsChanging=true;
if(!f_p.level.dimension().location().getPath().equals(f_dim.dimension().location().getPath())) dimensionNeedsChanging=true;
f_p.teleportTo(f_dim, f_pos.x, f_pos.y, f_pos.z, f_rot.x, f_rot.y);
if(!dimensionNeedsChanging){
}else {
// Get dimension then change dimension
f_p.server.execute(new Runnable() {
public void run()
{
PlayerFlyCache c = PlayerFlyCache.cachePlayer(f_p);
f_p.teleportTo(f_dim, f_pos.x, f_pos.y, f_pos.z, f_rot.y, f_rot.x);
f_p.changeDimension(f_dim);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
f_p.setPos(f_pos);
f_p.setXRot(f_rot.x);
f_p.setYRot(f_rot.y);
}
});
}
try {
Thread.sleep(2000);
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
f_p.server.execute(new Runnable() {
public void run()
{
c.Assert(f_p);
f_p.removeEffect(MobEffects.DARKNESS);
f_p.removeEffect(MobEffects.REGENERATION);
}
});
f_p.setPos(f_pos);
}
});

View file

@ -0,0 +1,22 @@
package dev.zontreck.otemod.configs;
import net.minecraft.server.level.ServerPlayer;
public class PlayerFlyCache
{
public boolean FlyEnabled;
public boolean Flying;
public static PlayerFlyCache cachePlayer(ServerPlayer play){
PlayerFlyCache cache = new PlayerFlyCache();
cache.FlyEnabled = play.getAbilities().mayfly;
cache.Flying = play.getAbilities().flying;
play.onUpdateAbilities();
return cache;
}
public void Assert(ServerPlayer play){
}
}

View file

@ -19,7 +19,7 @@ modId="otemod" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build
version="1.2.3" #mandatory
version="1.3.0" #mandatory
# A display name for the mod
displayName="OTEMod Resources" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/