-
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.
Add reset repair cost functionality and filters
- Loading branch information
Showing
26 changed files
with
625 additions
and
125 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
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
43 changes: 43 additions & 0 deletions
43
src/main/java/de/mschae23/grindenchantments/config/FilterAction.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,43 @@ | ||
/* | ||
* 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 net.minecraft.util.StringIdentifiable; | ||
import com.mojang.serialization.Codec; | ||
|
||
public enum FilterAction implements StringIdentifiable { | ||
ALLOW("allow"), | ||
IGNORE("ignore"), | ||
DENY("deny"); | ||
|
||
public static final Codec<FilterAction> CODEC = StringIdentifiable.createCodec(FilterAction::values); | ||
public static final Codec<FilterAction> NON_IGNORE_CODEC = StringIdentifiable.createCodec(() -> new FilterAction[] { ALLOW, DENY, }); | ||
|
||
private final String name; | ||
|
||
FilterAction(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String asString() { | ||
return this.name; | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
src/main/java/de/mschae23/grindenchantments/config/FilterConfig.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,119 @@ | ||
/* | ||
* 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 net.minecraft.component.type.ItemEnchantmentsComponent; | ||
import net.minecraft.enchantment.Enchantment; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.registry.RegistryCodecs; | ||
import net.minecraft.registry.RegistryKeys; | ||
import net.minecraft.registry.entry.RegistryEntry; | ||
import net.minecraft.registry.entry.RegistryEntryList; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
|
||
public record FilterConfig(boolean enabled, ItemConfig item, EnchantmentConfig enchantment, FilterAction curses) { | ||
public static final Codec<FilterConfig> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
Codec.BOOL.fieldOf("enabled").forGetter(FilterConfig::enabled), | ||
ItemConfig.CODEC.fieldOf("item").forGetter(FilterConfig::item), | ||
EnchantmentConfig.CODEC.fieldOf("enchantment").forGetter(FilterConfig::enchantment), | ||
FilterAction.CODEC.fieldOf("cursed_enchantments").forGetter(FilterConfig::curses) | ||
).apply(instance, instance.stable(FilterConfig::new))); | ||
|
||
public static final FilterConfig DEFAULT = new FilterConfig(true, ItemConfig.DEFAULT, EnchantmentConfig.DEFAULT, FilterAction.IGNORE); | ||
|
||
public ItemEnchantmentsComponent filter(ItemEnchantmentsComponent enchantments) { | ||
if (!this.enabled) { | ||
return enchantments; | ||
} | ||
|
||
ItemEnchantmentsComponent.Builder builder = new ItemEnchantmentsComponent.Builder(enchantments); | ||
|
||
if (this.curses == FilterAction.DENY) { | ||
for (RegistryEntry<Enchantment> entry : builder.getEnchantments()) { | ||
if (entry.value().isCursed()) { | ||
return ItemEnchantmentsComponent.DEFAULT; | ||
} | ||
} | ||
} | ||
|
||
if (this.enchantment.action == FilterAction.DENY) { | ||
for (RegistryEntry<Enchantment> entry : builder.getEnchantments()) { | ||
if (this.enchantment.enchantments.contains(entry)) { | ||
return ItemEnchantmentsComponent.DEFAULT; | ||
} | ||
} | ||
} | ||
|
||
builder.remove(enchantment -> | ||
((this.curses == FilterAction.IGNORE) && enchantment.value().isCursed()) | ||
|| ((this.enchantment.action == FilterAction.IGNORE) == this.enchantment.enchantments.contains(enchantment))); | ||
|
||
return builder.build(); | ||
} | ||
|
||
public ItemEnchantmentsComponent filterReversed(ItemEnchantmentsComponent enchantments) { | ||
if (!this.enabled) { | ||
return ItemEnchantmentsComponent.DEFAULT; | ||
} | ||
|
||
ItemEnchantmentsComponent.Builder builder = new ItemEnchantmentsComponent.Builder(enchantments); | ||
|
||
if (this.curses == FilterAction.DENY) { | ||
for (RegistryEntry<Enchantment> entry : builder.getEnchantments()) { | ||
if (entry.value().isCursed()) { | ||
return ItemEnchantmentsComponent.DEFAULT; | ||
} | ||
} | ||
} | ||
|
||
if (this.enchantment.action == FilterAction.DENY) { | ||
for (RegistryEntry<Enchantment> entry : builder.getEnchantments()) { | ||
if (this.enchantment.enchantments.contains(entry)) { | ||
return ItemEnchantmentsComponent.DEFAULT; | ||
} | ||
} | ||
} | ||
|
||
builder.remove(enchantment -> | ||
((this.curses == FilterAction.ALLOW) || !enchantment.value().isCursed()) | ||
&& ((this.enchantment.action == FilterAction.ALLOW) == this.enchantment.enchantments.contains(enchantment))); | ||
|
||
return builder.build(); | ||
} | ||
|
||
public record ItemConfig(RegistryEntryList<Item> items, FilterAction action) { | ||
public static final Codec<ItemConfig> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
RegistryCodecs.entryList(RegistryKeys.ITEM).fieldOf("enchantments").forGetter(ItemConfig::items), | ||
FilterAction.NON_IGNORE_CODEC.fieldOf("action").forGetter(ItemConfig::action) | ||
).apply(instance, instance.stable(ItemConfig::new))); | ||
|
||
public static final ItemConfig DEFAULT = new ItemConfig(RegistryEntryList.empty(), FilterAction.DENY); | ||
} | ||
|
||
public record EnchantmentConfig(RegistryEntryList<Enchantment> enchantments, FilterAction action) { | ||
public static final Codec<EnchantmentConfig> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
RegistryCodecs.entryList(RegistryKeys.ENCHANTMENT).fieldOf("enchantments").forGetter(EnchantmentConfig::enchantments), | ||
FilterAction.CODEC.fieldOf("action").forGetter(EnchantmentConfig::action) | ||
).apply(instance, instance.stable(EnchantmentConfig::new))); | ||
|
||
public static final EnchantmentConfig DEFAULT = new EnchantmentConfig(RegistryEntryList.empty(), FilterAction.IGNORE); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/de/mschae23/grindenchantments/config/GrindEnchantmentsV3Config.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,57 @@ | ||
/* | ||
* 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 GrindEnchantmentsV3Config(DisenchantConfig disenchant, MoveConfig move, ResetRepairCostConfig resetRepairCost, | ||
FilterConfig filter, | ||
DedicatedServerConfig dedicatedServerConfig, ClientConfig clientConfig) implements ModConfig<GrindEnchantmentsV3Config> { | ||
public static final MapCodec<GrindEnchantmentsV3Config> TYPE_CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( | ||
DisenchantConfig.CODEC.fieldOf("disenchant_to_book").forGetter(GrindEnchantmentsV3Config::disenchant), | ||
MoveConfig.CODEC.fieldOf("move_enchantments").forGetter(GrindEnchantmentsV3Config::move), | ||
ResetRepairCostConfig.CODEC.fieldOf("reset_repair_cost").forGetter(GrindEnchantmentsV3Config::resetRepairCost), | ||
FilterConfig.CODEC.fieldOf("filter").forGetter(GrindEnchantmentsV3Config::filter), | ||
DedicatedServerConfig.CODEC.orElse(DedicatedServerConfig.DEFAULT).fieldOf("dedicated_server_options").forGetter(GrindEnchantmentsV3Config::dedicatedServerConfig), | ||
ClientConfig.CODEC.fieldOf("client_options").forGetter(GrindEnchantmentsV3Config::clientConfig) | ||
).apply(instance, instance.stable(GrindEnchantmentsV3Config::new))); | ||
|
||
public static final ModConfig.Type<GrindEnchantmentsV3Config, GrindEnchantmentsV3Config> TYPE = new ModConfig.Type<>(3, TYPE_CODEC); | ||
|
||
public static final GrindEnchantmentsV3Config DEFAULT = | ||
new GrindEnchantmentsV3Config(DisenchantConfig.DEFAULT, MoveConfig.DEFAULT, ResetRepairCostConfig.DEFAULT, FilterConfig.DEFAULT, DedicatedServerConfig.DEFAULT, ClientConfig.DEFAULT); | ||
|
||
@Override | ||
public Type<GrindEnchantmentsV3Config, ?> type() { | ||
return TYPE; | ||
} | ||
|
||
@Override | ||
public GrindEnchantmentsV3Config latest() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean shouldUpdate() { | ||
return true; | ||
} | ||
} |
Oops, something went wrong.