[factions-banking] Flight tweaks to be MWAH before I go to bed
Some checks are pending
build / build (21) (push) Waiting to run
Some checks are pending
build / build (21) (push) Waiting to run
This commit is contained in:
parent
d274810ca4
commit
6d14d47e0b
@ -3,11 +3,13 @@ package jesse.keeblarcraft.AttributeMgr.AttributeNodes.FactionNodes;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.core.jmx.Server;
|
||||||
|
|
||||||
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.AbstractNode;
|
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.AbstractNode;
|
||||||
|
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerCommandFlightCallback;
|
||||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerEnteredBaseCallback;
|
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerEnteredBaseCallback;
|
||||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerExitedBaseCallback;
|
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerExitedBaseCallback;
|
||||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerInBaseCallback;
|
import net.minecraft.entity.player.PlayerAbilities;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
@ -16,6 +18,8 @@ import net.minecraft.util.ActionResult;
|
|||||||
public class FactionFlight extends AbstractNode {
|
public class FactionFlight extends AbstractNode {
|
||||||
private final int flightSpeed = 1;
|
private final int flightSpeed = 1;
|
||||||
private ServerPlayerEntity player;
|
private ServerPlayerEntity player;
|
||||||
|
private float SPEED_SCALAR = 40.0f; // The value to scale this correctly to CREATIVE flight is '20.0f' however faction flight is slower than creative intentionally
|
||||||
|
private Boolean canFly = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String GetNodeTitle() {
|
public String GetNodeTitle() {
|
||||||
@ -34,6 +38,40 @@ public class FactionFlight extends AbstractNode {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean ToggleFlight(ServerPlayerEntity player) {
|
||||||
|
// Only bother with flight if the player can fly
|
||||||
|
Boolean isFlying = false;
|
||||||
|
if (canFly) {
|
||||||
|
PlayerAbilities abilities = player.getAbilities();
|
||||||
|
|
||||||
|
// Flight toggle off
|
||||||
|
if (abilities.flying) {
|
||||||
|
// Disable flight
|
||||||
|
abilities.flying = false;
|
||||||
|
abilities.allowFlying = false;
|
||||||
|
abilities.setFlySpeed(0);
|
||||||
|
} else {
|
||||||
|
// Flight toggle on
|
||||||
|
isFlying = true;
|
||||||
|
abilities.allowFlying = true;
|
||||||
|
abilities.setFlySpeed((float) (flightSpeed / SPEED_SCALAR)); // Dividing by 20f yields max clamp value of 0.5 since MC does 0.0-> 1.0 flight. 0.1 flight is too fast!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player.sendAbilitiesUpdate();
|
||||||
|
return isFlying;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetPlayer(ServerPlayerEntity player) {
|
||||||
|
PlayerAbilities abilities = player.getAbilities();
|
||||||
|
if (abilities.flying) {
|
||||||
|
// Disable flight
|
||||||
|
abilities.flying = false;
|
||||||
|
abilities.allowFlying = false;
|
||||||
|
abilities.setFlySpeed(0);
|
||||||
|
}
|
||||||
|
player.sendAbilitiesUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void RegisterCallbacks(ServerPlayerEntity playerObj, ServerWorld worldObj) {
|
public void RegisterCallbacks(ServerPlayerEntity playerObj, ServerWorld worldObj) {
|
||||||
// PlayerInBaseCallback.EVENT.register((player, world) -> {
|
// PlayerInBaseCallback.EVENT.register((player, world) -> {
|
||||||
@ -43,11 +81,32 @@ public class FactionFlight extends AbstractNode {
|
|||||||
|
|
||||||
PlayerEnteredBaseCallback.EVENT.register((player, world) -> {
|
PlayerEnteredBaseCallback.EVENT.register((player, world) -> {
|
||||||
player.sendMessage(Text.of("Faction flight enabled"));
|
player.sendMessage(Text.of("Faction flight enabled"));
|
||||||
|
canFly = true;
|
||||||
|
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
|
||||||
|
ToggleFlight(serverPlayer);
|
||||||
|
return ActionResult.SUCCESS;
|
||||||
|
});
|
||||||
|
|
||||||
|
PlayerCommandFlightCallback.EVENT.register((player, world) -> {
|
||||||
|
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
|
||||||
|
Boolean isFlying = ToggleFlight(serverPlayer);
|
||||||
|
if(isFlying) {
|
||||||
|
serverPlayer.sendMessage(Text.of("Flight turned on"));
|
||||||
|
} else if (!isFlying && canFly) {
|
||||||
|
// Infers toggled off
|
||||||
|
serverPlayer.sendMessage(Text.of("Flight turned off"));
|
||||||
|
} else {
|
||||||
|
// Means player is not in fly-zone
|
||||||
|
serverPlayer.sendMessage(Text.of("You can only fly within the bounds of your faction base!"));
|
||||||
|
}
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
});
|
});
|
||||||
|
|
||||||
PlayerExitedBaseCallback.EVENT.register((player, world) -> {
|
PlayerExitedBaseCallback.EVENT.register((player, world) -> {
|
||||||
player.sendMessage(Text.of("Faction flight disabled"));
|
player.sendMessage(Text.of("Faction flight disabled"));
|
||||||
|
canFly = false;
|
||||||
|
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
|
||||||
|
ResetPlayer(serverPlayer);
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ import java.util.HashMap;
|
|||||||
import jesse.keeblarcraft.Keeblarcraft;
|
import jesse.keeblarcraft.Keeblarcraft;
|
||||||
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.AbstractNode;
|
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.AbstractNode;
|
||||||
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
|
||||||
|
@ -7,12 +7,14 @@ import com.mojang.brigadier.arguments.StringArgumentType;
|
|||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
|
||||||
import jesse.keeblarcraft.FactionMgr.FactionManager;
|
import jesse.keeblarcraft.FactionMgr.FactionManager;
|
||||||
|
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerCommandFlightCallback;
|
||||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
import net.minecraft.command.argument.EntityArgumentType;
|
import net.minecraft.command.argument.EntityArgumentType;
|
||||||
import net.minecraft.server.command.CommandManager;
|
import net.minecraft.server.command.CommandManager;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
|
||||||
public class FactionCommands {
|
public class FactionCommands {
|
||||||
|
|
||||||
@ -34,6 +36,8 @@ public class FactionCommands {
|
|||||||
.executes(context -> GetFactionInformation(context.getSource().getPlayer()))
|
.executes(context -> GetFactionInformation(context.getSource().getPlayer()))
|
||||||
.build();
|
.build();
|
||||||
var invite = CommandManager.literal("invite").build();
|
var invite = CommandManager.literal("invite").build();
|
||||||
|
var fly = CommandManager.literal("fly")
|
||||||
|
.executes(context -> ForwardFlightCallback(context)).build();
|
||||||
|
|
||||||
// The below nodes are duplicates but are necessary to make the execute path jump correctly
|
// The below nodes are duplicates but are necessary to make the execute path jump correctly
|
||||||
var createFactionName = CommandManager.argument("faction_name", StringArgumentType.greedyString())
|
var createFactionName = CommandManager.argument("faction_name", StringArgumentType.greedyString())
|
||||||
@ -85,6 +89,7 @@ public class FactionCommands {
|
|||||||
factionNode.addChild(kick);
|
factionNode.addChild(kick);
|
||||||
factionNode.addChild(info);
|
factionNode.addChild(info);
|
||||||
factionNode.addChild(invite);
|
factionNode.addChild(invite);
|
||||||
|
factionNode.addChild(fly);
|
||||||
|
|
||||||
promote.addChild(promoteName);
|
promote.addChild(promoteName);
|
||||||
demote.addChild(demoteName);
|
demote.addChild(demoteName);
|
||||||
@ -118,6 +123,13 @@ public class FactionCommands {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int ForwardFlightCallback(CommandContext<ServerCommandSource> context) {
|
||||||
|
if (context.getSource().isExecutedByPlayer()) {
|
||||||
|
ActionResult result = PlayerCommandFlightCallback.EVENT.invoker().interact(context.getSource().getPlayer(), context.getSource().getWorld());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public int SetFactionPower(ServerPlayerEntity caller, String faction, Integer amount) {
|
public int SetFactionPower(ServerPlayerEntity caller, String faction, Integer amount) {
|
||||||
FactionManager.GetInstance().SetFactionPower(caller, faction, amount);
|
FactionManager.GetInstance().SetFactionPower(caller, faction, amount);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
|
|
||||||
package jesse.keeblarcraft.Commands;
|
package jesse.keeblarcraft.Commands;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
|
||||||
@ -27,8 +25,6 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
|||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
public class ShortcutCommands {
|
public class ShortcutCommands {
|
||||||
|
|
||||||
float DEFAULT_FLIGHT_SPEED = 0.05f; // Minecraft operates on a 0.0 -> 1.0 scale; with each .01 making a difference in speed. 0.05 is creative flight speed
|
|
||||||
float SPEED_SCALAR = 20.0f; // For clamping speed down to half of its max output (So 0.5 will be max speed on a system that goes up in 0.05'ths)
|
float SPEED_SCALAR = 20.0f; // For clamping speed down to half of its max output (So 0.5 will be max speed on a system that goes up in 0.05'ths)
|
||||||
|
|
||||||
public void RegisterShortcutCommands()
|
public void RegisterShortcutCommands()
|
||||||
@ -130,21 +126,24 @@ public class ShortcutCommands {
|
|||||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||||
PlayerAbilities abilities = player.getAbilities();
|
PlayerAbilities abilities = player.getAbilities();
|
||||||
|
|
||||||
if (abilities.flying && value == null) {
|
|
||||||
// Disable flight
|
// Disable flight
|
||||||
|
if (abilities.flying && value == null) {
|
||||||
abilities.flying = false;
|
abilities.flying = false;
|
||||||
|
abilities.allowFlying = false;
|
||||||
abilities.setFlySpeed(0);
|
abilities.setFlySpeed(0);
|
||||||
player.sendMessage(Text.of("Disabled flight"));
|
player.sendMessage(Text.of("Disabled flight"));
|
||||||
|
player.sendAbilitiesUpdate();
|
||||||
} else if (!abilities.flying && value == null) {
|
} else if (!abilities.flying && value == null) {
|
||||||
value = 1;
|
value = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable flight
|
||||||
if (value != null && value >= 1 && value <= 10) {
|
if (value != null && value >= 1 && value <= 10) {
|
||||||
abilities.allowFlying = true;
|
abilities.allowFlying = true;
|
||||||
abilities.setFlySpeed((float) (value / SPEED_SCALAR)); // Dividing by 20f yields max clamp value of 0.5 since MC does 0.0-> 1.0 flight. 0.1 flight is too fast!
|
abilities.setFlySpeed((float) (value / SPEED_SCALAR)); // Dividing by 20f yields max clamp value of 0.5 since MC does 0.0-> 1.0 flight. 0.1 flight is too fast!
|
||||||
player.sendAbilitiesUpdate();
|
player.sendAbilitiesUpdate();
|
||||||
player.sendMessage(Text.of("Flight speed set to " + value));
|
player.sendMessage(Text.of("Flight speed set to " + value));
|
||||||
} else {
|
} else if (value != null) {
|
||||||
player.sendMessage(Text.literal("Only values from 1-10 are accepted"));
|
player.sendMessage(Text.literal("Only values from 1-10 are accepted"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package jesse.keeblarcraft.FactionMgr.Callbacks;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.event.Event;
|
||||||
|
import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public interface PlayerCommandFlightCallback {
|
||||||
|
Event<PlayerCommandFlightCallback> EVENT = EventFactory.createArrayBacked(PlayerCommandFlightCallback.class,
|
||||||
|
(listeners) -> (player, world) -> {
|
||||||
|
for (PlayerCommandFlightCallback listener : listeners) {
|
||||||
|
ActionResult result = listener.interact(player, world);
|
||||||
|
|
||||||
|
if (result != ActionResult.PASS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ActionResult.PASS;
|
||||||
|
});
|
||||||
|
|
||||||
|
ActionResult interact(PlayerEntity player, World world);
|
||||||
|
}
|
@ -3,7 +3,6 @@ package jesse.keeblarcraft.FactionMgr.Callbacks;
|
|||||||
import net.fabricmc.fabric.api.event.Event;
|
import net.fabricmc.fabric.api.event.Event;
|
||||||
import net.fabricmc.fabric.api.event.EventFactory;
|
import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
// import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user