From d5968b7d260de1c048861a8b3b4ceb5fbfd2596b Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Sat, 23 Mar 2024 01:36:09 +0000 Subject: [PATCH 1/7] fix: minor issues but nothing fatal --- build.gradle | 2 +- common/build.gradle | 22 ---------------------- neoforge/build.gradle | 2 +- 3 files changed, 2 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index 2cb07b3..b49b5d6 100755 --- a/build.gradle +++ b/build.gradle @@ -106,7 +106,7 @@ publishMods { // TODO: Migrate to something else def tag = providers.environmentVariable("TAG").getOrElse("release") - type = tag == "release" ? STABLE : (tag == "beta" ? BETA : ALPHA) + type = tag == "beta" ? BETA : (tag == "alpha" ? ALPHA : STABLE) def createOptions = (String projectName) -> { publishOptions { diff --git a/common/build.gradle b/common/build.gradle index 543f8bd..7dfd646 100755 --- a/common/build.gradle +++ b/common/build.gradle @@ -31,26 +31,4 @@ publishing { from components.java } } - - repositories { - if (ftbPublishing.ftbToken) { - maven { - url ftbPublishing.ftbURL - credentials { - username = ftbPublishing.ftbUser - password = ftbPublishing.ftbToken - } - } - } - - if (ftbPublishing.sapsToken) { - maven { - url ftbPublishing.sapsURL - credentials { - username = ftbPublishing.sapsUser - password = ftbPublishing.sapsToken - } - } - } - } } diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 61290e0..a907215 100755 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -78,7 +78,7 @@ components.java { publishing { publications { - mavenForge(MavenPublication) { + mavenNeoforge(MavenPublication) { artifactId = "${rootProject.archives_base_name}-${project.name}" version ftbPublishing.mavenVersion from components.java From ce97f0ad0a998b937a9f3841699af87e974e73a9 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Tue, 26 Mar 2024 10:01:47 +0000 Subject: [PATCH 2/7] chore: documented the item & block tags in README [ciskip] --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3bdf87b..f4dc736 100755 --- a/README.md +++ b/README.md @@ -1 +1,25 @@ -# FTB Ultimine \ No newline at end of file +# FTB Ultimine + +public static final TagKey DENY_TAG = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "excluded_tools")); +public static final TagKey STRICT_DENY_TAG = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "excluded_tools/strict")); +public static final TagKey ALLOW_TAG = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "included_tools")); + + public static final TagKey EXCLUDED_BLOCKS = TagKey.create(Registries.BLOCK, new ResourceLocation(MOD_ID, "excluded_blocks")); + public static final TagKey BLOCK_WHITELIST = TagKey.create(Registries.BLOCK, new ResourceLocation(MOD_ID, "block_whitelist")); + public static final TagKey TILLABLE_TAG = TagKey.create(Registries.BLOCK, new ResourceLocation(MOD_ID, "farmland_tillable")); + public static final TagKey FLATTENABLE_TAG = TagKey.create(Registries.BLOCK, new ResourceLocation(MOD_ID, "shovel_flattenable")); + +## Tags + +### Item Tags + +* `ftbultimine:excluded_tools` - items in this tag can't be used for ultimining (applies to main hand slot) +* `ftbultimine:excluded_tools/strict` - items in this tag can't be used for ultimining (applies to main _and_ offhand slots) +* `ftbultimine:included_tools` - if `require_tool` is true in server config, by default only "tool" items can be used (tiered items with durability); this can be used to allow extra items + +### Block Tags + +* `ftbultimine:excluded_blocks` - blocks in this tag may never be ultimined +* `ftbultimine:block_whitelist` - if this tag is non-empty, then _only_ blocks in this tag may be ultimined +* `ftbultimine:farmland_tillable` - blocks in this tag can be ultimine-tilled with a hoe tool; includes grass & dirt blocks by default +* `ftbultimine:shovel_flattenable` - blocks in this tag can be ultimine-flattened (turned to dirt path) with a shovel tool; includes grass & dirt blocks by default \ No newline at end of file From c8e4ae9b1b50b90fcee2a55bbe236685238bc36b Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Tue, 26 Mar 2024 10:02:31 +0000 Subject: [PATCH 3/7] fix: oops too much info in README :) [ciskip] --- README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/README.md b/README.md index f4dc736..18a1b07 100755 --- a/README.md +++ b/README.md @@ -1,14 +1,5 @@ # FTB Ultimine -public static final TagKey DENY_TAG = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "excluded_tools")); -public static final TagKey STRICT_DENY_TAG = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "excluded_tools/strict")); -public static final TagKey ALLOW_TAG = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "included_tools")); - - public static final TagKey EXCLUDED_BLOCKS = TagKey.create(Registries.BLOCK, new ResourceLocation(MOD_ID, "excluded_blocks")); - public static final TagKey BLOCK_WHITELIST = TagKey.create(Registries.BLOCK, new ResourceLocation(MOD_ID, "block_whitelist")); - public static final TagKey TILLABLE_TAG = TagKey.create(Registries.BLOCK, new ResourceLocation(MOD_ID, "farmland_tillable")); - public static final TagKey FLATTENABLE_TAG = TagKey.create(Registries.BLOCK, new ResourceLocation(MOD_ID, "shovel_flattenable")); - ## Tags ### Item Tags From 94dedb71363ad7e9c2d58c6b53c92315310efc2f Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Tue, 26 Mar 2024 10:07:10 +0000 Subject: [PATCH 4/7] chore: added ftb ranks notes to README [ciskip] --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 18a1b07..76e29e4 100755 --- a/README.md +++ b/README.md @@ -13,4 +13,11 @@ * `ftbultimine:excluded_blocks` - blocks in this tag may never be ultimined * `ftbultimine:block_whitelist` - if this tag is non-empty, then _only_ blocks in this tag may be ultimined * `ftbultimine:farmland_tillable` - blocks in this tag can be ultimine-tilled with a hoe tool; includes grass & dirt blocks by default -* `ftbultimine:shovel_flattenable` - blocks in this tag can be ultimine-flattened (turned to dirt path) with a shovel tool; includes grass & dirt blocks by default \ No newline at end of file +* `ftbultimine:shovel_flattenable` - blocks in this tag can be ultimine-flattened (turned to dirt path) with a shovel tool; includes grass & dirt blocks by default + +## FTB Ranks Integration + +Following nodes can be configured via [FTB Ranks](https://www.curseforge.com/minecraft/mc-mods/ftb-ranks-forge): + +* `ftbultimine.max_blocks` - if present in a player's rank, overrides the server `max_blocks` config setting +* `ftbultimine.ultimine_cooldown` - if present in a player's rank, overrides the server `ultimine_cooldown` setting From 2b761749361086c923745fc4b52dceb8f3257059 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Mon, 20 May 2024 12:22:02 +0100 Subject: [PATCH 5/7] chore: ported to 1.20.6 --- .github/workflows/build.yml | 3 +- .github/workflows/release.yml | 1 + build.gradle | 4 +- common/build.gradle | 2 +- .../mods/ftbultimine/BrokenItemHandler.java | 11 ++- .../ftb/mods/ftbultimine/CooldownTracker.java | 3 +- .../dev/ftb/mods/ftbultimine/FTBUltimine.java | 19 +++--- .../mods/ftbultimine/FTBUltimineCommands.java | 5 +- .../ftbultimine/FTBUltiminePlayerData.java | 9 +-- .../ftb/mods/ftbultimine/ItemCollection.java | 67 +++++++++++-------- .../mods/ftbultimine/RightClickHandlers.java | 12 ++-- .../ftbultimine/client/FTBUltimineClient.java | 7 +- .../config/FTBUltimineServerConfig.java | 3 +- .../integration/FTBRanksIntegration.java | 5 +- .../ftbultimine/net/EditConfigPacket.java | 34 ++++------ .../mods/ftbultimine/net/FTBUltimineNet.java | 24 +++---- .../ftbultimine/net/KeyPressedPacket.java | 39 +++++------ .../ftbultimine/net/ModeChangedPacket.java | 33 ++++----- .../mods/ftbultimine/net/SendShapePacket.java | 51 ++++---------- .../net/SyncConfigFromServerPacket.java | 38 +++++------ .../net/SyncConfigToServerPacket.java | 56 +++++++--------- .../net/SyncUltimineTimePacket.java | 49 ++++++-------- .../ftb/mods/ftbultimine/utils/ItemUtils.java | 16 ----- .../ftbultimine/utils/PlatformMethods.java | 11 --- .../utils/fabric/ItemUtilsImpl.java | 23 ------- .../utils/fabric/PlatformMethodsImpl.java | 9 --- gradle.properties | 18 ++--- gradle/wrapper/gradle-wrapper.properties | 2 +- neoforge/build.gradle | 2 +- .../utils/neoforge/ItemUtilsImpl.java | 14 ---- .../utils/neoforge/PlatformMethodsImpl.java | 10 --- .../{mods.toml => neoforge.mods.toml} | 0 settings.gradle | 6 +- 33 files changed, 228 insertions(+), 358 deletions(-) mode change 100755 => 100644 common/src/main/java/dev/ftb/mods/ftbultimine/net/KeyPressedPacket.java mode change 100755 => 100644 common/src/main/java/dev/ftb/mods/ftbultimine/net/ModeChangedPacket.java mode change 100755 => 100644 common/src/main/java/dev/ftb/mods/ftbultimine/net/SendShapePacket.java delete mode 100755 common/src/main/java/dev/ftb/mods/ftbultimine/utils/ItemUtils.java delete mode 100755 common/src/main/java/dev/ftb/mods/ftbultimine/utils/PlatformMethods.java delete mode 100755 fabric/src/main/java/dev/ftb/mods/ftbultimine/utils/fabric/ItemUtilsImpl.java delete mode 100755 fabric/src/main/java/dev/ftb/mods/ftbultimine/utils/fabric/PlatformMethodsImpl.java delete mode 100755 neoforge/src/main/java/dev/ftb/mods/ftbultimine/utils/neoforge/ItemUtilsImpl.java delete mode 100755 neoforge/src/main/java/dev/ftb/mods/ftbultimine/utils/neoforge/PlatformMethodsImpl.java rename neoforge/src/main/resources/META-INF/{mods.toml => neoforge.mods.toml} (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5d4d795..2cb0001 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,6 +18,7 @@ jobs: with: curse-publish-task: "" maven-snapshots: true + java-version: 21 secrets: ftb-maven-token: ${{ secrets.FTB_MAVEN_TOKEN }} - saps-token: ${{ secrets.SAPS_TOKEN }} \ No newline at end of file + saps-token: ${{ secrets.SAPS_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d444b64..5d42e34 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,6 +11,7 @@ jobs: uses: FTBTeam/mods-meta/.github/workflows/standard-release.yml@main with: curse-publish-task: publishMods + java-version: 21 secrets: ftb-maven-token: ${{ secrets.FTB_MAVEN_TOKEN }} saps-token: ${{ secrets.SAPS_TOKEN }} diff --git a/build.gradle b/build.gradle index b49b5d6..ae296cc 100755 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false id "me.modmuss50.mod-publish-plugin" version "0.4.5" } @@ -34,7 +34,7 @@ allprojects { // needs to be done AFTER version is set apply from: "https://raw.githubusercontent.com/FTBTeam/mods-meta/main/gradle/publishing.gradle" - sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = 17 + sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = 21 compileJava { options.encoding = "UTF-8" diff --git a/common/build.gradle b/common/build.gradle index 7dfd646..833efbf 100755 --- a/common/build.gradle +++ b/common/build.gradle @@ -8,7 +8,7 @@ dependencies { def ENV = System.getenv() architectury { - common("forge", "fabric", "neoforge") + common(/* "forge", */ "fabric", "neoforge") } configurations { diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/BrokenItemHandler.java b/common/src/main/java/dev/ftb/mods/ftbultimine/BrokenItemHandler.java index a2f81ad..e3aa235 100755 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/BrokenItemHandler.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/BrokenItemHandler.java @@ -5,11 +5,16 @@ import java.util.function.Consumer; -public class BrokenItemHandler implements Consumer { +public class BrokenItemHandler implements Runnable { + private final ServerPlayer player; public boolean isBroken = false; - @Override - public void accept(ServerPlayer player) { + public BrokenItemHandler(ServerPlayer player) { + this.player = player; + } + + @Override + public void run() { isBroken = true; player.broadcastBreakEvent(EquipmentSlot.MAINHAND); } diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/CooldownTracker.java b/common/src/main/java/dev/ftb/mods/ftbultimine/CooldownTracker.java index cd24254..410a841 100644 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/CooldownTracker.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/CooldownTracker.java @@ -1,5 +1,6 @@ package dev.ftb.mods.ftbultimine; +import dev.architectury.networking.NetworkManager; import dev.ftb.mods.ftbultimine.config.FTBUltimineServerConfig; import dev.ftb.mods.ftbultimine.net.SyncUltimineTimePacket; import dev.ftb.mods.ftbultimine.net.SyncUltimineTimePacket.TimeType; @@ -30,7 +31,7 @@ public static void setLastUltimineTime(Player player, long when) { CooldownTracker instance = player.level().isClientSide ? clientInstance : serverInstance; instance.lastUltimineTime.put(player.getUUID(), when); if (player instanceof ServerPlayer sp) { - new SyncUltimineTimePacket(when, TimeType.LAST_USED).sendTo(sp); + NetworkManager.sendToPlayer(sp, new SyncUltimineTimePacket(when, TimeType.LAST_USED)); } } diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/FTBUltimine.java b/common/src/main/java/dev/ftb/mods/ftbultimine/FTBUltimine.java index 27de4a1..a0eec6e 100755 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/FTBUltimine.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/FTBUltimine.java @@ -3,6 +3,7 @@ import dev.architectury.event.EventResult; import dev.architectury.event.events.common.*; import dev.architectury.hooks.level.entity.PlayerHooks; +import dev.architectury.networking.NetworkManager; import dev.architectury.platform.Platform; import dev.architectury.registry.ReloadListenerRegistry; import dev.architectury.utils.EnvExecutor; @@ -83,6 +84,7 @@ public static void setPermissionOverride(Predicate p) { public FTBUltimine() { instance = this; + FTBUltimineNet.init(); if (Platform.isModLoaded("ftbranks")) { @@ -120,8 +122,8 @@ public FTBUltiminePlayerData getOrCreatePlayerData(Player player) { private void playerJoined(ServerPlayer serverPlayer) { SNBTCompoundTag config = new SNBTCompoundTag(); FTBUltimineServerConfig.CONFIG.write(config); - new SyncConfigFromServerPacket(config).sendTo(serverPlayer); - new SyncUltimineTimePacket(FTBUltimineServerConfig.getUltimineCooldown(serverPlayer), TimeType.COOLDOWN).sendTo(serverPlayer); + NetworkManager.sendToPlayer(serverPlayer, new SyncConfigFromServerPacket(config)); + NetworkManager.sendToPlayer(serverPlayer, new SyncUltimineTimePacket(FTBUltimineServerConfig.getUltimineCooldown(serverPlayer), TimeType.COOLDOWN)); } private void serverStarting(MinecraftServer server) { @@ -136,7 +138,7 @@ public void setKeyPressed(ServerPlayer player, boolean pressed) { data.clearCache(); if (!data.isPressed()) { - new SendShapePacket(data.getCurrentShapeIndex(), Collections.emptyList()).sendTo(player); + NetworkManager.sendToPlayer(player, new SendShapePacket(data.getCurrentShapeIndex(), Collections.emptyList())); } } @@ -144,7 +146,7 @@ public void modeChanged(ServerPlayer player, boolean next) { FTBUltiminePlayerData data = getOrCreatePlayerData(player); data.cycleShape(next); data.clearCache(); - new SendShapePacket(data.getCurrentShapeIndex(), Collections.emptyList()).sendTo(player); + NetworkManager.sendToPlayer(player, new SendShapePacket(data.getCurrentShapeIndex(), Collections.emptyList())); } /** @@ -248,8 +250,9 @@ public EventResult blockBroken(Level world, BlockPos pos, BlockState state, Serv ItemStack stack = player.getMainHandItem(); if (hadItem && stack.isEmpty()) { break; - } else if (hadItem && stack.hasTag() && stack.getTag().getBoolean("tic_broken")) { - break; + // TODO update this if & when Tinkers updates to 1.20.6+ +// } else if (hadItem && stack.hasTag() && stack.getTag().getBoolean("tic_broken")) { +// break; } else if (hadItem && FTBUltimineServerConfig.PREVENT_TOOL_BREAK.get() > 0 && stack.isDamageableItem() && stack.getDamageValue() >= stack.getMaxDamage() - FTBUltimineServerConfig.PREVENT_TOOL_BREAK.get()) { break; } @@ -271,7 +274,7 @@ public EventResult blockBroken(Level world, BlockPos pos, BlockState state, Serv } data.clearCache(); - new SendShapePacket(data.getCurrentShapeIndex(), Collections.emptyList()).sendTo(player); + NetworkManager.sendToPlayer(player, new SendShapePacket(data.getCurrentShapeIndex(), Collections.emptyList())); return EventResult.interruptFalse(); } @@ -354,7 +357,7 @@ public EventResult entityJoinedWorld(Entity entity, Level level) { return EventResult.pass(); } - public static ResourceLocation id(String path) { + public static ResourceLocation rl(String path) { return new ResourceLocation(MOD_ID, path); } diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/FTBUltimineCommands.java b/common/src/main/java/dev/ftb/mods/ftbultimine/FTBUltimineCommands.java index bd953a6..d45693a 100644 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/FTBUltimineCommands.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/FTBUltimineCommands.java @@ -1,6 +1,7 @@ package dev.ftb.mods.ftbultimine; import com.mojang.brigadier.CommandDispatcher; +import dev.architectury.networking.NetworkManager; import dev.ftb.mods.ftbultimine.net.EditConfigPacket; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; @@ -14,14 +15,14 @@ public static void registerCommands(CommandDispatcher dispat .then(Commands.literal("serverconfig") .requires(sourceStack -> sourceStack.isPlayer() && sourceStack.hasPermission(2)) .executes(context -> { - new EditConfigPacket(false).sendTo(Objects.requireNonNull(context.getSource().getPlayer())); + NetworkManager.sendToPlayer(context.getSource().getPlayerOrException(), new EditConfigPacket(false)); return 1; }) ) .then(Commands.literal("clientconfig") .requires(CommandSourceStack::isPlayer) .executes(context -> { - new EditConfigPacket(true).sendTo(Objects.requireNonNull(context.getSource().getPlayer())); + NetworkManager.sendToPlayer(context.getSource().getPlayerOrException(), new EditConfigPacket(true)); return 1; }) ) diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/FTBUltiminePlayerData.java b/common/src/main/java/dev/ftb/mods/ftbultimine/FTBUltiminePlayerData.java index e483af1..3c43507 100755 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/FTBUltiminePlayerData.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/FTBUltiminePlayerData.java @@ -1,16 +1,17 @@ package dev.ftb.mods.ftbultimine; +import dev.architectury.networking.NetworkManager; import dev.ftb.mods.ftbultimine.config.FTBUltimineServerConfig; import dev.ftb.mods.ftbultimine.net.SendShapePacket; import dev.ftb.mods.ftbultimine.shape.BlockMatcher; import dev.ftb.mods.ftbultimine.shape.Shape; import dev.ftb.mods.ftbultimine.shape.ShapeContext; import dev.ftb.mods.ftbultimine.shape.ShapeRegistry; -import dev.ftb.mods.ftbultimine.utils.PlatformMethods; import net.minecraft.commands.CommandSourceStack; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; @@ -65,7 +66,7 @@ public Collection cachedPositions() { } public static HitResult rayTrace(ServerPlayer player) { - double distance = PlatformMethods.reach(player); + double distance = player.getAttributeValue(Attributes.BLOCK_INTERACTION_RANGE); return player.pick(player.isCreative() ? distance + 0.5D : distance, 1F, false); } @@ -116,7 +117,7 @@ public void checkBlocks(ServerPlayer player, boolean sendUpdate, int maxBlocks) clearCache(); if (sendUpdate) { - new SendShapePacket(getCurrentShapeIndex(), Collections.emptyList()).sendTo(player); + NetworkManager.sendToPlayer(player, new SendShapePacket(getCurrentShapeIndex(), Collections.emptyList())); } } @@ -159,7 +160,7 @@ public ShapeContext updateBlocks(ServerPlayer player, BlockPos pos, Direction di } if (sendUpdate) { - new SendShapePacket(getCurrentShapeIndex(), cachedBlocks).sendTo(player); + NetworkManager.sendToPlayer(player, new SendShapePacket(getCurrentShapeIndex(), cachedBlocks)); } return context; diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/ItemCollection.java b/common/src/main/java/dev/ftb/mods/ftbultimine/ItemCollection.java index 68bb4eb..3d21f32 100755 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/ItemCollection.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/ItemCollection.java @@ -1,6 +1,5 @@ package dev.ftb.mods.ftbultimine; -import dev.ftb.mods.ftbultimine.utils.ItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; @@ -8,7 +7,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Objects; public class ItemCollection { private final List items = new ArrayList<>(); @@ -56,40 +54,51 @@ public void drop(Level world, BlockPos pos) { } private ItemStack insert(List stacks, ItemStack stack, int slot) { - ItemStack existing = stacks.get(slot); - - if (stack.isEmpty() || existing.isEmpty() || stack.getItem() != existing.getItem()) { - return stack; + if (stack.isEmpty()) { + return ItemStack.EMPTY; // degenerate case } - // intellij doesn't like that we throw something here - //noinspection ConstantConditions - if (!stack.isStackable() || !Objects.equals(stack.getTag(), existing.getTag()) || !ItemUtils.areCompatible(stack, existing)) { - return stack; - } - - int limit = stack.getMaxStackSize(); - - if (!existing.isEmpty()) { - if (!ItemUtils.canItemStacksStack(stack, existing)) { - return stack; - } + ItemStack existing = stacks.get(slot); - limit -= existing.getCount(); + if (existing.isEmpty()) { + // trivial case, just put the stack in the slot + stacks.set(slot, stack.copy()); + return ItemStack.EMPTY; } - if (limit <= 0) { + if (!stack.isStackable() || !ItemStack.isSameItemSameComponents(stack, existing)) { + // stack doesn't fit here return stack; } - boolean reachedLimit = stack.getCount() > limit; - - if (existing.isEmpty()) { - stacks.set(slot, reachedLimit ? stack.copyWithCount(limit) : stack); - } else { - existing.grow(reachedLimit ? limit : stack.getCount()); - } - - return reachedLimit ? stack.copyWithCount(stack.getCount() - limit) : ItemStack.EMPTY; + // the slot is not empty, and is compatible with the stack to be inserted + // - so at least some of it can be inserted + int available = stack.getMaxStackSize() - existing.getCount(); + int toAdd = Math.min(available, stack.getCount()); + existing.grow(toAdd); + + return toAdd == stack.getCount() ? ItemStack.EMPTY : stack.copyWithCount(stack.getCount() - toAdd); + +// if (!existing.isEmpty()) { +// if (!ItemUtils.canItemStacksStack(stack, existing)) { +// return stack; +// } +// +// limit -= existing.getCount(); +// } +// +// if (limit <= 0) { +// return stack; +// } +// +// boolean reachedLimit = stack.getCount() > limit; +// +// if (existing.isEmpty()) { +// stacks.set(slot, reachedLimit ? stack.copyWithCount(limit) : stack); +// } else { +// existing.grow(reachedLimit ? limit : stack.getCount()); +// } +// +// return reachedLimit ? stack.copyWithCount(stack.getCount() - limit) : ItemStack.EMPTY; } } \ No newline at end of file diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/RightClickHandlers.java b/common/src/main/java/dev/ftb/mods/ftbultimine/RightClickHandlers.java index 7e7f303..acd8114 100644 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/RightClickHandlers.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/RightClickHandlers.java @@ -29,7 +29,7 @@ public class RightClickHandlers { static int axeStripping(ServerPlayer player, InteractionHand hand, BlockPos clickPos, FTBUltiminePlayerData data) { Set sounds = new HashSet<>(); - BrokenItemHandler brokenItemHandler = new BrokenItemHandler(); + BrokenItemHandler brokenItemHandler = new BrokenItemHandler(player); Level level = player.level(); ItemStack itemStack = player.getItemInHand(hand); @@ -59,7 +59,7 @@ static int axeStripping(ServerPlayer player, InteractionHand hand, BlockPos clic CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger(player, pos, itemStack); level.setBlock(pos, actual.get(), Block.UPDATE_ALL_IMMEDIATE); level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(player, actual.get())); - itemStack.hurtAndBreak(1, player, brokenItemHandler); + itemStack.hurtAndBreak(1, level.random, player, brokenItemHandler); if (brokenItemHandler.isBroken) { break; @@ -72,7 +72,7 @@ static int axeStripping(ServerPlayer player, InteractionHand hand, BlockPos clic static int shovelFlattening(ServerPlayer player, InteractionHand hand, BlockPos clickPos, FTBUltiminePlayerData data) { int didWork = 0; - BrokenItemHandler brokenItemHandler = new BrokenItemHandler(); + BrokenItemHandler brokenItemHandler = new BrokenItemHandler(player); for (BlockPos pos : data.cachedPositions()) { if (!player.level().getBlockState(pos.above()).isAir()) { @@ -88,7 +88,7 @@ static int shovelFlattening(ServerPlayer player, InteractionHand hand, BlockPos player.level().setBlock(pos, newState, Block.UPDATE_ALL_IMMEDIATE); didWork++; - player.getMainHandItem().hurtAndBreak(1, player, brokenItemHandler); + player.getMainHandItem().hurtAndBreak(1, player.getRandom(), player, brokenItemHandler); player.level().gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(player, newState)); if (brokenItemHandler.isBroken || player.getFoodData().getFoodLevel() <= 0) { break; @@ -107,7 +107,7 @@ static int shovelFlattening(ServerPlayer player, InteractionHand hand, BlockPos static int farmlandConversion(ServerPlayer player, InteractionHand hand, BlockPos clickPos, FTBUltiminePlayerData data) { int clicked = 0; - BrokenItemHandler brokenItemHandler = new BrokenItemHandler(); + BrokenItemHandler brokenItemHandler = new BrokenItemHandler(player); for (BlockPos pos : data.cachedPositions()) { if (!player.level().getBlockState(pos.above()).isAir()) { @@ -121,7 +121,7 @@ static int farmlandConversion(ServerPlayer player, InteractionHand hand, BlockPo if (!player.isCreative()) { player.causeFoodExhaustion((float) (FTBUltimineServerConfig.EXHAUSTION_PER_BLOCK.get() * 0.005D)); - player.getMainHandItem().hurtAndBreak(1, player, brokenItemHandler); + player.getMainHandItem().hurtAndBreak(1, player.getRandom(), player, brokenItemHandler); if (brokenItemHandler.isBroken || FTBUltimine.isTooExhausted(player)) { break; } diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/client/FTBUltimineClient.java b/common/src/main/java/dev/ftb/mods/ftbultimine/client/FTBUltimineClient.java index 6d3cef8..70b79de 100755 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/client/FTBUltimineClient.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/client/FTBUltimineClient.java @@ -10,6 +10,7 @@ import dev.architectury.event.events.client.ClientLifecycleEvent; import dev.architectury.event.events.client.ClientRawInputEvent; import dev.architectury.event.events.client.ClientTickEvent; +import dev.architectury.networking.NetworkManager; import dev.architectury.registry.client.keymappings.KeyMappingRegistry; import dev.ftb.mods.ftblibrary.config.ui.EditConfigScreen; import dev.ftb.mods.ftbultimine.CooldownTracker; @@ -143,7 +144,7 @@ public void renderInGame(PoseStack stack) { public EventResult onMouseScrolled(Minecraft client, double amountX, double amountY) { if (pressed && (amountY != 0 || amountX != 0) && sneak()) { hasScrolled = true; - new ModeChangedPacket(amountX < 0D || amountY < 0D).sendToServer(); + NetworkManager.sendToServer(new ModeChangedPacket(amountX < 0D || amountY < 0D)); return EventResult.interruptFalse(); } @@ -164,7 +165,7 @@ public EventResult onKeyPress(Minecraft client, int keyCode, int scanCode, int a } hasScrolled = true; - new ModeChangedPacket(keyCode == InputConstants.KEY_DOWN).sendToServer(); + NetworkManager.sendToServer(new ModeChangedPacket(keyCode == InputConstants.KEY_DOWN)); lastToggle = System.currentTimeMillis(); return EventResult.pass(); } @@ -280,7 +281,7 @@ public void clientTick(Minecraft mc) { boolean p = pressed; if ((pressed = keyBinding.isDown()) != p) { - new KeyPressedPacket(pressed).sendToServer(); + NetworkManager.sendToServer(new KeyPressedPacket(pressed)); } canUltimine = pressed && FTBUltimine.instance.canUltimine(mc.player); diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/config/FTBUltimineServerConfig.java b/common/src/main/java/dev/ftb/mods/ftbultimine/config/FTBUltimineServerConfig.java index c1dc83b..06a6a65 100755 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/config/FTBUltimineServerConfig.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/config/FTBUltimineServerConfig.java @@ -1,5 +1,6 @@ package dev.ftb.mods.ftbultimine.config; +import dev.architectury.networking.NetworkManager; import dev.ftb.mods.ftblibrary.config.ConfigGroup; import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag; import dev.ftb.mods.ftblibrary.snbt.config.*; @@ -98,7 +99,7 @@ static ConfigGroup getConfigGroup() { clearTagCache(); SNBTCompoundTag config = new SNBTCompoundTag(); FTBUltimineServerConfig.CONFIG.write(config); - new SyncConfigToServerPacket(config).sendToServer(); + NetworkManager.sendToServer(new SyncConfigToServerPacket(config)); } }); CONFIG.createClientConfig(group); diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/integration/FTBRanksIntegration.java b/common/src/main/java/dev/ftb/mods/ftbultimine/integration/FTBRanksIntegration.java index 7df1a30..cc853b0 100644 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/integration/FTBRanksIntegration.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/integration/FTBRanksIntegration.java @@ -1,5 +1,6 @@ package dev.ftb.mods.ftbultimine.integration; +import dev.architectury.networking.NetworkManager; import dev.ftb.mods.ftbranks.api.FTBRanksAPI; import dev.ftb.mods.ftbranks.api.event.RankEvent; import dev.ftb.mods.ftbultimine.FTBUltimine; @@ -25,13 +26,13 @@ public static void init() { private static void updatePlayer(RankEvent.Player event) { ServerPlayer sp = event.getManager().getServer().getPlayerList().getPlayer(event.getPlayer().getId()); if (sp != null) { - new SyncUltimineTimePacket(FTBUltimineServerConfig.getUltimineCooldown(sp), TimeType.COOLDOWN).sendTo(sp); + NetworkManager.sendToPlayer(sp, new SyncUltimineTimePacket(FTBUltimineServerConfig.getUltimineCooldown(sp), TimeType.COOLDOWN)); } } private static void updateAllPlayers(RankEvent event) { event.getManager().getServer().getPlayerList().getPlayers().forEach(sp -> { - new SyncUltimineTimePacket(FTBUltimineServerConfig.getUltimineCooldown(sp), TimeType.COOLDOWN).sendTo(sp); + NetworkManager.sendToPlayer(sp, new SyncUltimineTimePacket(FTBUltimineServerConfig.getUltimineCooldown(sp), TimeType.COOLDOWN)); }); } diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/net/EditConfigPacket.java b/common/src/main/java/dev/ftb/mods/ftbultimine/net/EditConfigPacket.java index adbf948..4725303 100644 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/net/EditConfigPacket.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/net/EditConfigPacket.java @@ -1,34 +1,26 @@ package dev.ftb.mods.ftbultimine.net; import dev.architectury.networking.NetworkManager; -import dev.architectury.networking.simple.BaseS2CMessage; -import dev.architectury.networking.simple.MessageType; import dev.ftb.mods.ftbultimine.FTBUltimine; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -public class EditConfigPacket extends BaseS2CMessage { - private final boolean isClientConfig; +public record EditConfigPacket(boolean isClientConfig) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(FTBUltimine.rl("edit_config_packet")); - public EditConfigPacket(boolean isClientConfig) { - this.isClientConfig = isClientConfig; - } - - public EditConfigPacket(FriendlyByteBuf buf) { - isClientConfig = buf.readBoolean(); - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.BOOL, EditConfigPacket::isClientConfig, + EditConfigPacket::new + ); @Override - public MessageType getType() { - return FTBUltimineNet.EDIT_CONFIG; + public Type type() { + return TYPE; } - @Override - public void write(FriendlyByteBuf buf) { - buf.writeBoolean(isClientConfig); - } - - @Override - public void handle(NetworkManager.PacketContext context) { - FTBUltimine.instance.proxy.editConfig(isClientConfig); + public static void handle(EditConfigPacket message, NetworkManager.PacketContext context) { + context.queue(() -> FTBUltimine.instance.proxy.editConfig(message.isClientConfig)); } } diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/net/FTBUltimineNet.java b/common/src/main/java/dev/ftb/mods/ftbultimine/net/FTBUltimineNet.java index cc36316..2482c51 100755 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/net/FTBUltimineNet.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/net/FTBUltimineNet.java @@ -1,20 +1,16 @@ package dev.ftb.mods.ftbultimine.net; -import dev.architectury.networking.simple.MessageType; -import dev.architectury.networking.simple.SimpleNetworkManager; -import dev.ftb.mods.ftbultimine.FTBUltimine; +import dev.ftb.mods.ftblibrary.util.NetworkHelper; -public interface FTBUltimineNet { - SimpleNetworkManager NET = SimpleNetworkManager.create(FTBUltimine.MOD_ID); +public class FTBUltimineNet { + public static void init() { + NetworkHelper.registerS2C(SendShapePacket.TYPE, SendShapePacket.STREAM_CODEC, SendShapePacket::handle); + NetworkHelper.registerS2C(SyncConfigFromServerPacket.TYPE, SyncConfigFromServerPacket.STREAM_CODEC, SyncConfigFromServerPacket::handle); + NetworkHelper.registerS2C(EditConfigPacket.TYPE, EditConfigPacket.STREAM_CODEC, EditConfigPacket::handle); + NetworkHelper.registerS2C(SyncUltimineTimePacket.TYPE, SyncUltimineTimePacket.STREAM_CODEC, SyncUltimineTimePacket::handle); - MessageType SEND_SHAPE = NET.registerS2C("send_shape", SendShapePacket::new); - MessageType KEY_PRESSED = NET.registerC2S("key_pressed", KeyPressedPacket::new); - MessageType MODE_CHANGED = NET.registerC2S("mode_changed", ModeChangedPacket::new); - MessageType SYNC_CONFIG_FROM_SERVER = NET.registerS2C("sync_config_from_server", SyncConfigFromServerPacket::new); - MessageType SYNC_CONFIG_TO_SERVER = NET.registerC2S("sync_config_to_server", SyncConfigToServerPacket::new); - MessageType EDIT_CONFIG = NET.registerS2C("edit_config", EditConfigPacket::new); - MessageType SYNC_ULTIMINE_TIME = NET.registerS2C("sync_ultimine_time", SyncUltimineTimePacket::new); - - static void init() { + NetworkHelper.registerC2S(KeyPressedPacket.TYPE, KeyPressedPacket.STREAM_CODEC, KeyPressedPacket::handle); + NetworkHelper.registerC2S(ModeChangedPacket.TYPE, ModeChangedPacket.STREAM_CODEC, ModeChangedPacket::handle); + NetworkHelper.registerC2S(SyncConfigToServerPacket.TYPE, SyncConfigToServerPacket.STREAM_CODEC, SyncConfigToServerPacket::handle); } } \ No newline at end of file diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/net/KeyPressedPacket.java b/common/src/main/java/dev/ftb/mods/ftbultimine/net/KeyPressedPacket.java old mode 100755 new mode 100644 index 0ae99c6..7ec5b38 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/net/KeyPressedPacket.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/net/KeyPressedPacket.java @@ -1,34 +1,27 @@ package dev.ftb.mods.ftbultimine.net; import dev.architectury.networking.NetworkManager; -import dev.architectury.networking.simple.BaseC2SMessage; -import dev.architectury.networking.simple.MessageType; import dev.ftb.mods.ftbultimine.FTBUltimine; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.server.level.ServerPlayer; -public class KeyPressedPacket extends BaseC2SMessage { - private final boolean pressed; +public record KeyPressedPacket(boolean pressed) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(FTBUltimine.rl("key_pressed_packet")); - public KeyPressedPacket(boolean p) { - pressed = p; - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.BOOL, KeyPressedPacket::pressed, + KeyPressedPacket::new + ); - public KeyPressedPacket(FriendlyByteBuf buf) { - pressed = buf.readBoolean(); - } + @Override + public Type type() { + return TYPE; + } - public void write(FriendlyByteBuf buf) { - buf.writeBoolean(pressed); - } - - @Override - public MessageType getType() { - return FTBUltimineNet.KEY_PRESSED; - } - - @Override - public void handle(NetworkManager.PacketContext context) { - context.queue(() -> FTBUltimine.instance.setKeyPressed((ServerPlayer) context.getPlayer(), pressed)); - } + public static void handle(KeyPressedPacket message, NetworkManager.PacketContext context) { + context.queue(() -> FTBUltimine.instance.setKeyPressed((ServerPlayer) context.getPlayer(), message.pressed)); + } } \ No newline at end of file diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/net/ModeChangedPacket.java b/common/src/main/java/dev/ftb/mods/ftbultimine/net/ModeChangedPacket.java old mode 100755 new mode 100644 index 09b26fd..f2d1a37 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/net/ModeChangedPacket.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/net/ModeChangedPacket.java @@ -1,34 +1,27 @@ package dev.ftb.mods.ftbultimine.net; import dev.architectury.networking.NetworkManager; -import dev.architectury.networking.simple.BaseC2SMessage; -import dev.architectury.networking.simple.MessageType; import dev.ftb.mods.ftbultimine.FTBUltimine; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.server.level.ServerPlayer; -public class ModeChangedPacket extends BaseC2SMessage { - public final boolean next; +public record ModeChangedPacket(boolean next) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(FTBUltimine.rl("mode_changed_packet")); - public ModeChangedPacket(boolean n) { - next = n; - } - - public ModeChangedPacket(FriendlyByteBuf buf) { - next = buf.readBoolean(); - } - - public void write(FriendlyByteBuf buf) { - buf.writeBoolean(next); - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.BOOL, ModeChangedPacket::next, + ModeChangedPacket::new + ); @Override - public MessageType getType() { - return FTBUltimineNet.MODE_CHANGED; + public Type type() { + return TYPE; } - @Override - public void handle(NetworkManager.PacketContext context) { - context.queue(() -> FTBUltimine.instance.modeChanged((ServerPlayer) context.getPlayer(), next)); + public static void handle(ModeChangedPacket message, NetworkManager.PacketContext context) { + context.queue(() -> FTBUltimine.instance.modeChanged((ServerPlayer) context.getPlayer(), message.next)); } } \ No newline at end of file diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/net/SendShapePacket.java b/common/src/main/java/dev/ftb/mods/ftbultimine/net/SendShapePacket.java old mode 100755 new mode 100644 index acd7252..9d6e1e2 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/net/SendShapePacket.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/net/SendShapePacket.java @@ -1,55 +1,32 @@ package dev.ftb.mods.ftbultimine.net; import dev.architectury.networking.NetworkManager; -import dev.architectury.networking.simple.BaseS2CMessage; -import dev.architectury.networking.simple.MessageType; import dev.ftb.mods.ftbultimine.FTBUltimine; -import dev.ftb.mods.ftbultimine.client.FTBUltimineClient; -import dev.ftb.mods.ftbultimine.shape.Shape; -import dev.ftb.mods.ftbultimine.shape.ShapeRegistry; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import java.util.ArrayList; import java.util.List; -public class SendShapePacket extends BaseS2CMessage { - private final int shapeIdx; - private final List blocks; +public record SendShapePacket(int shapeIdx, List blocks) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(FTBUltimine.rl("send_shape_packet")); - public SendShapePacket(int idx, List b) { - shapeIdx = idx; - blocks = b; - } - - public SendShapePacket(FriendlyByteBuf buf) { - shapeIdx = buf.readVarInt(); - int s = buf.readVarInt(); - blocks = new ArrayList<>(s); - - for (int i = 0; i < s; i++) { - blocks.add(buf.readBlockPos()); - } - } - - public void write(FriendlyByteBuf buf) { - buf.writeVarInt(shapeIdx); - buf.writeVarInt(blocks.size()); - - for (BlockPos pos : blocks) { - buf.writeBlockPos(pos); - } - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.VAR_INT, SendShapePacket::shapeIdx, + BlockPos.STREAM_CODEC.apply(ByteBufCodecs.list()), SendShapePacket::blocks, + SendShapePacket::new + ); @Override - public MessageType getType() { - return FTBUltimineNet.SEND_SHAPE; + public Type type() { + return TYPE; } - @Override - public void handle(NetworkManager.PacketContext context) { + public static void handle(SendShapePacket message, NetworkManager.PacketContext context) { context.queue(() -> { - FTBUltimine.instance.proxy.setShape(shapeIdx, blocks); + FTBUltimine.instance.proxy.setShape(message.shapeIdx, message.blocks); }); } } diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/net/SyncConfigFromServerPacket.java b/common/src/main/java/dev/ftb/mods/ftbultimine/net/SyncConfigFromServerPacket.java index 2cf43ce..5fde4a4 100644 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/net/SyncConfigFromServerPacket.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/net/SyncConfigFromServerPacket.java @@ -1,38 +1,30 @@ package dev.ftb.mods.ftbultimine.net; import dev.architectury.networking.NetworkManager; -import dev.architectury.networking.simple.BaseS2CMessage; -import dev.architectury.networking.simple.MessageType; import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag; -import dev.ftb.mods.ftblibrary.snbt.SNBTNet; import dev.ftb.mods.ftbultimine.FTBUltimine; import dev.ftb.mods.ftbultimine.config.FTBUltimineServerConfig; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -public class SyncConfigFromServerPacket extends BaseS2CMessage { - private final SNBTCompoundTag config; +public record SyncConfigFromServerPacket(SNBTCompoundTag config) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(FTBUltimine.rl("sync_config_from_server_packet")); - public SyncConfigFromServerPacket(SNBTCompoundTag config) { - this.config = config; - } - - public SyncConfigFromServerPacket(FriendlyByteBuf buf) { - config = SNBTNet.readCompound(buf); - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + SNBTCompoundTag.STREAM_CODEC, SyncConfigFromServerPacket::config, + SyncConfigFromServerPacket::new + ); @Override - public MessageType getType() { - return FTBUltimineNet.SYNC_CONFIG_FROM_SERVER; + public Type type() { + return TYPE; } - @Override - public void write(FriendlyByteBuf buf) { - SNBTNet.writeCompound(buf, config); - } - - @Override - public void handle(NetworkManager.PacketContext context) { - FTBUltimineServerConfig.CONFIG.read(config); - FTBUltimine.LOGGER.info("received server config settings"); + public static void handle(SyncConfigFromServerPacket message, NetworkManager.PacketContext context) { + context.queue(() -> { + FTBUltimineServerConfig.CONFIG.read(message.config); + FTBUltimine.LOGGER.info("received server config settings"); + }); } } diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/net/SyncConfigToServerPacket.java b/common/src/main/java/dev/ftb/mods/ftbultimine/net/SyncConfigToServerPacket.java index 6459c8e..5edcddb 100644 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/net/SyncConfigToServerPacket.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/net/SyncConfigToServerPacket.java @@ -1,59 +1,51 @@ package dev.ftb.mods.ftbultimine.net; import dev.architectury.networking.NetworkManager; -import dev.architectury.networking.simple.BaseC2SMessage; -import dev.architectury.networking.simple.MessageType; import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag; -import dev.ftb.mods.ftblibrary.snbt.SNBTNet; import dev.ftb.mods.ftblibrary.snbt.config.ConfigUtil; import dev.ftb.mods.ftbultimine.FTBUltimine; import dev.ftb.mods.ftbultimine.config.FTBUltimineServerConfig; import dev.ftb.mods.ftbultimine.net.SyncUltimineTimePacket.TimeType; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import java.nio.file.Path; -public class SyncConfigToServerPacket extends BaseC2SMessage { - private final SNBTCompoundTag config; +public record SyncConfigToServerPacket(SNBTCompoundTag config) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(FTBUltimine.rl("sync_config_to_server_packet")); - public SyncConfigToServerPacket(SNBTCompoundTag config) { - this.config = config; - } - - public SyncConfigToServerPacket(FriendlyByteBuf buf) { - config = SNBTNet.readCompound(buf); - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + SNBTCompoundTag.STREAM_CODEC, SyncConfigToServerPacket::config, + SyncConfigToServerPacket::new + ); @Override - public MessageType getType() { - return FTBUltimineNet.SYNC_CONFIG_TO_SERVER; + public Type type() { + return TYPE; } - @Override - public void write(FriendlyByteBuf buf) { - SNBTNet.writeCompound(buf, config); - } - - @Override - public void handle(NetworkManager.PacketContext context) { + public static void handle(SyncConfigToServerPacket message, NetworkManager.PacketContext context) { if (context.getPlayer() instanceof ServerPlayer sp && sp.hasPermissions(2)) { - MinecraftServer server = sp.getServer(); + context.queue(() -> { + MinecraftServer server = sp.getServer(); - FTBUltimine.LOGGER.info("Server config updated from client by player {}", sp.getName().getString()); - FTBUltimineServerConfig.CONFIG.read(config); - FTBUltimineServerConfig.clearTagCache(); + FTBUltimine.LOGGER.info("Server config updated from client by player {}", sp.getName().getString()); + FTBUltimineServerConfig.CONFIG.read(message.config); + FTBUltimineServerConfig.clearTagCache(); - Path file = server.getWorldPath(ConfigUtil.SERVER_CONFIG_DIR).resolve(FTBUltimineServerConfig.CONFIG.key + ".snbt"); - FTBUltimineServerConfig.CONFIG.save(file); + Path file = server.getWorldPath(ConfigUtil.SERVER_CONFIG_DIR).resolve(FTBUltimineServerConfig.CONFIG.key + ".snbt"); + FTBUltimineServerConfig.CONFIG.save(file); - for (ServerPlayer player : server.getPlayerList().getPlayers()) { - if (!sp.getUUID().equals(player.getUUID())) { - new SyncConfigFromServerPacket(config).sendTo(player); + for (ServerPlayer player : server.getPlayerList().getPlayers()) { + if (!sp.getUUID().equals(player.getUUID())) { + NetworkManager.sendToPlayer(player, new SyncConfigFromServerPacket(message.config)); + } + NetworkManager.sendToPlayer(player, new SyncUltimineTimePacket(FTBUltimineServerConfig.getUltimineCooldown(player), TimeType.COOLDOWN)); } - new SyncUltimineTimePacket(FTBUltimineServerConfig.getUltimineCooldown(player), TimeType.COOLDOWN).sendTo(player); - } + }); } } } diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/net/SyncUltimineTimePacket.java b/common/src/main/java/dev/ftb/mods/ftbultimine/net/SyncUltimineTimePacket.java index 5898746..d8bce52 100644 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/net/SyncUltimineTimePacket.java +++ b/common/src/main/java/dev/ftb/mods/ftbultimine/net/SyncUltimineTimePacket.java @@ -1,43 +1,36 @@ package dev.ftb.mods.ftbultimine.net; import dev.architectury.networking.NetworkManager; -import dev.architectury.networking.simple.BaseS2CMessage; -import dev.architectury.networking.simple.MessageType; +import dev.ftb.mods.ftblibrary.util.NetworkHelper; import dev.ftb.mods.ftbultimine.CooldownTracker; +import dev.ftb.mods.ftbultimine.FTBUltimine; import dev.ftb.mods.ftbultimine.client.FTBUltimineClient; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -public class SyncUltimineTimePacket extends BaseS2CMessage { - private final long when; - private final TimeType timetype; +public record SyncUltimineTimePacket(long when, TimeType timetype) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(FTBUltimine.rl("sync_ultimine_time_packet")); - public SyncUltimineTimePacket(FriendlyByteBuf buf) { - this.when = buf.readLong(); - this.timetype = buf.readEnum(TimeType.class); - } - - public SyncUltimineTimePacket(long when, TimeType timetype) { - this.when = when; - this.timetype = timetype; - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.VAR_LONG, SyncUltimineTimePacket::when, + NetworkHelper.enumStreamCodec(TimeType.class), SyncUltimineTimePacket::timetype, + SyncUltimineTimePacket::new + ); @Override - public MessageType getType() { - return FTBUltimineNet.SYNC_ULTIMINE_TIME; + public Type type() { + return TYPE; } - @Override - public void write(FriendlyByteBuf buf) { - buf.writeLong(when); - buf.writeEnum(timetype); - } - - @Override - public void handle(NetworkManager.PacketContext context) { - switch (timetype) { - case LAST_USED -> CooldownTracker.setLastUltimineTime(FTBUltimineClient.getClientPlayer(), when); - case COOLDOWN -> CooldownTracker.setClientCooldownTime(when); - } + public static void handle(SyncUltimineTimePacket message, NetworkManager.PacketContext context) { + context.queue(() -> { + switch (message.timetype) { + case LAST_USED -> CooldownTracker.setLastUltimineTime(FTBUltimineClient.getClientPlayer(), message.when); + case COOLDOWN -> CooldownTracker.setClientCooldownTime(message.when); + } + }); } public enum TimeType { diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/utils/ItemUtils.java b/common/src/main/java/dev/ftb/mods/ftbultimine/utils/ItemUtils.java deleted file mode 100755 index 8cfe4f0..0000000 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/utils/ItemUtils.java +++ /dev/null @@ -1,16 +0,0 @@ -package dev.ftb.mods.ftbultimine.utils; - -import dev.architectury.injectables.annotations.ExpectPlatform; -import net.minecraft.world.item.ItemStack; - -public class ItemUtils { - @ExpectPlatform - public static boolean canItemStacksStack(ItemStack a, ItemStack b) { - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean areCompatible(ItemStack a, ItemStack b) { - throw new AssertionError(); - } -} diff --git a/common/src/main/java/dev/ftb/mods/ftbultimine/utils/PlatformMethods.java b/common/src/main/java/dev/ftb/mods/ftbultimine/utils/PlatformMethods.java deleted file mode 100755 index d41c0b8..0000000 --- a/common/src/main/java/dev/ftb/mods/ftbultimine/utils/PlatformMethods.java +++ /dev/null @@ -1,11 +0,0 @@ -package dev.ftb.mods.ftbultimine.utils; - -import dev.architectury.injectables.annotations.ExpectPlatform; -import net.minecraft.server.level.ServerPlayer; - -public class PlatformMethods { - @ExpectPlatform - public static double reach(ServerPlayer player) { - throw new AssertionError(); - } -} diff --git a/fabric/src/main/java/dev/ftb/mods/ftbultimine/utils/fabric/ItemUtilsImpl.java b/fabric/src/main/java/dev/ftb/mods/ftbultimine/utils/fabric/ItemUtilsImpl.java deleted file mode 100755 index f4c9a9a..0000000 --- a/fabric/src/main/java/dev/ftb/mods/ftbultimine/utils/fabric/ItemUtilsImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package dev.ftb.mods.ftbultimine.utils.fabric; - -import net.minecraft.world.item.ItemStack; - -public class ItemUtilsImpl { - public static boolean canItemStacksStack(ItemStack a, ItemStack b) { - if (!a.isEmpty() && !b.isEmpty() && a.getItem() == b.getItem()) { - if (!a.isStackable()) { - return false; - } else if (a.hasTag() != b.hasTag()) { - return false; - } else { - return (!a.hasTag() || a.getTag().equals(b.getTag())) && areCompatible(a, b); - } - } else { - return false; - } - } - - public static boolean areCompatible(ItemStack a, ItemStack b) { - return true; - } -} diff --git a/fabric/src/main/java/dev/ftb/mods/ftbultimine/utils/fabric/PlatformMethodsImpl.java b/fabric/src/main/java/dev/ftb/mods/ftbultimine/utils/fabric/PlatformMethodsImpl.java deleted file mode 100755 index 80e0eb2..0000000 --- a/fabric/src/main/java/dev/ftb/mods/ftbultimine/utils/fabric/PlatformMethodsImpl.java +++ /dev/null @@ -1,9 +0,0 @@ -package dev.ftb.mods.ftbultimine.utils.fabric; - -import net.minecraft.server.level.ServerPlayer; - -public class PlatformMethodsImpl { - public static double reach(ServerPlayer player) { - return 5.0; - } -} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index fb25509..6c51e1b 100755 --- a/gradle.properties +++ b/gradle.properties @@ -1,24 +1,24 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -mod_version=2004.1.0 +mod_version=2006.1.0 maven_group=dev.ftb.mods mod_id=ftbultimine archives_base_name=ftb-ultimine readable_name=FTB Ultimine mod_author=FTB Team -minecraft_version=1.20.4 +minecraft_version=1.20.6 -forge_version=49.0.31 -neoforge_version=20.4.196 +forge_version=50.0.9 +neoforge_version=20.6.49-beta neoforge_loader_version=1 -fabric_loader_version=0.15.7 -fabric_api_version=0.96.4+1.20.4 -architectury_version=11.1.17 +fabric_loader_version=0.15.10 +fabric_api_version=0.97.8+1.20.6 +architectury_version=12.0.28 -ftb_library_version=2004.2.0 -ftb_ranks_version=2004.2.0 +ftb_library_version=2006.1.0-SNAPSHOT +ftb_ranks_version=2006.1.0-SNAPSHOT curseforge_id_forge=386134 curseforge_id_fabric=448231 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4d6272d..4518132 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip diff --git a/neoforge/build.gradle b/neoforge/build.gradle index a907215..7abbe7e 100755 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -42,7 +42,7 @@ apply from: "https://raw.githubusercontent.com/FTBTeam/mods-meta/main/gradle/ext processResources { inputs.property "version", project.version - filesMatching("META-INF/mods.toml") { + filesMatching("META-INF/neoforge.mods.toml") { expand "version": project.version, "archversion": project.architectury_version, "neoforgeversion": project.neoforge_version, diff --git a/neoforge/src/main/java/dev/ftb/mods/ftbultimine/utils/neoforge/ItemUtilsImpl.java b/neoforge/src/main/java/dev/ftb/mods/ftbultimine/utils/neoforge/ItemUtilsImpl.java deleted file mode 100755 index 58e26f9..0000000 --- a/neoforge/src/main/java/dev/ftb/mods/ftbultimine/utils/neoforge/ItemUtilsImpl.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.ftb.mods.ftbultimine.utils.neoforge; - -import net.minecraft.world.item.ItemStack; -import net.neoforged.neoforge.items.ItemHandlerHelper; - -public class ItemUtilsImpl { - public static boolean canItemStacksStack(ItemStack a, ItemStack b) { - return ItemHandlerHelper.canItemStacksStack(a, b); - } - - public static boolean areCompatible(ItemStack a, ItemStack b) { - return a.areAttachmentsCompatible(b); - } -} diff --git a/neoforge/src/main/java/dev/ftb/mods/ftbultimine/utils/neoforge/PlatformMethodsImpl.java b/neoforge/src/main/java/dev/ftb/mods/ftbultimine/utils/neoforge/PlatformMethodsImpl.java deleted file mode 100755 index 62d86b7..0000000 --- a/neoforge/src/main/java/dev/ftb/mods/ftbultimine/utils/neoforge/PlatformMethodsImpl.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.ftb.mods.ftbultimine.utils.neoforge; - -import net.minecraft.server.level.ServerPlayer; -import net.neoforged.neoforge.common.NeoForgeMod; - -public class PlatformMethodsImpl { - public static double reach(ServerPlayer player) { - return player.getAttributeValue(NeoForgeMod.BLOCK_REACH.value()); - } -} diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml similarity index 100% rename from neoforge/src/main/resources/META-INF/mods.toml rename to neoforge/src/main/resources/META-INF/neoforge.mods.toml diff --git a/settings.gradle b/settings.gradle index e7b8121..a1c4bcf 100755 --- a/settings.gradle +++ b/settings.gradle @@ -1,8 +1,8 @@ pluginManagement { repositories { maven { url "https://maven.fabricmc.net/" } - maven { url "https://maven.creeperhost.net/" } maven { url "https://maven.architectury.dev" } + maven { url "https://maven.creeperhost.net/" } maven { url "https://server.bbkr.space/artifactory/libs-release" } mavenCentral() gradlePluginPortal() @@ -10,6 +10,6 @@ pluginManagement { } } -include "common", "fabric", "forge", "neoforge" +include "common", "fabric", /*"forge",*/ "neoforge" -rootProject.name = 'FTB-Ultimine-1.20.4' +rootProject.name = 'FTB-Ultimine-1.20.6' From 4640921853222130af542fedc2e8199eb1d511bc Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Tue, 21 May 2024 09:29:00 +0100 Subject: [PATCH 6/7] build: bumped arch/neo/fabric versions --- gradle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6c51e1b..e5f0e63 100755 --- a/gradle.properties +++ b/gradle.properties @@ -11,11 +11,11 @@ mod_author=FTB Team minecraft_version=1.20.6 forge_version=50.0.9 -neoforge_version=20.6.49-beta +neoforge_version=20.6.72-beta neoforge_loader_version=1 fabric_loader_version=0.15.10 -fabric_api_version=0.97.8+1.20.6 -architectury_version=12.0.28 +fabric_api_version=0.99.0+1.20.6 +architectury_version=12.1.2 ftb_library_version=2006.1.0-SNAPSHOT ftb_ranks_version=2006.1.0-SNAPSHOT From 9bcce47f7d131c6bc9574ad39c98f4a0902331c3 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Mon, 10 Jun 2024 08:35:03 +0100 Subject: [PATCH 7/7] build: bumped dep versions, changelog updated --- CHANGELOG.md | 6 ++++++ gradle.properties | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 409dc36..2e7232f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2006.1.0] + +### Changed +* Ported to Minecraft 1.20.6. Support for Fabric and NeoForge. + * Forge support may be re-added if/when Architectury adds support for Forge + ## [2004.1.0] ### Added diff --git a/gradle.properties b/gradle.properties index e5f0e63..c5125a6 100755 --- a/gradle.properties +++ b/gradle.properties @@ -11,14 +11,14 @@ mod_author=FTB Team minecraft_version=1.20.6 forge_version=50.0.9 -neoforge_version=20.6.72-beta +neoforge_version=20.6.100-beta neoforge_loader_version=1 fabric_loader_version=0.15.10 fabric_api_version=0.99.0+1.20.6 -architectury_version=12.1.2 +architectury_version=12.1.3 -ftb_library_version=2006.1.0-SNAPSHOT -ftb_ranks_version=2006.1.0-SNAPSHOT +ftb_library_version=2006.1.1 +ftb_ranks_version=2006.1.0 curseforge_id_forge=386134 curseforge_id_fabric=448231