Update to 1.21.5

This commit is contained in:
2025-04-16 22:30:44 +02:00
parent 5a45506bd9
commit d8c4773424
12 changed files with 91 additions and 43 deletions

View File

@@ -1,5 +1,5 @@
plugins { plugins {
id 'fabric-loom' version '1.8-SNAPSHOT' id 'fabric-loom' version '1.10-SNAPSHOT'
id 'maven-publish' id 'maven-publish'
} }

View File

@@ -3,19 +3,19 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check these on https://modmuss50.me/fabric.html # check these on https://modmuss50.me/fabric.html
minecraft_version=1.21.4 minecraft_version=1.21.5
yarn_mappings=1.21.4+build.8 yarn_mappings=1.21.5+build.1
loader_version=0.16.10 loader_version=0.16.13
# Fabric API # Fabric API
fabric_version=0.118.0+1.21.4 fabric_version=0.120.0+1.21.5
# Mod Properties # Mod Properties
mod_version=3.3.4 mod_version=3.3.5
maven_group=systems.brn maven_group=systems.brn
archives_base_name=Serverstorage archives_base_name=Serverstorage
# Dependencies # Dependencies
polymer_version=0.11.7+1.21.4 polymer_version=0.12.3+1.21.5
server_translations_api_version=2.4.0+1.21.2-rc1 server_translations_api_version=2.5.0+1.21.5-rc1
servergui_version=1.8.2+1.21.4 servergui_version=1.9.0+1.21.5

View File

@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000 networkTimeout=10000
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME

View File

@@ -59,8 +59,8 @@ public class InventoryInterfaceBlockEntity extends BlockEntity {
} }
public void nextDirection() { public void nextDirection() {
int newId = (direction.getId() + 1) % 6; int newId = (direction.getIndex() + 1) % 6;
direction = Direction.byId(newId); direction = Direction.byIndex(newId);
} }
// Serialize the BlockEntity // Serialize the BlockEntity
@@ -68,7 +68,7 @@ public class InventoryInterfaceBlockEntity extends BlockEntity {
public void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) { public void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) {
// Save the current value of the number to the nbt // Save the current value of the number to the nbt
nbt.putBoolean("isOutput", isOutput); nbt.putBoolean("isOutput", isOutput);
nbt.putInt("direction", direction.getId()); nbt.putInt("direction", direction.getIndex());
nbt.putInt("tickCounter", tickCounter); nbt.putInt("tickCounter", tickCounter);
nbt.putString("query", query); nbt.putString("query", query);
super.writeNbt(nbt, wrapperLookup); super.writeNbt(nbt, wrapperLookup);
@@ -78,10 +78,10 @@ public class InventoryInterfaceBlockEntity extends BlockEntity {
@Override @Override
public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) { public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) {
super.readNbt(nbt, wrapperLookup); super.readNbt(nbt, wrapperLookup);
isOutput = nbt.getBoolean("isOutput"); isOutput = nbt.getBoolean("isOutput", false);
direction = Direction.byId(nbt.getInt("direction")); direction = Direction.byIndex(nbt.getInt("direction", Direction.NORTH.getIndex()));
tickCounter = nbt.getInt("tickCounter"); tickCounter = nbt.getInt("tickCounter", 0);
query = nbt.getString("query"); query = nbt.getString("query", "");
} }
private static int processIncomingInternal(ItemStack stack, int count, InventoryInterfaceBlockEntity blockEntity, Inventory targetedBlockEntityInventory) { private static int processIncomingInternal(ItemStack stack, int count, InventoryInterfaceBlockEntity blockEntity, Inventory targetedBlockEntityInventory) {

View File

@@ -18,6 +18,7 @@ import systems.brn.serverstorage.lib.Session;
import systems.brn.serverstorage.screenhandlers.RadioInterfaceScreenHandler; import systems.brn.serverstorage.screenhandlers.RadioInterfaceScreenHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import static systems.brn.serverstorage.ServerStorage.ANTENNA_RANGES; import static systems.brn.serverstorage.ServerStorage.ANTENNA_RANGES;
@@ -98,17 +99,22 @@ public class RadioInterfaceBlockEntity extends LootableContainerBlockEntity {
protected void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { protected void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) {
super.readNbt(nbt, registryLookup); super.readNbt(nbt, registryLookup);
this.inventory = DefaultedList.ofSize(this.size(), ItemStack.EMPTY); this.inventory = DefaultedList.ofSize(this.size(), ItemStack.EMPTY);
this.antennaRange = nbt.getInt("AntennaRange"); this.antennaRange = nbt.getInt("AntennaRange", 0);
if (!this.readLootTable(nbt)) { if (!this.readLootTable(nbt)) {
Inventories.readNbt(nbt, this.inventory, registryLookup); Inventories.readNbt(nbt, this.inventory, registryLookup);
} }
updateAntenna(); updateAntenna();
// Deserialize sessions list // Deserialize sessions list
this.sessions.clear(); this.sessions.clear();
NbtList sessionsNbtList = nbt.getList("Sessions", 10); // 10 = NbtCompound type NbtList sessionsNbtList = nbt.getListOrEmpty("Sessions"); // 10 = NbtCompound type
for (int i = 0; i < sessionsNbtList.size(); i++) { for (int i = 0; i < sessionsNbtList.size(); i++) {
NbtCompound sessionNbt = sessionsNbtList.getCompound(i); Optional<NbtCompound> sessionNbt = sessionsNbtList.getCompound(i);
this.sessions.add(Session.fromNbt(sessionNbt)); if (sessionNbt.isPresent()) {
Session session = Session.fromNbt(sessionNbt.get());
if (session != null) {
this.sessions.add(session);
}
}
} }
} }

View File

@@ -77,9 +77,9 @@ public class StorageInterfaceBlockEntity extends BlockEntity {
public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) { public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) {
super.readNbt(nbt, wrapperLookup); super.readNbt(nbt, wrapperLookup);
page = nbt.getInt("page"); page = nbt.getInt("page", 0);
sortAlphabetically = SortMode.fromId(nbt.getInt("sortAlphabetically")); sortAlphabetically = SortMode.fromId(nbt.getInt("sortAlphabetically", SortMode.NUMERICALLY_REVERSE.getId()));
searchString = nbt.getString("searchString"); searchString = nbt.getString("searchString", "");
groupSimilar = nbt.getBoolean("groupSimilar"); groupSimilar = nbt.getBoolean("groupSimilar", false);
} }
} }

