From c5e8f1cc5489caacdf89a7f75d70e98f1049979d Mon Sep 17 00:00:00 2001 From: Zontreck Date: Tue, 4 Oct 2022 03:54:34 -0700 Subject: [PATCH] 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 --- build.gradle | 4 +- .../zontreck/otemod/commands/FlyCommand.java | 8 ---- .../zontreck/otemod/commands/HomeCommand.java | 48 ++++--------------- .../otemod/configs/PlayerFlyCache.java | 22 +++++++++ src/main/resources/META-INF/mods.toml | 2 +- 5 files changed, 35 insertions(+), 49 deletions(-) create mode 100644 src/main/java/dev/zontreck/otemod/configs/PlayerFlyCache.java diff --git a/build.gradle b/build.gradle index edb6b79..3135fe4 100644 --- a/build.gradle +++ b/build.gradle @@ -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", diff --git a/src/main/java/dev/zontreck/otemod/commands/FlyCommand.java b/src/main/java/dev/zontreck/otemod/commands/FlyCommand.java index 185b0b8..1dd2014 100644 --- a/src/main/java/dev/zontreck/otemod/commands/FlyCommand.java +++ b/src/main/java/dev/zontreck/otemod/commands/FlyCommand.java @@ -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; diff --git a/src/main/java/dev/zontreck/otemod/commands/HomeCommand.java b/src/main/java/dev/zontreck/otemod/commands/HomeCommand.java index fab86c1..28f8df8 100644 --- a/src/main/java/dev/zontreck/otemod/commands/HomeCommand.java +++ b/src/main/java/dev/zontreck/otemod/commands/HomeCommand.java @@ -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); } }); diff --git a/src/main/java/dev/zontreck/otemod/configs/PlayerFlyCache.java b/src/main/java/dev/zontreck/otemod/configs/PlayerFlyCache.java new file mode 100644 index 0000000..5ae9aec --- /dev/null +++ b/src/main/java/dev/zontreck/otemod/configs/PlayerFlyCache.java @@ -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){ + + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index aec04e3..f1032ed 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -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/