Skip to content

Commit

Permalink
Merge branch 'refs/heads/1.19' into 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Nov 12, 2024
2 parents eeb8e4c + e9b014a commit 6110496
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 114 deletions.
46 changes: 18 additions & 28 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
tab_width = 4
trim_trailing_whitespace = true

[*.gradle]
indent_style = tab

[*.java]
indent_size = 4
indent_style = tab
tab_width = 4
insert_final_newline = true

[*.json]
indent_style = space
[*.yml]
indent_size = 2

[quilt.mod.json]
indent_style = tab
tab_width = 2

[*.toml]
indent_style = tab
tab_width = 2

[*.properties]
indent_style = space
indent_size = 2

[.editorconfig]
indent_style = space
indent_size = 4
[*.java]
ij_java_block_brace_style = end_of_line
ij_java_lambda_brace_style = end_of_line
ij_java_method_brace_style = end_of_line
ij_java_names_count_to_use_import_on_demand = 999

[{*.gant,*.groovy,*.gy,*.gradle}]
ij_groovy_block_brace_style = end_of_line
ij_groovy_class_brace_style = end_of_line
ij_groovy_lambda_brace_style = end_of_line
ij_groovy_method_brace_style = end_of_line

[{*.har,*.json,*.png.mcmeta,mcmod.info,pack.mcmeta}]
ij_json_array_wrapping = split_into_lines
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ Requires <a href="https://modrinth.com/mod/connector">Connector</a> and <a href=
- `spawn_point`: separate spawn points per preset

## Usage

Both modules are disabled by default, run `/switchy module enable` to enable them.

### Last Location

When first switching to a preset after enabling this module, nothing will happen. When you switch back to that preset later, you will be teleported to where you left off. Disabling the module removes all saved locations.

### Spawn Point

When switching to a preset for the first time after enabling this module, that preset will keep the spawnpoint of the *previous* preset that you just switched from. You can re-set the spawnpoint for the current preset by using a bed or respawn anchor.
24 changes: 12 additions & 12 deletions src/main/java/xyz/fulmine/switchy_teleport/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ public Location(Vec3d coordinates, float pitch, float yaw, Identifier dimension,
this(coordinates.getX(), coordinates.getY(), coordinates.getZ(), pitch, yaw, dimension, setSpawn);
}

public static Location fromNbt(NbtCompound nbt) {
return new Location(
nbt.getDouble(KEY_X),
nbt.getDouble(KEY_Y),
nbt.getDouble(KEY_Z),
nbt.getFloat(KEY_PITCH),
nbt.getFloat(KEY_YAW),
new Identifier(nbt.getString(KEY_DIMENSION)),
nbt.contains(KEY_SET_SPAWN) ? nbt.getBoolean(KEY_SET_SPAWN) : null
);
}

public Vec3d getCoordinates() {
return new Vec3d(x, y, z);
}
Expand All @@ -38,16 +50,4 @@ public NbtCompound toNbt() {

return outNbt;
}

public static Location fromNbt(NbtCompound nbt) {
return new Location(
nbt.getDouble(KEY_X),
nbt.getDouble(KEY_Y),
nbt.getDouble(KEY_Z),
nbt.getFloat(KEY_PITCH),
nbt.getFloat(KEY_YAW),
new Identifier(nbt.getString(KEY_DIMENSION)),
nbt.contains(KEY_SET_SPAWN) ? nbt.getBoolean(KEY_SET_SPAWN) : null
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package xyz.fulmine.switchy_teleport.modules;

import folk.sisby.switchy.api.SwitchyEvents;
import folk.sisby.switchy.api.module.*;
import folk.sisby.switchy.api.module.SwitchyModule;
import folk.sisby.switchy.api.module.SwitchyModuleEditable;
import folk.sisby.switchy.api.module.SwitchyModuleInfo;
import folk.sisby.switchy.api.module.SwitchyModuleRegistry;
import folk.sisby.switchy.api.module.SwitchyModuleTransferable;
import folk.sisby.switchy.util.Feedback;
import net.minecraft.server.network.ServerPlayerEntity;
import org.jetbrains.annotations.Nullable;
Expand All @@ -12,10 +16,10 @@ public class LocationModule extends LocationModuleData implements SwitchyModule,
@Override
public void updateFromPlayer(ServerPlayerEntity player, @Nullable String nextPreset) {
location = new Location(
player.getX(), player.getY(), player.getZ(),
player.getPitch(), player.getYaw(),
player.getWorld().getRegistryKey().getValue(),
null
player.getX(), player.getY(), player.getZ(),
player.getPitch(), player.getYaw(),
player.getWorld().getRegistryKey().getValue(),
null
);
}

Expand All @@ -29,12 +33,12 @@ public void applyToPlayer(ServerPlayerEntity player) {
@Override
public void onInitialize() {
SwitchyModuleRegistry.registerModule(ID, LocationModule::new, new SwitchyModuleInfo(
false,
SwitchyModuleEditable.OPERATOR,
Feedback.translatable("switchy.modules.switchy_teleport.last_location.description"))
.withDescriptionWhenEnabled(Feedback.translatable("switchy.modules.switchy_teleport.last_location.enabled"))
.withDescriptionWhenDisabled(Feedback.translatable("switchy.modules.switchy_teleport.last_location.disabled"))
.withDeletionWarning(Feedback.translatable("switchy.modules.switchy_teleport.last_location.warning"))
false,
SwitchyModuleEditable.OPERATOR,
Feedback.translatable("switchy.modules.switchy_teleport.last_location.description"))
.withDescriptionWhenEnabled(Feedback.translatable("switchy.modules.switchy_teleport.last_location.enabled"))
.withDescriptionWhenDisabled(Feedback.translatable("switchy.modules.switchy_teleport.last_location.disabled"))
.withDeletionWarning(Feedback.translatable("switchy.modules.switchy_teleport.last_location.warning"))
);
}
}
32 changes: 18 additions & 14 deletions src/main/java/xyz/fulmine/switchy_teleport/modules/SpawnModule.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package xyz.fulmine.switchy_teleport.modules;

import folk.sisby.switchy.api.SwitchyEvents;
import folk.sisby.switchy.api.module.*;
import folk.sisby.switchy.api.module.SwitchyModule;
import folk.sisby.switchy.api.module.SwitchyModuleEditable;
import folk.sisby.switchy.api.module.SwitchyModuleInfo;
import folk.sisby.switchy.api.module.SwitchyModuleRegistry;
import folk.sisby.switchy.api.module.SwitchyModuleTransferable;
import folk.sisby.switchy.util.Feedback;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
Expand All @@ -17,10 +21,10 @@ public void updateFromPlayer(ServerPlayerEntity player, @Nullable String nextPre

if (respawnPoint != null) {
location = new Location(
respawnPoint.getX(), respawnPoint.getY(), respawnPoint.getZ(),
0, player.getSpawnAngle(),
player.getSpawnPointDimension().getValue(),
player.isSpawnForced()
respawnPoint.getX(), respawnPoint.getY(), respawnPoint.getZ(),
0, player.getSpawnAngle(),
player.getSpawnPointDimension().getValue(),
player.isSpawnForced()
);
}
}
Expand All @@ -29,21 +33,21 @@ public void updateFromPlayer(ServerPlayerEntity player, @Nullable String nextPre
public void applyToPlayer(ServerPlayerEntity player) {
if (location != null) {
player.setSpawnPoint(RegistryKey.of(Registry.WORLD_KEY, location.dimension()),
new BlockPos(location.getCoordinates()),
location.yaw(),
Boolean.TRUE.equals(location.setSpawn()), false);
new BlockPos(location.getCoordinates()),
location.yaw(),
Boolean.TRUE.equals(location.setSpawn()), false);
}
}

@Override
public void onInitialize() {
SwitchyModuleRegistry.registerModule(ID, SpawnModule::new, new SwitchyModuleInfo(
false,
SwitchyModuleEditable.OPERATOR,
Feedback.translatable("switchy.modules.switchy_teleport.spawn_point.description"))
.withDescriptionWhenEnabled(Feedback.translatable("switchy.modules.switchy_teleport.spawn_point.enabled"))
.withDescriptionWhenDisabled(Feedback.translatable("switchy.modules.switchy_teleport.spawn_point.disabled"))
.withDeletionWarning(Feedback.translatable("switchy.modules.switchy_teleport.spawn_point.warning"))
false,
SwitchyModuleEditable.OPERATOR,
Feedback.translatable("switchy.modules.switchy_teleport.spawn_point.description"))
.withDescriptionWhenEnabled(Feedback.translatable("switchy.modules.switchy_teleport.spawn_point.enabled"))
.withDescriptionWhenDisabled(Feedback.translatable("switchy.modules.switchy_teleport.spawn_point.disabled"))
.withDeletionWarning(Feedback.translatable("switchy.modules.switchy_teleport.spawn_point.warning"))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
public class TeleportUtils {
public static void teleportPlayer(ServerPlayerEntity player, Location location) {
player.teleport(
player.getWorld().getServer().getWorld(RegistryKey.of(Registry.WORLD_KEY, location.dimension())),
location.x(), location.y(), location.z(),
location.yaw(), location.pitch()
player.getWorld().getServer().getWorld(RegistryKey.of(Registry.WORLD_KEY, location.dimension())),
location.x(), location.y(), location.z(),
location.yaw(), location.pitch()
);
}
}
20 changes: 10 additions & 10 deletions src/main/resources/assets/switchy_teleport/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"switchy.modules.switchy_teleport.last_location.description": "A module that switches the location of the player.",
"switchy.modules.switchy_teleport.last_location.enabled": "You will have a separate tracked location for each preset.",
"switchy.modules.switchy_teleport.last_location.disabled": "Your location wont be tracked per-preset; you will not be teleported when switching.",
"switchy.modules.switchy_teleport.last_location.warning": "All saved locations will be IMMEDIATELY lost. This is irreversible.",
"switchy.modules.switchy_teleport.spawn_point.description": "A module that switches the spawn point of the player.",
"switchy.modules.switchy_teleport.spawn_point.enabled": "You will have separate spawn points per-preset.",
"switchy.modules.switchy_teleport.spawn_point.disabled": "You will share a single spawn point across all presets.",
"switchy.modules.switchy_teleport.spawn_point.warning": "All other spawn points will be IMMEDIATELY lost. This is irreversible.",
"switchy.modules.switchy_teleport.last_location.preview.tooltip": "Location: %s X:%s Y:%s Z:%s",
"switchy.modules.switchy_teleport.spawn_point.preview.tooltip": "Spawn: %s X:%s Y:%s Z:%s"
"switchy.modules.switchy_teleport.last_location.description": "A module that switches the location of the player.",
"switchy.modules.switchy_teleport.last_location.enabled": "You will have a separate tracked location for each preset.",
"switchy.modules.switchy_teleport.last_location.disabled": "Your location wont be tracked per-preset; you will not be teleported when switching.",
"switchy.modules.switchy_teleport.last_location.warning": "All saved locations will be IMMEDIATELY lost. This is irreversible.",
"switchy.modules.switchy_teleport.spawn_point.description": "A module that switches the spawn point of the player.",
"switchy.modules.switchy_teleport.spawn_point.enabled": "You will have separate spawn points per-preset.",
"switchy.modules.switchy_teleport.spawn_point.disabled": "You will share a single spawn point across all presets.",
"switchy.modules.switchy_teleport.spawn_point.warning": "All other spawn points will be IMMEDIATELY lost. This is irreversible.",
"switchy.modules.switchy_teleport.last_location.preview.tooltip": "Location: %s X:%s Y:%s Z:%s",
"switchy.modules.switchy_teleport.spawn_point.preview.tooltip": "Spawn: %s X:%s Y:%s Z:%s"
}
72 changes: 36 additions & 36 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
{
"schemaVersion": 1,
"id": "${modId}",
"version": "${version}",
"name": "${modName}",
"description": "${modDescription}",
"authors": [
"${authors}"
],
"contributors": [
"${contributors}"
],
"contact": {
"homepage": "${homepage}",
"issues": "${issues}",
"sources": "${sources}"
},
"license": "${license}",
"icon": "assets/${modId}/icon.png",
"depends": {
"minecraft": ">=${mc}",
"fabricloader": ">=${fl}",
"fabric-api": ">=${fapi}",
"switchy-core": ">=${switchy}",
"switchy-client": ">=${switchy}",
"switchy-ui": ">=${switchy}"
},
"entrypoints": {
"switchy": [
"xyz.fulmine.switchy_teleport.modules.LocationModule",
"xyz.fulmine.switchy_teleport.modules.SpawnModule"
],
"switchy_client": [
"xyz.fulmine.switchy_teleport.modules.client.LocationClientModule",
"xyz.fulmine.switchy_teleport.modules.client.SpawnClientModule"
]
}
"schemaVersion": 1,
"id": "${modId}",
"version": "${version}",
"name": "${modName}",
"description": "${modDescription}",
"authors": [
"${authors}"
],
"contributors": [
"${contributors}"
],
"contact": {
"homepage": "${homepage}",
"issues": "${issues}",
"sources": "${sources}"
},
"license": "${license}",
"icon": "assets/${modId}/icon.png",
"depends": {
"minecraft": ">=${mc}",
"fabricloader": ">=${fl}",
"fabric-api": ">=${fapi}",
"switchy-core": ">=${switchy}",
"switchy-client": ">=${switchy}",
"switchy-ui": ">=${switchy}"
},
"entrypoints": {
"switchy": [
"xyz.fulmine.switchy_teleport.modules.LocationModule",
"xyz.fulmine.switchy_teleport.modules.SpawnModule"
],
"switchy_client": [
"xyz.fulmine.switchy_teleport.modules.client.LocationClientModule",
"xyz.fulmine.switchy_teleport.modules.client.SpawnClientModule"
]
}
}

0 comments on commit 6110496

Please sign in to comment.