View File

@@ -12,6 +12,7 @@ import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.state.property.EnumProperty; import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@@ -110,8 +111,8 @@ public class HardDriveContainerBlock extends ConnectedBlock implements PolymerTe
} }
@Override @Override
protected void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { protected void onStateReplaced(BlockState state, ServerWorld world, BlockPos pos, boolean moved) {
ItemScatterer.onStateReplaced(state, newState, world, pos); ItemScatterer.onStateReplaced(state, world, pos);
super.onStateReplaced(state, world, pos, newState, moved); super.onStateReplaced(state, world, pos, moved);
} }
} }

View File

@@ -15,6 +15,7 @@ import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.state.property.EnumProperty; import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@@ -148,8 +149,8 @@ public class RadioInterfaceBlock extends ConnectedBlock implements PolymerTextur
} }
@Override @Override
protected void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { protected void onStateReplaced(BlockState state, ServerWorld world, BlockPos pos, boolean moved) {
ItemScatterer.onStateReplaced(state, newState, world, pos); ItemScatterer.onStateReplaced(state, world, pos);
super.onStateReplaced(state, world, pos, newState, moved); super.onStateReplaced(state, world, pos, moved);
} }
} }

View File

@@ -2,22 +2,29 @@ package systems.brn.serverstorage.lib;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import static systems.brn.serverstorage.lib.Util.getUUID;
import static systems.brn.serverstorage.lib.Util.putUUID;
public record Session(UUID sessionKey, UUID playerUUID) { public record Session(UUID sessionKey, UUID playerUUID) {
// Serialize to NBT // Serialize to NBT
public NbtCompound toNbt() { public NbtCompound toNbt() {
NbtCompound nbt = new NbtCompound(); NbtCompound nbt = new NbtCompound();
nbt.putUuid("SessionKey", this.sessionKey); putUUID(nbt, "SessionKey", this.sessionKey);
nbt.putUuid("PlayerUUID", this.playerUUID); putUUID(nbt, "PlayerUUID", this.playerUUID);
return nbt; return nbt;
} }
// Deserialize from NBT // Deserialize from NBT
public static Session fromNbt(NbtCompound nbt) { public static Session fromNbt(NbtCompound nbt) {
UUID sessionKey = nbt.getUuid("SessionKey"); Optional<UUID> sessionKey = getUUID(nbt, "SessionKey");
UUID playerUUID = nbt.getUuid("PlayerUUID"); Optional<UUID> playerUUID = getUUID(nbt, "PlayerUUID");
return new Session(sessionKey, playerUUID); if (sessionKey.isPresent() && playerUUID.isPresent()) {
return new Session(sessionKey.get(), playerUUID.get());
}
return null;
} }
} }

