Skip to content

Commit

Permalink
Merge branch 'master' into 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Treetrain1 committed Dec 14, 2023
2 parents 1fb75f9 + b00ff57 commit 28131bf
Show file tree
Hide file tree
Showing 25 changed files with 647 additions and 198 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Put changelog here:
- Moved all field annotations for config syncing to `EntrySyncData` for easier use
- Fixed a small bug with `Locked When Synced` fields syncing instead of remaining stagnant
- Added an additional tooltip to notify Server Operators and LAN Hosts when a config value will sync
- Moved most packets from channels to `FabricPacket`s
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.loader.api.FabricLoader;
import net.frozenblock.lib.FrozenLogUtils;
import net.frozenblock.lib.FrozenSharedConstants;
import net.frozenblock.lib.config.api.instance.Config;
import net.frozenblock.lib.config.api.instance.ConfigModification;
import net.frozenblock.lib.config.api.registry.ConfigRegistry;
Expand All @@ -55,7 +56,10 @@ public record ConfigSyncPacket<T>(

public static final int PERMISSION_LEVEL = 2;

public static final PacketType<ConfigSyncPacket<?>> PACKET_TYPE = PacketType.create(FrozenNetworking.CONFIG_SYNC_PACKET, ConfigSyncPacket::create);
public static final PacketType<ConfigSyncPacket<?>> PACKET_TYPE = PacketType.create(
FrozenSharedConstants.id("config_sync_packet"),
ConfigSyncPacket::create
);

@Nullable
public static <T> ConfigSyncPacket<T> create(@NotNull FriendlyByteBuf buf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void changeCooldown(@NotNull Player player, Item item, int additio
if (entry != null) {
int between = entry.endTime - entry.startTime;
if ((between + additionalCooldown) > min) {
((CooldownInterface)player.getCooldowns()).changeCooldown(item, additionalCooldown);
((CooldownInterface)player.getCooldowns()).frozenLib$changeCooldown(item, additionalCooldown);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

public interface CooldownInterface {

void changeCooldown(Item item, int additional);
void frozenLib$changeCooldown(Item item, int additional);

void onCooldownChanged(Item item, int additional);
void frozenLib$onCooldownChanged(Item item, int additional);

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.frozenblock.lib.FrozenSharedConstants;
import net.frozenblock.lib.config.frozenlib_config.FrozenLibConfig;
import net.frozenblock.lib.item.impl.network.CooldownTickCountPacket;
import net.frozenblock.lib.item.impl.network.ForcedCooldownPacket;
import net.frozenblock.lib.networking.FrozenNetworking;
import net.frozenblock.lib.tag.api.FrozenItemTags;
import net.minecraft.core.registries.BuiltInRegistries;
Expand Down Expand Up @@ -82,9 +84,7 @@ public static void setCooldowns(@NotNull List<SaveableCooldownInstance> saveable
ItemCooldowns itemCooldowns = player.getCooldowns();
int tickCount = itemCooldowns.tickCount;

FriendlyByteBuf tickCountByteBuf = new FriendlyByteBuf(Unpooled.buffer());
tickCountByteBuf.writeInt(tickCount);
ServerPlayNetworking.send(player, FrozenNetworking.COOLDOWN_TICK_COUNT_PACKET, tickCountByteBuf);
ServerPlayNetworking.send(player, new CooldownTickCountPacket(tickCount));

for (SaveableCooldownInstance saveableCooldownInstance : saveableCooldownInstances) {
int cooldownLeft = saveableCooldownInstance.cooldownLeft();
Expand All @@ -94,11 +94,7 @@ public static void setCooldowns(@NotNull List<SaveableCooldownInstance> saveable
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, FrozenNetworking.FORCED_COOLDOWN_PACKET, byteBuf);
ServerPlayNetworking.send(player, new ForcedCooldownPacket(item, startTime, endTime));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2023 FrozenBlock
* This file is part of FrozenLib.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/

package net.frozenblock.lib.item.impl.network;

import net.fabricmc.fabric.api.networking.v1.FabricPacket;
import net.fabricmc.fabric.api.networking.v1.PacketType;
import net.frozenblock.lib.FrozenSharedConstants;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.item.Item;

public record CooldownChangePacket(
Item item,
int additional
) implements FabricPacket {

public static final PacketType<CooldownChangePacket> PACKET_TYPE = PacketType.create(
FrozenSharedConstants.id("cooldown_change_packet"),
CooldownChangePacket::new
);

public CooldownChangePacket(FriendlyByteBuf buf) {
this(buf.readById(BuiltInRegistries.ITEM), buf.readVarInt());
}

@Override
public void write(FriendlyByteBuf buf) {
buf.writeId(BuiltInRegistries.ITEM, this.item());
buf.writeVarInt(this.additional());
}

@Override
public PacketType<?> getType() {
return PACKET_TYPE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2023 FrozenBlock
* This file is part of FrozenLib.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/

package net.frozenblock.lib.item.impl.network;

import net.fabricmc.fabric.api.networking.v1.FabricPacket;
import net.fabricmc.fabric.api.networking.v1.PacketType;
import net.frozenblock.lib.FrozenSharedConstants;
import net.minecraft.network.FriendlyByteBuf;

public record CooldownTickCountPacket(int count) implements FabricPacket {

public static final PacketType<CooldownTickCountPacket> PACKET_TYPE = PacketType.create(
FrozenSharedConstants.id("cooldown_tick_count_packet"),
CooldownTickCountPacket::new
);

public CooldownTickCountPacket(FriendlyByteBuf buf) {
this(buf.readInt());
}

@Override
public void write(FriendlyByteBuf buf) {
buf.writeInt(this.count());
}

@Override
public PacketType<?> getType() {
return PACKET_TYPE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2023 FrozenBlock
* This file is part of FrozenLib.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/

package net.frozenblock.lib.item.impl.network;

import net.fabricmc.fabric.api.networking.v1.FabricPacket;
import net.fabricmc.fabric.api.networking.v1.PacketType;
import net.frozenblock.lib.FrozenSharedConstants;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.item.Item;

public record ForcedCooldownPacket(
Item item,
int startTime,
int endTime
) implements FabricPacket {

public static final PacketType<ForcedCooldownPacket> PACKET_TYPE = PacketType.create(
FrozenSharedConstants.id("forced_cooldown_packet"),
ForcedCooldownPacket::new
);

public ForcedCooldownPacket(FriendlyByteBuf buf) {
this(buf.readById(BuiltInRegistries.ITEM), buf.readVarInt(), buf.readVarInt());
}


@Override
public void write(FriendlyByteBuf buf) {
buf.writeId(BuiltInRegistries.ITEM, this.item());
buf.writeVarInt(this.startTime());
buf.writeVarInt(this.endTime());
}

@Override
public PacketType<?> getType() {
return PACKET_TYPE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,16 @@ public class ItemCooldownsMixin implements CooldownInterface {

@Unique
@Override
public void changeCooldown(Item item, int additional) {
if (this.cooldowns.containsKey(item)) {
ItemCooldowns.CooldownInstance cooldown = this.cooldowns.get(item);
this.cooldowns.put(item, new ItemCooldowns.CooldownInstance(cooldown.startTime, cooldown.endTime + additional));
this.onCooldownChanged(item, additional);
}
public void frozenLib$changeCooldown(Item item, int additional) {
this.cooldowns.computeIfPresent(item, (item1, cooldown) -> {
this.frozenLib$onCooldownChanged(item, additional);
return new ItemCooldowns.CooldownInstance(cooldown.startTime, cooldown.endTime + additional);
});
}

@Unique
@Override
public void onCooldownChanged(Item item, int additional) {
public void frozenLib$onCooldownChanged(Item item, int additional) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.frozenblock.lib.item.impl.CooldownInterface;
import net.frozenblock.lib.item.impl.network.CooldownChangePacket;
import net.frozenblock.lib.networking.FrozenNetworking;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.FriendlyByteBuf;
Expand All @@ -41,21 +42,17 @@ public class ServerItemCooldownsMixin extends ItemCooldowns implements CooldownI

@Unique
@Override
public void changeCooldown(Item item, int additional) {
if (this.cooldowns.containsKey(item)) {
CooldownInstance cooldown = this.cooldowns.get(item);
this.cooldowns.put(item, new CooldownInstance(cooldown.startTime, cooldown.endTime + additional));
this.onCooldownChanged(item, additional);
}
public void frozenLib$changeCooldown(Item item, int additional) {
this.cooldowns.computeIfPresent(item, (item1, cooldown) -> {
this.frozenLib$onCooldownChanged(item, additional);
return new CooldownInstance(cooldown.startTime, cooldown.endTime + additional);
});
}

@Unique
@Override
public void onCooldownChanged(Item item, int additional) {
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
byteBuf.writeId(BuiltInRegistries.ITEM, item);
byteBuf.writeVarInt(additional);
ServerPlayNetworking.send(this.player, FrozenNetworking.COOLDOWN_CHANGE_PACKET, byteBuf);
public void frozenLib$onCooldownChanged(Item item, int additional) {
ServerPlayNetworking.send(this.player, new CooldownChangePacket(item, additional));
}

}
Loading

0 comments on commit 28131bf

Please sign in to comment.