Close #96
This commit is contained in:
parent
79b97a2998
commit
eb52579062
7 changed files with 34 additions and 6 deletions
|
@ -42,6 +42,8 @@ public class HexConfig {
|
||||||
|
|
||||||
boolean isActionAllowed(ResourceLocation actionID);
|
boolean isActionAllowed(ResourceLocation actionID);
|
||||||
|
|
||||||
|
boolean isActionAllowedInCircles(ResourceLocation actionID);
|
||||||
|
|
||||||
int DEFAULT_MAX_RECURSE_DEPTH = 64;
|
int DEFAULT_MAX_RECURSE_DEPTH = 64;
|
||||||
int DEFAULT_MAX_SPELL_CIRCLE_LENGTH = 1024;
|
int DEFAULT_MAX_SPELL_CIRCLE_LENGTH = 1024;
|
||||||
int DEFAULT_OP_BREAK_HARVEST_LEVEL = 3;
|
int DEFAULT_OP_BREAK_HARVEST_LEVEL = 3;
|
||||||
|
|
|
@ -132,9 +132,6 @@ class CastingHarness private constructor(
|
||||||
* handle it functionally.
|
* handle it functionally.
|
||||||
*/
|
*/
|
||||||
fun updateWithPattern(newPat: HexPattern, world: ServerLevel, continuation: SpellContinuation): CastResult {
|
fun updateWithPattern(newPat: HexPattern, world: ServerLevel, continuation: SpellContinuation): CastResult {
|
||||||
if (this.ctx.spellCircle == null)
|
|
||||||
this.ctx.caster.awardStat(HexStatistics.PATTERNS_DRAWN)
|
|
||||||
|
|
||||||
var operatorIdPair: Pair<Operator, ResourceLocation>? = null
|
var operatorIdPair: Pair<Operator, ResourceLocation>? = null
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -142,7 +139,10 @@ class CastingHarness private constructor(
|
||||||
operatorIdPair = PatternRegistry.matchPatternAndID(newPat, world)
|
operatorIdPair = PatternRegistry.matchPatternAndID(newPat, world)
|
||||||
if (!HexConfig.server().isActionAllowed(operatorIdPair.second)) {
|
if (!HexConfig.server().isActionAllowed(operatorIdPair.second)) {
|
||||||
throw MishapDisallowedSpell()
|
throw MishapDisallowedSpell()
|
||||||
|
} else if (this.ctx.spellCircle != null && !HexConfig.server().isActionAllowedInCircles(operatorIdPair.second)) {
|
||||||
|
throw MishapDisallowedSpell("disallowed_circle")
|
||||||
}
|
}
|
||||||
|
|
||||||
val pattern = operatorIdPair.first
|
val pattern = operatorIdPair.first
|
||||||
|
|
||||||
val unenlightened = pattern.isGreat && !ctx.isCasterEnlightened
|
val unenlightened = pattern.isGreat && !ctx.isCasterEnlightened
|
||||||
|
|
|
@ -6,7 +6,7 @@ import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||||
import at.petrak.hexcasting.api.spell.casting.ResolvedPatternType
|
import at.petrak.hexcasting.api.spell.casting.ResolvedPatternType
|
||||||
import net.minecraft.world.item.DyeColor
|
import net.minecraft.world.item.DyeColor
|
||||||
|
|
||||||
class MishapDisallowedSpell : Mishap() {
|
class MishapDisallowedSpell(val type: String = "disallowed") : Mishap() {
|
||||||
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
|
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
|
||||||
dyeColor(DyeColor.BLACK)
|
dyeColor(DyeColor.BLACK)
|
||||||
|
|
||||||
|
@ -17,5 +17,5 @@ class MishapDisallowedSpell : Mishap() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun errorMessage(ctx: CastingContext, errorCtx: Context) =
|
override fun errorMessage(ctx: CastingContext, errorCtx: Context) =
|
||||||
error("disallowed", actionName(errorCtx.action))
|
error(type, actionName(errorCtx.action))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package at.petrak.hexcasting.common.network;
|
package at.petrak.hexcasting.common.network;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.mod.HexItemTags;
|
import at.petrak.hexcasting.api.mod.HexItemTags;
|
||||||
|
import at.petrak.hexcasting.api.mod.HexStatistics;
|
||||||
import at.petrak.hexcasting.api.spell.SpellDatum;
|
import at.petrak.hexcasting.api.spell.SpellDatum;
|
||||||
import at.petrak.hexcasting.api.spell.casting.ControllerInfo;
|
import at.petrak.hexcasting.api.spell.casting.ControllerInfo;
|
||||||
import at.petrak.hexcasting.api.spell.casting.ResolvedPattern;
|
import at.petrak.hexcasting.api.spell.casting.ResolvedPattern;
|
||||||
|
@ -78,6 +79,8 @@ public record MsgNewSpellPatternSyn(InteractionHand handUsed, HexPattern pattern
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sender.awardStat(HexStatistics.PATTERNS_DRAWN);
|
||||||
|
|
||||||
var harness = IXplatAbstractions.INSTANCE.getHarness(sender, this.handUsed);
|
var harness = IXplatAbstractions.INSTANCE.getHarness(sender, this.handUsed);
|
||||||
|
|
||||||
ControllerInfo clientInfo;
|
ControllerInfo clientInfo;
|
||||||
|
|
|
@ -409,6 +409,7 @@
|
||||||
"hexcasting.mishap.divide_by_zero.cos": "the cosine of %s",
|
"hexcasting.mishap.divide_by_zero.cos": "the cosine of %s",
|
||||||
"hexcasting.mishap.no_akashic_record": "No Akashic Record at %s",
|
"hexcasting.mishap.no_akashic_record": "No Akashic Record at %s",
|
||||||
"hexcasting.mishap.disallowed": "%s has been disallowed by the server admins",
|
"hexcasting.mishap.disallowed": "%s has been disallowed by the server admins",
|
||||||
|
"hexcasting.mishap.disallowed_circle": "%s has been disallowed in spell circles by the server admins",
|
||||||
"hexcasting.mishap.invalid_spell_datum_type": "Tried to use a value of invalid type as a SpellDatum: %s (class %s). This is a bug in the mod.",
|
"hexcasting.mishap.invalid_spell_datum_type": "Tried to use a value of invalid type as a SpellDatum: %s (class %s). This is a bug in the mod.",
|
||||||
"hexcasting.mishap.unknown": "%s threw an exception (%s). This is a bug in the mod.",
|
"hexcasting.mishap.unknown": "%s threw an exception (%s). This is a bug in the mod.",
|
||||||
|
|
||||||
|
|
|
@ -157,6 +157,8 @@ public class FabricHexConfig {
|
||||||
ConfigTypes.INTEGER.withMinimum(4));
|
ConfigTypes.INTEGER.withMinimum(4));
|
||||||
private final PropertyMirror<List<String>> actionDenyList = PropertyMirror.create(
|
private final PropertyMirror<List<String>> actionDenyList = PropertyMirror.create(
|
||||||
ConfigTypes.makeList(ConfigTypes.STRING));
|
ConfigTypes.makeList(ConfigTypes.STRING));
|
||||||
|
private final PropertyMirror<List<String>> circleActionDenyList = PropertyMirror.create(
|
||||||
|
ConfigTypes.makeList(ConfigTypes.STRING));
|
||||||
|
|
||||||
public ConfigTree configure(ConfigTreeBuilder bob) {
|
public ConfigTree configure(ConfigTreeBuilder bob) {
|
||||||
bob.fork("Spells")
|
bob.fork("Spells")
|
||||||
|
@ -174,10 +176,14 @@ public class FabricHexConfig {
|
||||||
.beginValue("maxSpellCircleLength", ConfigTypes.NATURAL, DEFAULT_MAX_SPELL_CIRCLE_LENGTH)
|
.beginValue("maxSpellCircleLength", ConfigTypes.NATURAL, DEFAULT_MAX_SPELL_CIRCLE_LENGTH)
|
||||||
.withComment("The maximum number of slates in a spell circle")
|
.withComment("The maximum number of slates in a spell circle")
|
||||||
.finishValue(maxSpellCircleLength::mirror)
|
.finishValue(maxSpellCircleLength::mirror)
|
||||||
|
|
||||||
|
.beginValue("circleActionDenyList", ConfigTypes.makeList(ConfigTypes.STRING), List.of())
|
||||||
|
.withComment("Resource locations of disallowed actions within circles. Trying to cast one of these in a circle will result in a mishap.")
|
||||||
|
.finishValue(circleActionDenyList::mirror)
|
||||||
.finishBranch()
|
.finishBranch()
|
||||||
|
|
||||||
.beginValue("actionDenyList", ConfigTypes.makeList(ConfigTypes.STRING), List.of())
|
.beginValue("actionDenyList", ConfigTypes.makeList(ConfigTypes.STRING), List.of())
|
||||||
.withComment("The maximum number of slates in a spell circle")
|
.withComment("Resource locations of disallowed actions. Trying to cast one of these will result in a mishap.")
|
||||||
.finishValue(actionDenyList::mirror);
|
.finishValue(actionDenyList::mirror);
|
||||||
|
|
||||||
return bob.build();
|
return bob.build();
|
||||||
|
@ -202,5 +208,10 @@ public class FabricHexConfig {
|
||||||
public boolean isActionAllowed(ResourceLocation actionID) {
|
public boolean isActionAllowed(ResourceLocation actionID) {
|
||||||
return !actionDenyList.getValue().contains(actionID.toString());
|
return !actionDenyList.getValue().contains(actionID.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActionAllowedInCircles(ResourceLocation actionID) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ public class ForgeHexConfig implements HexConfig.CommonConfigAccess {
|
||||||
private static ForgeConfigSpec.IntValue maxSpellCircleLength;
|
private static ForgeConfigSpec.IntValue maxSpellCircleLength;
|
||||||
|
|
||||||
private static ForgeConfigSpec.ConfigValue<List<? extends String>> actionDenyList;
|
private static ForgeConfigSpec.ConfigValue<List<? extends String>> actionDenyList;
|
||||||
|
private static ForgeConfigSpec.ConfigValue<List<? extends String>> circleActionDenyList;
|
||||||
|
|
||||||
public Server(ForgeConfigSpec.Builder builder) {
|
public Server(ForgeConfigSpec.Builder builder) {
|
||||||
builder.push("Spells");
|
builder.push("Spells");
|
||||||
|
@ -91,6 +92,11 @@ public class ForgeHexConfig implements HexConfig.CommonConfigAccess {
|
||||||
builder.push("Spell Circles");
|
builder.push("Spell Circles");
|
||||||
maxSpellCircleLength = builder.comment("The maximum number of slates in a spell circle")
|
maxSpellCircleLength = builder.comment("The maximum number of slates in a spell circle")
|
||||||
.defineInRange("maxSpellCircleLength", DEFAULT_MAX_SPELL_CIRCLE_LENGTH, 4, Integer.MAX_VALUE);
|
.defineInRange("maxSpellCircleLength", DEFAULT_MAX_SPELL_CIRCLE_LENGTH, 4, Integer.MAX_VALUE);
|
||||||
|
|
||||||
|
circleActionDenyList = builder.comment(
|
||||||
|
"Resource locations of disallowed actions within circles. Trying to cast one of these in a circle will result in a mishap.")
|
||||||
|
.defineList("circleActionDenyList", List.of(),
|
||||||
|
obj -> obj instanceof String s && ResourceLocation.isValidResourceLocation(s));
|
||||||
builder.pop();
|
builder.pop();
|
||||||
|
|
||||||
actionDenyList = builder.comment(
|
actionDenyList = builder.comment(
|
||||||
|
@ -118,5 +124,10 @@ public class ForgeHexConfig implements HexConfig.CommonConfigAccess {
|
||||||
public boolean isActionAllowed(ResourceLocation actionID) {
|
public boolean isActionAllowed(ResourceLocation actionID) {
|
||||||
return !actionDenyList.get().contains(actionID.toString());
|
return !actionDenyList.get().contains(actionID.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActionAllowedInCircles(ResourceLocation actionID) {
|
||||||
|
return !circleActionDenyList.get().contains(actionID.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue