-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split client and server configs (unfinished)
- Loading branch information
Showing
8 changed files
with
280 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/de/mschae23/grindenchantments/config/ClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (C) 2024 mschae23 | ||
* | ||
* This file is part of Grind enchantments. | ||
* | ||
* Grind enchantments 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 de.mschae23.grindenchantments.config; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.MapCodec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import de.mschae23.config.api.ModConfig; | ||
|
||
public record ClientConfig(boolean showLevelCost) implements ModConfig<ClientConfig> { | ||
public static final MapCodec<ClientConfig> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( | ||
Codec.BOOL.fieldOf("show_enchantment_cost").forGetter(ClientConfig::showLevelCost) | ||
).apply(instance, instance.stable(ClientConfig::new))); | ||
|
||
public static final ModConfig.Type<ClientConfig, ClientConfig> TYPE = new ModConfig.Type<>(4, CODEC); | ||
public static final ClientConfig DEFAULT = new ClientConfig(true); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static final ModConfig.Type<ClientConfig, ? extends ModConfig<ClientConfig>>[] VERSIONS = new ModConfig.Type[] { TYPE, }; | ||
|
||
@Override | ||
public Type<ClientConfig, ?> type() { | ||
return TYPE; | ||
} | ||
|
||
@Override | ||
public ClientConfig latest() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean shouldUpdate() { | ||
return true; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/de/mschae23/grindenchantments/config/DedicatedServerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (C) 2024 mschae23 | ||
* | ||
* This file is part of Grind enchantments. | ||
* | ||
* Grind enchantments 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 de.mschae23.grindenchantments.config; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
|
||
public record DedicatedServerConfig(boolean alternativeCostDisplay) { | ||
public static final Codec<DedicatedServerConfig> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
Codec.BOOL.fieldOf("alternative_cost_display_enabled").forGetter(DedicatedServerConfig::alternativeCostDisplay) | ||
).apply(instance, instance.stable(DedicatedServerConfig::new))); | ||
|
||
public static final DedicatedServerConfig DEFAULT = new DedicatedServerConfig(false); | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/de/mschae23/grindenchantments/config/ServerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) 2024 mschae23 | ||
* | ||
* This file is part of Grind enchantments. | ||
* | ||
* Grind enchantments 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 de.mschae23.grindenchantments.config; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import de.mschae23.config.api.ModConfig; | ||
|
||
public record ServerConfig(DisenchantConfig disenchant, MoveConfig move, ResetRepairCostConfig resetRepairCost, | ||
FilterConfig filter, | ||
DedicatedServerConfig dedicatedServerConfig) implements ModConfig<ServerConfig> { | ||
public static final MapCodec<ServerConfig> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( | ||
DisenchantConfig.CODEC.fieldOf("disenchant_to_book").forGetter(ServerConfig::disenchant), | ||
MoveConfig.CODEC.fieldOf("move_enchantments").forGetter(ServerConfig::move), | ||
ResetRepairCostConfig.CODEC.fieldOf("reset_repair_cost").forGetter(ServerConfig::resetRepairCost), | ||
FilterConfig.CODEC.fieldOf("filter").forGetter(ServerConfig::filter), | ||
DedicatedServerConfig.CODEC.orElse(DedicatedServerConfig.DEFAULT).fieldOf("dedicated_server_options").forGetter(ServerConfig::dedicatedServerConfig) | ||
).apply(instance, instance.stable(ServerConfig::new))); | ||
|
||
public static final ModConfig.Type<ServerConfig, ServerConfig> TYPE = new ModConfig.Type<>(4, CODEC); | ||
public static final ServerConfig DEFAULT = new ServerConfig(DisenchantConfig.DEFAULT, MoveConfig.DEFAULT, | ||
ResetRepairCostConfig.DEFAULT, FilterConfig.DEFAULT, DedicatedServerConfig.DEFAULT); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static final ModConfig.Type<ServerConfig, ? extends ModConfig<ServerConfig>>[] VERSIONS = new ModConfig.Type[] { TYPE, }; | ||
|
||
@Override | ||
public Type<ServerConfig, ?> type() { | ||
return TYPE; | ||
} | ||
|
||
@Override | ||
public ServerConfig latest() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean shouldUpdate() { | ||
return true; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/de/mschae23/grindenchantments/network/s2c/ServerConfigS2CPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2024 mschae23 | ||
* | ||
* This file is part of Grind enchantments. | ||
* | ||
* Grind enchantments 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 de.mschae23.grindenchantments.network.s2c; | ||
|
||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.network.codec.PacketCodec; | ||
import net.minecraft.network.packet.CustomPayload; | ||
import net.minecraft.util.Identifier; | ||
import de.mschae23.grindenchantments.GrindEnchantmentsMod; | ||
|
||
public record ServerConfigS2CPayload() implements CustomPayload { | ||
public static final Identifier PACKET_ID = GrindEnchantmentsMod.id("server_config"); | ||
public static final CustomPayload.Id<ServerConfigS2CPayload> ID = new CustomPayload.Id<>(PACKET_ID); | ||
|
||
public static final PacketCodec<PacketByteBuf, ServerConfigS2CPayload> CODEC = PacketCodec.unit(new ServerConfigS2CPayload()); | ||
|
||
@Override | ||
public Id<? extends CustomPayload> getId() { | ||
return ID; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters