Skip to content

Commit

Permalink
Add anvil algorithm customize
Browse files Browse the repository at this point in the history
  • Loading branch information
Eyre-S committed Jun 16, 2024
1 parent 913381e commit 3bc9a2f
Show file tree
Hide file tree
Showing 14 changed files with 418 additions and 23 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ server.
## Scheduled features list

- [x] anvilItemCostRollupAlgorithm
- [ ] anvilCostAlgorithm
- [ ] anvilChangeNameCost
- [x] anvilItemCostRollupAlgorithm
- [x] anvilCostAlgorithm
- [x] anvilUseItemCost
- [x] anvilRenameCost -- only implements the on/off yet, and have bugs picking up when cost is 0
- [x] anvilTooExpensiveLimit -- have bugs picking up
- [ ] tickFreezeWhenNoPlayersUseDeepFreeze
- [ ] petsPreventOwnerDamage
- [ ] petsShowHealth
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ loader_version=0.15.11
fabric_version=0.92.2+1.20.1

# Mod Properties
mod_version=0.1.1
mod_version=0.2.0
maven_group=cc.sukazyo
archives_base_name=carpet_nukos_addition

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@

public class CarpetAdditionNukos implements CarpetExtension {

public static final String CATEGORY_KEY = "nukos";
public static class NukosCategoryKeys {
public static final String NUKOS = "nukos";
public static final String TICK = "tick";
public static final String ANVIL = "anvil";
}

public static MinecraftServer SERVER;
private static TickStatusClientSyncThread tickStatusClientSyncThread;

Expand Down
25 changes: 23 additions & 2 deletions src/main/java/cc/sukazyo/nukos/carpet/CarpetNukosSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,42 @@

import carpet.api.settings.Rule;
import carpet.api.settings.RuleCategory;
import cc.sukazyo.nukos.carpet.anvils.AnvilAlgorithms;
import cc.sukazyo.nukos.carpet.anvils.AnvilItemCostRollupAlgorithm;
import cc.sukazyo.nukos.carpet.CarpetAdditionNukos.NukosCategoryKeys;

public class CarpetNukosSettings {

@Rule(
categories = {CarpetAdditionNukos.CATEGORY_KEY, RuleCategory.SURVIVAL, RuleCategory.FEATURE},
categories = {NukosCategoryKeys.NUKOS, RuleCategory.SURVIVAL, NukosCategoryKeys.ANVIL},
options = {"vanilla", "linear:1", "no-change", "fixed:0"},
strict = false,
validators = AnvilItemCostRollupAlgorithm.Validator.class
)
public static String anvilItemCostRollupAlgorithm = "vanilla";

@Rule(
categories = {CarpetAdditionNukos.CATEGORY_KEY, RuleCategory.OPTIMIZATION, RuleCategory.EXPERIMENTAL}
categories = {NukosCategoryKeys.NUKOS, RuleCategory.SURVIVAL, NukosCategoryKeys.ANVIL},
options = {"vanilla", "vanilla-reforged"},
strict = false,
validators = AnvilAlgorithms.Validator.class
)
public static String anvilAlgorithm = "vanilla";

@Rule(categories = {NukosCategoryKeys.NUKOS, RuleCategory.SURVIVAL, NukosCategoryKeys.ANVIL})
public static Boolean anvilUseRenameCost = true;

@Rule(categories = {NukosCategoryKeys.NUKOS, RuleCategory.SURVIVAL, NukosCategoryKeys.ANVIL})
public static Boolean anvilUseItemCost = true;

@Rule(
categories = {NukosCategoryKeys.NUKOS, RuleCategory.SURVIVAL, NukosCategoryKeys.ANVIL},
options = {"40", "255"},
strict = false
)
public static int anvilTooExpensiveLimit = 40;

@Rule(categories = {NukosCategoryKeys.NUKOS, RuleCategory.OPTIMIZATION, RuleCategory.EXPERIMENTAL, NukosCategoryKeys.TICK})
public static Boolean tickFreezeWhenNoPlayers = false;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cc.sukazyo.nukos.carpet.anvils;

import java.util.Optional;

public interface AnvilAlgorithm {

Optional<AnvilResult> updateResult (AnvilContext context);

}
38 changes: 38 additions & 0 deletions src/main/java/cc/sukazyo/nukos/carpet/anvils/AnvilAlgorithms.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cc.sukazyo.nukos.carpet.anvils;

import carpet.api.settings.CarpetRule;
import cc.sukazyo.nukos.carpet.anvils.algorithms.VanillaAlgorithm;
import cc.sukazyo.nukos.carpet.anvils.algorithms.VanillaReforgedAlgorithm;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Pair;
import org.jetbrains.annotations.Nullable;

public class AnvilAlgorithms {

public static Pair<AnvilAlgorithm, String> validateAndGet (String name) {

return switch (name) {
case "vanilla" -> new Pair<>(new VanillaAlgorithm(), name);
case "vanilla-reforged" -> new Pair<>(new VanillaReforgedAlgorithm(), name);
default -> new Pair<>(null, null);
};

}

public static AnvilAlgorithm getFromName (String name) {
return validateAndGet(name).getLeft();
}

public static class Validator extends carpet.api.settings.Validator<String> {

@Override
public String validate (
@Nullable ServerCommandSource source, CarpetRule<String> changingRule,
String newValue, String userInput
) {
return validateAndGet(userInput).getRight();
}

}

}
24 changes: 24 additions & 0 deletions src/main/java/cc/sukazyo/nukos/carpet/anvils/AnvilContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cc.sukazyo.nukos.carpet.anvils;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;

public class AnvilContext {

public final ItemStack input1;
public final ItemStack input2;
public final String newItemName;

public final PlayerEntity player;

public AnvilContext (
ItemStack input1, ItemStack input2, String newItemName,
PlayerEntity player
) {
this.input1 = input1;
this.input2 = input2;
this.newItemName = newItemName;
this.player = player;
}

}
19 changes: 19 additions & 0 deletions src/main/java/cc/sukazyo/nukos/carpet/anvils/AnvilResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cc.sukazyo.nukos.carpet.anvils;

import net.minecraft.item.ItemStack;

public class AnvilResult {

public ItemStack output = ItemStack.EMPTY;
public int levelCost = 0;
public int ingotUsed = 0;

public AnvilResult setOutput (ItemStack output) { this.output = output; return this; }
public AnvilResult setLevelCost (int levelCost) { this.levelCost = levelCost; return this; }
public AnvilResult setIngotUsed (int ingotUsed) { this.ingotUsed = ingotUsed; return this; }

public static AnvilResult empty () {
return new AnvilResult();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cc.sukazyo.nukos.carpet.anvils.algorithms;

import cc.sukazyo.nukos.carpet.anvils.AnvilAlgorithm;
import cc.sukazyo.nukos.carpet.anvils.AnvilContext;
import cc.sukazyo.nukos.carpet.anvils.AnvilResult;

import java.util.Optional;

public class VanillaAlgorithm implements AnvilAlgorithm {

@Override
public Optional<AnvilResult> updateResult (AnvilContext context) {
return Optional.empty();
}

}
Loading

0 comments on commit 3bc9a2f

Please sign in to comment.