Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ A faction's power cap increases as new members join, expanding their ability to

 

### **GET STARTED**
### **GET STARTED**

Factions Mod is very intuitive and works immediately after installation, requiring no additional configuration. However, you can read further about the mod on the [Wiki][wiki]. Our wiki goes in depth about the factions mechanics, its configuration, commands and integrations.

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/icker/factions/core/WorldManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private static void onMove(ServerPlayer player) {
ServerLevel world = (ServerLevel) player.level();
String dimension = world.dimension().identifier().toString();

ChunkPos chunkPos = world.getChunk(player.blockPosition()).getPos();
ChunkPos chunkPos = player.chunkPosition();

Claim claim = Claim.get(chunkPos.x(), chunkPos.z(), dimension);
if (user.autoclaim && claim == null) {
Expand Down
44 changes: 31 additions & 13 deletions src/main/java/io/icker/factions/database/SerializerRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.icker.factions.api.persistents.User.SoundMode;
import io.icker.factions.util.WorldUtils;

import net.minecraft.core.RegistryAccess;
import net.minecraft.core.UUIDUtil;
import net.minecraft.nbt.ByteArrayTag;
import net.minecraft.nbt.ByteTag;
Expand Down Expand Up @@ -146,6 +147,17 @@ private static <T extends Enum<T>> Serializer<T, StringTag> createEnumSerializer
el -> Enum.valueOf(clazz, el.asString().orElse("")));
}

private static RegistryAccess resolveRegistryAccess() {
var world = WorldUtils.getWorld("minecraft:overworld");
if (world != null) {
return world.registryAccess();
}
if (WorldUtils.server != null) {
return WorldUtils.server.registryAccess();
}
return null;
}

public record InventoryItem(int slot, ItemStack stack) {
public static final Codec<InventoryItem> CODEC =
RecordCodecBuilder.create(
Expand All @@ -165,12 +177,16 @@ public record InventoryItem(int slot, ItemStack stack) {
private static Serializer<SimpleContainer, ListTag> createInventorySerializer(int size) {
return new Serializer<SimpleContainer, ListTag>(
val -> {
RegistryAccess registryAccess = resolveRegistryAccess();
if (registryAccess == null) {
FactionsMod.LOGGER.error(
"Registry access unavailable; skipping inventory serialization.");
return new ListTag();
}
ProblemReporter.ScopedCollector reporter =
new ProblemReporter.ScopedCollector(FactionsMod.LOGGER);
TagValueOutput view =
TagValueOutput.createWithContext(
reporter,
WorldUtils.getWorld("minecraft:overworld").registryAccess());
TagValueOutput.createWithContext(reporter, registryAccess);
TypedOutputList<InventoryItem> appender =
view.list("Data", InventoryItem.CODEC);

Expand All @@ -186,23 +202,25 @@ private static Serializer<SimpleContainer, ListTag> createInventorySerializer(in
return view.buildResult().getList("Data").get();
},
el -> {
RegistryAccess registryAccess = resolveRegistryAccess();
SimpleContainer inventory = new SimpleContainer(size);
for (int i = 0; i < size; ++i) {
inventory.setItem(i, ItemStack.EMPTY);
}
if (registryAccess == null) {
FactionsMod.LOGGER.error(
"Registry access unavailable; skipping inventory deserialization.");
return inventory;
}

CompoundTag compound = new CompoundTag();
compound.put("Data", el);

ProblemReporter.ScopedCollector reporter =
new ProblemReporter.ScopedCollector(FactionsMod.LOGGER);

ValueInput view =
TagValueInput.create(
reporter,
WorldUtils.getWorld("minecraft:overworld").registryAccess(),
compound);

SimpleContainer inventory = new SimpleContainer(size);

for (int i = 0; i < size; ++i) {
inventory.setItem(i, ItemStack.EMPTY);
}
TagValueInput.create(reporter, registryAccess, compound);

TypedInputList<InventoryItem> list_view =
view.listOrEmpty("Data", InventoryItem.CODEC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@
public class ServerGamePacketListenerImplMixin {
@Shadow public ServerPlayer player;

@Inject(method = "handleMovePlayer", at = @At("HEAD"))
@Inject(method = "handleMovePlayer", at = @At("TAIL"))
public void handleMovePlayer(ServerboundMovePlayerPacket packet, CallbackInfo ci) {
PlayerEvents.ON_MOVE.invoker().onMove(player);
if (player == null) return;
if (player.level() == null) return;

var server = player.level().getServer();
if (server == null) return;

if (server.isSameThread()) {
PlayerEvents.ON_MOVE.invoker().onMove(player);
} else {
server.execute(() -> PlayerEvents.ON_MOVE.invoker().onMove(player));
}
}

@Inject(method = "broadcastChatMessage", at = @At("HEAD"), cancellable = true)
Expand Down