diff --git a/build.gradle.kts b/build.gradle.kts index 1fb9182cf..8af0fa62d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,6 +3,8 @@ import com.matthewprenger.cursegradle.CurseProject import com.matthewprenger.cursegradle.CurseRelation import groovy.xml.XmlSlurper import org.codehaus.groovy.runtime.ResourceGroovyMethods +import org.kohsuke.github.GHReleaseBuilder +import org.kohsuke.github.GitHub import java.io.FileInputStream import java.io.FileNotFoundException import java.net.URL @@ -70,6 +72,8 @@ val memoryleakfix_version: String by project val no_unused_chunks_version: String by project val ksyxis_version: String by project +val githubActions: Boolean = System.getenv("GITHUB_ACTIONS") == "true" + base { archivesName.set(archives_base_name) } @@ -403,7 +407,7 @@ tasks { } } -if (!(release == true || System.getenv("GITHUB_ACTIONS") == "true")) { +if (!(release == true || githubActions)) { build.dependsOn(applyLicenses) } @@ -593,10 +597,10 @@ val github by tasks.register("github") { } doLast { - val github = org.kohsuke.github.GitHub.connectUsingOAuth(token) + val github = GitHub.connectUsingOAuth(token) val repository = github.getRepository(repoVar) - val releaseBuilder = org.kohsuke.github.GHReleaseBuilder(repository, makeModrinthVersion(mod_version)) + val releaseBuilder = GHReleaseBuilder(repository, makeModrinthVersion(mod_version)) releaseBuilder.name(makeName(mod_version)) releaseBuilder.body(changelog_text) releaseBuilder.commitish(getBranch()) diff --git a/src/main/java/net/frozenblock/lib/axe/mixin/AxeItemMixin.java b/src/main/java/net/frozenblock/lib/axe/mixin/AxeItemMixin.java index 22947ebf7..b3ab458c4 100644 --- a/src/main/java/net/frozenblock/lib/axe/mixin/AxeItemMixin.java +++ b/src/main/java/net/frozenblock/lib/axe/mixin/AxeItemMixin.java @@ -41,8 +41,8 @@ @Mixin(AxeItem.class) public class AxeItemMixin { - @Inject(method = "useOn", at = @At(value = "INVOKE", target = "Ljava/util/Optional;isPresent()Z", ordinal = 0, shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) - public void frozenlib$_axeBehaviors(UseOnContext context, CallbackInfoReturnable info, Level level, BlockPos blockPos, Player player, BlockState blockState, Optional optional, Optional optional2, Optional optional3, ItemStack itemStack, Optional optional4) { + @Inject(method = "useOn", at = @At(value = "INVOKE", target = "Ljava/util/Optional;isPresent()Z", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) + public void frozenlib$_axeBehaviors(UseOnContext context, CallbackInfoReturnable cir, Level level, BlockPos blockPos, Player player, BlockState blockState, Optional optional, Optional optional2, Optional optional3, ItemStack itemStack, Optional optional4) { Direction direction = context.getClickedFace(); Direction horizontal = context.getHorizontalDirection(); if (AxeBehaviors.AXE_BEHAVIORS.containsKey(blockState.getBlock())) { @@ -50,12 +50,12 @@ public class AxeItemMixin { if (!level.isClientSide) { level.gameEvent(GameEvent.BLOCK_CHANGE, blockPos, GameEvent.Context.of(player, blockState)); if (player != null) { - context.getItemInHand().hurtAndBreak(1, player, (p) -> p.broadcastBreakEvent(context.getHand())); + context.getItemInHand().hurtAndBreak(1, player, p -> p.broadcastBreakEvent(context.getHand())); } CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger((ServerPlayer)player, blockPos, context.getItemInHand()); - info.setReturnValue(InteractionResult.SUCCESS); + cir.setReturnValue(InteractionResult.SUCCESS); } else { - info.setReturnValue(InteractionResult.sidedSuccess(true)); + cir.setReturnValue(InteractionResult.sidedSuccess(true)); } } } diff --git a/src/main/java/net/frozenblock/lib/item/impl/SaveableItemCooldowns.java b/src/main/java/net/frozenblock/lib/item/impl/SaveableItemCooldowns.java index 49558ede0..b0b608acd 100644 --- a/src/main/java/net/frozenblock/lib/item/impl/SaveableItemCooldowns.java +++ b/src/main/java/net/frozenblock/lib/item/impl/SaveableItemCooldowns.java @@ -22,6 +22,7 @@ import com.mojang.serialization.Dynamic; import com.mojang.serialization.codecs.RecordCodecBuilder; import io.netty.buffer.Unpooled; +import java.io.IOException; import java.util.ArrayList; import java.util.Optional; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; @@ -36,6 +37,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemCooldowns; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -76,51 +78,42 @@ public static ArrayList readCooldowns(@NotNull Compoun } public static void setCooldowns(@NotNull ArrayList saveableCooldownInstances, @NotNull ServerPlayer player) { - if (!player.level().isClientSide) { - ItemCooldowns itemCooldowns = player.getCooldowns(); - int tickCount = itemCooldowns.tickCount; - - FriendlyByteBuf tickCountByteBuf = new FriendlyByteBuf(Unpooled.buffer()); - tickCountByteBuf.writeInt(tickCount); - ServerPlayNetworking.send(player, FrozenMain.COOLDOWN_TICK_COUNT_PACKET, tickCountByteBuf); - - for (SaveableCooldownInstance saveableCooldownInstance : saveableCooldownInstances) { - int cooldownLeft = saveableCooldownInstance.getCooldownLeft(); - int startTime = tickCount - (saveableCooldownInstance.getTotalCooldownTime() - cooldownLeft); - int endTime = tickCount + cooldownLeft; - Optional optionalItem = BuiltInRegistries.ITEM.getOptional(saveableCooldownInstance.getItemResourceLocation()); - if (optionalItem.isPresent()) { - Item item = optionalItem.get(); - itemCooldowns.cooldowns.put(item, new ItemCooldowns.CooldownInstance(startTime, endTime)); - FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer()); - byteBuf.writeId(BuiltInRegistries.ITEM, item); - byteBuf.writeVarInt(startTime); - byteBuf.writeVarInt(endTime); - ServerPlayNetworking.send(player, FrozenMain.FORCED_COOLDOWN_PACKET, byteBuf); + try (Level level = player.level()) { + if (!level.isClientSide) { + ItemCooldowns itemCooldowns = player.getCooldowns(); + int tickCount = itemCooldowns.tickCount; + + FriendlyByteBuf tickCountByteBuf = new FriendlyByteBuf(Unpooled.buffer()); + tickCountByteBuf.writeInt(tickCount); + ServerPlayNetworking.send(player, FrozenMain.COOLDOWN_TICK_COUNT_PACKET, tickCountByteBuf); + + for (SaveableCooldownInstance saveableCooldownInstance : saveableCooldownInstances) { + int cooldownLeft = saveableCooldownInstance.cooldownLeft(); + int startTime = tickCount - (saveableCooldownInstance.totalCooldownTime() - cooldownLeft); + int endTime = tickCount + cooldownLeft; + Optional optionalItem = BuiltInRegistries.ITEM.getOptional(saveableCooldownInstance.itemResourceLocation()); + if (optionalItem.isPresent()) { + Item item = optionalItem.get(); + itemCooldowns.cooldowns.put(item, new ItemCooldowns.CooldownInstance(startTime, endTime)); + FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer()); + byteBuf.writeId(BuiltInRegistries.ITEM, item); + byteBuf.writeVarInt(startTime); + byteBuf.writeVarInt(endTime); + ServerPlayNetworking.send(player, FrozenMain.FORCED_COOLDOWN_PACKET, byteBuf); + } } } - } + } catch (IOException ignored) {} } - public static class SaveableCooldownInstance { + public record SaveableCooldownInstance(ResourceLocation itemResourceLocation, int cooldownLeft, int totalCooldownTime) { - private final ResourceLocation itemResourceLocation; - private final int cooldownLeft; - private final int totalCooldownTime; - - public static final Codec CODEC = RecordCodecBuilder.create((instance) -> instance.group( - ResourceLocation.CODEC.fieldOf("ItemResourceLocation").forGetter(SaveableCooldownInstance::getItemResourceLocation), - Codec.INT.fieldOf("CooldownLeft").orElse(0).forGetter(SaveableCooldownInstance::getCooldownLeft), - Codec.INT.fieldOf("TotalCooldownTime").orElse(0).forGetter(SaveableCooldownInstance::getTotalCooldownTime) + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ResourceLocation.CODEC.fieldOf("ItemResourceLocation").forGetter(SaveableCooldownInstance::itemResourceLocation), + Codec.INT.fieldOf("CooldownLeft").orElse(0).forGetter(SaveableCooldownInstance::cooldownLeft), + Codec.INT.fieldOf("TotalCooldownTime").orElse(0).forGetter(SaveableCooldownInstance::totalCooldownTime) ).apply(instance, SaveableCooldownInstance::new)); - - public SaveableCooldownInstance(ResourceLocation itemResourceLocation, int cooldownLeft, int totalCooldownTime) { - this.itemResourceLocation = itemResourceLocation; - this.cooldownLeft = cooldownLeft; - this.totalCooldownTime = totalCooldownTime; - } - @NotNull public static SaveableCooldownInstance makeFromCooldownInstance(@NotNull Item item, @NotNull ItemCooldowns.CooldownInstance cooldownInstance, int tickCount) { ResourceLocation resourceLocation = BuiltInRegistries.ITEM.getKey(item); @@ -128,19 +121,5 @@ public static SaveableCooldownInstance makeFromCooldownInstance(@NotNull Item it int totalCooldownTime = cooldownInstance.endTime - cooldownInstance.startTime; return new SaveableCooldownInstance(resourceLocation, cooldownLeft, totalCooldownTime); } - - public ResourceLocation getItemResourceLocation() { - return this.itemResourceLocation; - } - - public int getCooldownLeft() { - return this.cooldownLeft; - } - - public int getTotalCooldownTime() { - return this.totalCooldownTime; - } - } - }