Skip to content

Commit

Permalink
Merge branch 'master' into 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Treetrain1 committed Sep 14, 2023
2 parents 8ecbc0d + 1309510 commit 6b74388
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 60 deletions.
10 changes: 7 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -403,7 +407,7 @@ tasks {
}
}

if (!(release == true || System.getenv("GITHUB_ACTIONS") == "true")) {
if (!(release == true || githubActions)) {
build.dependsOn(applyLicenses)
}

Expand Down Expand Up @@ -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())
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/frozenblock/lib/axe/mixin/AxeItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@
@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<InteractionResult> info, Level level, BlockPos blockPos, Player player, BlockState blockState, Optional<BlockState> optional, Optional <BlockState>optional2, Optional<BlockState> optional3, ItemStack itemStack, Optional<BlockState> 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<InteractionResult> cir, Level level, BlockPos blockPos, Player player, BlockState blockState, Optional<BlockState> optional, Optional<BlockState> optional2, Optional<BlockState> optional3, ItemStack itemStack, Optional<BlockState> optional4) {
Direction direction = context.getClickedFace();
Direction horizontal = context.getHorizontalDirection();
if (AxeBehaviors.AXE_BEHAVIORS.containsKey(blockState.getBlock())) {
if (AxeBehaviors.AXE_BEHAVIORS.get(blockState.getBlock()).axe(context, level, blockPos, blockState, direction, horizontal)) {
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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -76,71 +78,48 @@ public static ArrayList<SaveableCooldownInstance> readCooldowns(@NotNull Compoun
}

public static void setCooldowns(@NotNull ArrayList<SaveableCooldownInstance> 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<Item> 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<Item> 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<SaveableCooldownInstance> 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<SaveableCooldownInstance> 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);
int cooldownLeft = cooldownInstance.endTime - tickCount;
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;
}

}

}

0 comments on commit 6b74388

Please sign in to comment.