View File

@@ -219,8 +219,8 @@ public class StorageOperations {
if (inventory instanceof PlayerInventory playerInventory) { if (inventory instanceof PlayerInventory playerInventory) {
// Iterate through the slots in the player's inventory // Iterate through the slots in the player's inventory
for (int i = 0; i < playerInventory.main.size(); i++) { for (int i = 0; i < playerInventory.getMainStacks().size(); i++) {
ItemStack slotStack = playerInventory.main.get(i); ItemStack slotStack = playerInventory.getMainStacks().get(i);
maxInsert = canInsertToStack(slotStack, itemStack, maxInsert); maxInsert = canInsertToStack(slotStack, itemStack, maxInsert);
} }
} else { } else {

View File

@@ -5,6 +5,7 @@ import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.LoreComponent; import net.minecraft.component.type.LoreComponent;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.recipe.CraftingRecipe; import net.minecraft.recipe.CraftingRecipe;
import net.minecraft.recipe.Ingredient; import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.RecipeEntry; import net.minecraft.recipe.RecipeEntry;
@@ -19,6 +20,7 @@ import net.minecraft.util.Formatting;
import net.minecraft.util.UserCache; import net.minecraft.util.UserCache;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import java.nio.ByteBuffer;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -205,4 +207,35 @@ public class Util {
} }
return craftingEntries; return craftingEntries;
} }
public static void putUUID(NbtCompound nbtCompound, String name, UUID uuid) {
Objects.requireNonNull(uuid, "UUID cannot be null");
ByteBuffer buffer = ByteBuffer.allocate(16);
buffer.putLong(uuid.getMostSignificantBits());
buffer.putLong(uuid.getLeastSignificantBits());
nbtCompound.putByteArray(name, buffer.array());
}
public static Optional<UUID> getUUID(NbtCompound nbtCompound, String name) {
Optional<byte[]> bytesOpt = nbtCompound.getByteArray(name);
if (bytesOpt.isPresent()) {
byte[] bytes = bytesOpt.get();
if (bytes.length == 16) {
ByteBuffer buffer = ByteBuffer.wrap(bytes);
long mostSigBits = buffer.getLong();
long leastSigBits = buffer.getLong();
return Optional.of(new UUID(mostSigBits, leastSigBits));
}
} else {
Optional<int[]> intsOpt = nbtCompound.getIntArray(name);
if (intsOpt.isPresent() && intsOpt.get().length == 4) {
int[] ints = intsOpt.get();
long mostSigBits = ((long) ints[0] << 32) | (ints[1] & 0xFFFFFFFFL);
long leastSigBits = ((long) ints[2] << 32) | (ints[3] & 0xFFFFFFFFL);
return Optional.of(new UUID(mostSigBits, leastSigBits));
}
}
return Optional.empty();
}
} }

View File

@@ -232,8 +232,8 @@ public class StorageScreen extends PagedGui implements Searchable {
if (!type.shift) { if (!type.shift) {
noLoreStack.setCount(Math.min(noLoreStack.getMaxCount(), noLoreStack.getCount() / 2)); //half stack noLoreStack.setCount(Math.min(noLoreStack.getMaxCount(), noLoreStack.getCount() / 2)); //half stack
} else { } else {
for (int i = 0; i < player.getInventory().main.size(); i++) { for (int i = 0; i < player.getInventory().getMainStacks().size(); i++) {
ItemStack stack = player.getInventory().main.get(i); ItemStack stack = player.getInventory().getMainStacks().get(i);
if (ItemStack.areItemsAndComponentsEqual(stack, noLoreStack)) { if (ItemStack.areItemsAndComponentsEqual(stack, noLoreStack)) {
insertItem(stack, 0, getVirtualSize(), false); insertItem(stack, 0, getVirtualSize(), false);
} }
@@ -382,8 +382,8 @@ public class StorageScreen extends PagedGui implements Searchable {
playClickSound(player); playClickSound(player);
if (checkDistance()) { if (checkDistance()) {
if (y.isLeft) { if (y.isLeft) {
for (int i = y.shift ? 0 : 8; i < player.getInventory().main.size(); i++) { for (int i = y.shift ? 0 : 8; i < player.getInventory().getMainStacks().size(); i++) {
ItemStack stack = player.getInventory().main.get(i); ItemStack stack = player.getInventory().getMainStacks().get(i);
insertItem(stack, 0, getVirtualSize(), false); insertItem(stack, 0, getVirtualSize(), false);
} }
} }