Skip to content

Commit

Permalink
sync required food amount config
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed May 14, 2024
1 parent f117597 commit 0a28f24
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ public class ClientPlayerFallbackValues extends ServerPlayerFallbackValues imple
private final boolean armorSlows;
private final float maxSlowedMultiplier;
private final boolean canLoopDeLoop;
private final float requiredFoodAmount;

public ClientPlayerFallbackValues(float wingsSpeed, float maxSlowedMultiplier, boolean armorSlows, boolean canLoopDeLoop) {
public ClientPlayerFallbackValues(float wingsSpeed, float maxSlowedMultiplier, boolean armorSlows, boolean canLoopDeLoop, float requiredFoodAmount) {
this.wingsSpeed = wingsSpeed;
this.armorSlows = armorSlows;
this.maxSlowedMultiplier = maxSlowedMultiplier;
this.canLoopDeLoop = canLoopDeLoop;
this.requiredFoodAmount = requiredFoodAmount;
}

@Override
Expand All @@ -36,4 +38,9 @@ public boolean armorSlows() {
public boolean canLoopDeLoop() {
return canLoopDeLoop;
}

@Override
public float requiredFoodAmount() {
return requiredFoodAmount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;

public record SyncConfigValuesPacket(float wingsSpeed, float maxSlowedMultiplier, boolean armorSlows, boolean canLoopDeLoop) {
public record SyncConfigValuesPacket(float wingsSpeed, float maxSlowedMultiplier, boolean armorSlows, boolean canLoopDeLoop, float requiredFoodAmount) {
public static final ResourceLocation ID = Icarus.id("sync_config_values");

public void encode(FriendlyByteBuf buf) {
Expand All @@ -23,7 +23,7 @@ public void encode(FriendlyByteBuf buf) {

public static void send(ServerPlayer player) {
var cfg = new ServerPlayerFallbackValues();
var packet = new SyncConfigValuesPacket(cfg.wingsSpeed(), cfg.maxSlowedMultiplier(), cfg.armorSlows(), cfg.canLoopDeLoop());
var packet = new SyncConfigValuesPacket(cfg.wingsSpeed(), cfg.maxSlowedMultiplier(), cfg.armorSlows(), cfg.canLoopDeLoop(), cfg.requiredFoodAmount());
Dispatcher.sendToClient(packet, player);
}

Expand All @@ -32,16 +32,18 @@ public static SyncConfigValuesPacket decode(FriendlyByteBuf buf) {
float maxSlowedMultiplier = buf.readFloat();
boolean armorSlows = buf.readBoolean();
boolean canLoopDeLoop = buf.readBoolean();
float requiredFoodAmount = buf.readFloat();

return new SyncConfigValuesPacket(wingsSpeed, maxSlowedMultiplier, armorSlows, canLoopDeLoop);
return new SyncConfigValuesPacket(wingsSpeed, maxSlowedMultiplier, armorSlows, canLoopDeLoop, requiredFoodAmount);
}

public static void handle(PacketContext<SyncConfigValuesPacket> ctx) {
Minecraft.getInstance().execute(() -> IcarusHelper.fallbackValues = new ClientPlayerFallbackValues(
ctx.message().wingsSpeed(),
ctx.message().maxSlowedMultiplier(),
ctx.message().armorSlows(),
ctx.message().canLoopDeLoop()
ctx.message().canLoopDeLoop(),
ctx.message().requiredFoodAmount()
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public TagKey<Level> noFlyingAllowedInDimensions() {
public int maxHeightAboveWorld() {
return IcarusConfig.maxHeightAboveWorld;
}

@Override
public float requiredFoodAmount() {
return IcarusConfig.requiredFoodAmount;
}
}

0 comments on commit 0a28f24

Please sign in to comment.