Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into misc-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Robotgiggle committed Feb 3, 2025
2 parents ece8564 + 7233cc1 commit 6702d99
Show file tree
Hide file tree
Showing 25 changed files with 154 additions and 109 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ permissions:

jobs:
hexdoc:
uses: hexdoc-dev/hexdoc/.github/workflows/hexdoc.yml@main
uses: hexdoc-dev/actions/.github/workflows/hexdoc.yml@v1
permissions:
contents: write
pages: read
Expand All @@ -51,7 +51,7 @@ jobs:
id-token: write
steps:
- name: Download package artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: hexdoc-build
path: dist
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
hexdoc:
# don't bother running the docs build when pushing to main - nothing necessary to cache here
if: github.event_name != 'push'
uses: hexdoc-dev/hexdoc/.github/workflows/hexdoc.yml@main
uses: hexdoc-dev/actions/.github/workflows/hexdoc.yml@v1
permissions:
contents: write
pages: read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import at.petrak.hexcasting.api.mod.HexConfig;
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.common.lib.HexAttributes;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -247,6 +248,9 @@ public boolean isEnlightened() {
* positive.
*/
public long extractMedia(long cost, boolean simulate) {
if (this.getCastingEntity() != null){
cost = (long) (cost * this.getCastingEntity().getAttributeValue(HexAttributes.MEDIA_CONSUMPTION_MODIFIER));
}
for (var extractMediaComponent : preMediaExtract)
cost = extractMediaComponent.onExtractMedia(cost, simulate);
cost = extractMediaEnvironment(cost, simulate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import at.petrak.hexcasting.api.casting.mishaps.MishapDisallowedSpell;
import at.petrak.hexcasting.api.mod.HexConfig;
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.common.lib.HexAttributes;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -29,8 +30,6 @@
import java.util.List;
import java.util.function.Predicate;

import static at.petrak.hexcasting.api.casting.eval.env.PlayerBasedCastEnv.SENTINEL_RADIUS;

public class CircleCastEnv extends CastingEnvironment {
protected final CircleExecutionState execState;

Expand Down Expand Up @@ -133,6 +132,7 @@ public long extractMediaEnvironment(long cost, boolean simulate) {
public boolean isVecInRangeEnvironment(Vec3 vec) {
var caster = this.execState.getCaster(this.world);
if (caster != null) {
double sentinelRadius = caster.getAttributeValue(HexAttributes.SENTINEL_RADIUS);
if (vec.distanceToSqr(caster.position()) <= caster.getBbHeight() * caster.getBbHeight()) {
return true;
}
Expand All @@ -141,7 +141,7 @@ public boolean isVecInRangeEnvironment(Vec3 vec) {
if (sentinel != null
&& sentinel.extendsRange()
&& caster.level().dimension() == sentinel.dimension()
&& vec.distanceToSqr(sentinel.position()) <= SENTINEL_RADIUS * SENTINEL_RADIUS + 0.00000000001
&& vec.distanceToSqr(sentinel.position()) <= sentinelRadius * sentinelRadius + 0.00000000001
) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.api.utils.MediaHelper;
import at.petrak.hexcasting.common.lib.HexAttributes;
import at.petrak.hexcasting.common.lib.HexDamageTypes;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.core.BlockPos;
Expand All @@ -35,8 +36,10 @@
import static at.petrak.hexcasting.api.HexAPI.modLoc;

public abstract class PlayerBasedCastEnv extends CastingEnvironment {
public static final double AMBIT_RADIUS = 32.0;
public static final double SENTINEL_RADIUS = 16.0;
public static final double DEFAULT_AMBIT_RADIUS = 32.0;
private double ambitRadius;
public static final double DEFAULT_SENTINEL_RADIUS = 16.0;
private double sentinelRadius;

protected final ServerPlayer caster;
protected final InteractionHand castingHand;
Expand All @@ -45,6 +48,8 @@ protected PlayerBasedCastEnv(ServerPlayer caster, InteractionHand castingHand) {
super(caster.serverLevel());
this.caster = caster;
this.castingHand = castingHand;
this.ambitRadius = caster.getAttributeValue(HexAttributes.AMBIT_RADIUS);
this.sentinelRadius = caster.getAttributeValue(HexAttributes.SENTINEL_RADIUS);
}

@Override
Expand All @@ -66,6 +71,16 @@ public void postExecution(CastResult result) {
this.sendMishapMsgToPlayer(doMishap);
}
}
if (this.caster != null){
double ambitAttribute = this.caster.getAttributeValue(HexAttributes.AMBIT_RADIUS);
if (this.ambitRadius != ambitAttribute){
this.ambitRadius = ambitAttribute;
}
double sentinelAttribute = this.caster.getAttributeValue(HexAttributes.SENTINEL_RADIUS);
if (this.sentinelRadius != sentinelAttribute){
this.sentinelRadius = sentinelAttribute;
}
}
}

@Override
Expand All @@ -78,6 +93,14 @@ protected List<HeldItemInfo> getPrimaryStacks() {
return getPrimaryStacksForPlayer(this.castingHand, this.caster);
}

public double getAmbitRadius() {
return this.ambitRadius;
}

public double getSentinelRadius(){
return this.sentinelRadius;
}

@Override
public boolean replaceItem(Predicate<ItemStack> stackOk, ItemStack replaceWith, @Nullable InteractionHand hand) {
return replaceItemForPlayer(stackOk, replaceWith, hand, this.caster);
Expand All @@ -90,12 +113,12 @@ public boolean isVecInRangeEnvironment(Vec3 vec) {
&& sentinel.extendsRange()
&& this.caster.level().dimension() == sentinel.dimension()
// adding 0.00000000001 to avoid machine precision errors at specific angles
&& vec.distanceToSqr(sentinel.position()) <= SENTINEL_RADIUS * SENTINEL_RADIUS + 0.00000000001
&& vec.distanceToSqr(sentinel.position()) <= sentinelRadius * sentinelRadius + 0.00000000001
) {
return true;
}

return vec.distanceToSqr(this.caster.position()) <= AMBIT_RADIUS * AMBIT_RADIUS + 0.00000000001;
return vec.distanceToSqr(this.caster.position()) <= ambitRadius * ambitRadius + 0.00000000001;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,11 @@ public interface ServerConfigAccess {

double traderScrollChance();

List<String> getRandomLootHex(RandomSource rand);

int DEFAULT_MAX_OP_COUNT = 100_000;
int DEFAULT_MAX_SPELL_CIRCLE_LENGTH = 1024;
int DEFAULT_OP_BREAK_HARVEST_LEVEL = 3;

double DEFAULT_TRADER_SCROLL_CHANCE = 0.4;
double DEFAULT_TRADER_SCROLL_CHANCE = 0.2;

boolean DEFAULT_VILLAGERS_DISLIKE_MIND_MURDER = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class GuiSpellcasting constructor(
val player = minecraft.player
if (player != null) {
val heldItem = player.getItemInHand(handOpenedWith)
if (heldItem.isEmpty || !heldItem.`is`(HexTags.Items.STAVES))
if (heldItem.isEmpty || !heldItem.`is`(HexTags.Items.STAVES) || player.getAttributeValue(HexAttributes.FEEBLE_MIND) > 0)
closeForReal()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static void tryRenderScryingLensOverlay(GuiGraphics graphics, float part
return;
}

if (player.getAttributeValue(HexAttributes.SCRY_SIGHT) <= 0.0)
if (player.getAttributeValue(HexAttributes.SCRY_SIGHT) <= 0.0 || player.getAttributeValue(HexAttributes.FEEBLE_MIND) > 0)
return;

var hitRes = mc.hitResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.entity.item.ItemEntity
import net.minecraft.world.item.ItemStack
import net.minecraft.network.chat.Component
import java.util.function.Predicate;

// TODO: How to handle in circles
class OpMakePackagedSpell<T : ItemPackagedHex>(val isValid: Predicate<ItemStack>, val expectedType: T, val cost: Long) : SpellAction {
class OpMakePackagedSpell(val isValid: Predicate<ItemStack>, val expectedTypeDesc: Component, val cost: Long) : SpellAction {
constructor(itemType: ItemPackagedHex, cost: Long) : this({s -> s.`is`(itemType)}, itemType.description, cost) {}

override val argc = 2
override fun execute(
args: List<Iota>,
Expand All @@ -33,11 +36,11 @@ class OpMakePackagedSpell<T : ItemPackagedHex>(val isValid: Predicate<ItemStack>
val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(it)
isValid.test(it) && hexHolder != null && !hexHolder.hasHex()
}
?: throw MishapBadOffhandItem(ItemStack.EMPTY.copy(), expectedType.description) // TODO: hack
?: throw MishapBadOffhandItem(ItemStack.EMPTY.copy(), expectedTypeDesc) // TODO: hack

val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(handStack)
if (!isValid.test(handStack)) {
throw MishapBadOffhandItem(handStack, expectedType.description)
throw MishapBadOffhandItem(handStack, expectedTypeDesc)
} else if (hexHolder == null || hexHolder.hasHex()) {
throw MishapBadOffhandItem.of(handStack, "iota.write")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.petrak.hexcasting.common.items;

import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.common.lib.HexAttributes;
import at.petrak.hexcasting.common.lib.HexSounds;
import at.petrak.hexcasting.common.msgs.MsgClearSpiralPatternsS2C;
import at.petrak.hexcasting.common.msgs.MsgOpenSpellGuiS2C;
Expand All @@ -25,6 +26,9 @@ public ItemStaff(Properties pProperties) {

@Override
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
if (player.getAttributeValue(HexAttributes.FEEBLE_MIND) > 0){
return InteractionResultHolder.fail(player.getItemInHand(hand));
}
if (player.isShiftKeyDown()) {
if (world.isClientSide()) {
player.playSound(HexSounds.STAFF_RESET, 1f, 1f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
import at.petrak.hexcasting.common.entities.EntityWallScroll;
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes;
import at.petrak.hexcasting.common.misc.PatternTooltip;
import at.petrak.hexcasting.common.loot.AddPerWorldPatternToScrollFunc;
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
import at.petrak.hexcasting.interop.inline.InlinePatternData;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
Expand Down Expand Up @@ -168,9 +170,17 @@ public void inventoryTick(ItemStack pStack, Level pLevel, Entity pEntity, int pS
if (NBTHelper.getBoolean(pStack, TAG_NEEDS_PURCHASE)) {
NBTHelper.remove(pStack, TAG_NEEDS_PURCHASE);
}
// if op_id is set but there's no stored pattern, load the pattern on inv tick
// if op_id is set but there's no stored pattern, attempt to load the pattern on inv tick
if (NBTHelper.hasString(pStack, TAG_OP_ID) && !NBTHelper.hasCompound(pStack, TAG_PATTERN) && pEntity.getServer() != null) {
AddPerWorldPatternToScrollFunc.doStatic(pStack, pLevel.getRandom(), pEntity.getServer().overworld());
var opID = ResourceLocation.tryParse(NBTHelper.getString(pStack, TAG_OP_ID));
if (opID == null) {
// if the provided op_id is invalid, remove it so we don't keep trying every tick
NBTHelper.remove(pStack, TAG_OP_ID);
return;
}
var patternKey = ResourceKey.create(IXplatAbstractions.INSTANCE.getActionRegistry().key(), opID);
var pat = PatternRegistryManifest.getCanonicalStrokesPerWorld(patternKey, pEntity.getServer().overworld());
NBTHelper.put(pStack, TAG_PATTERN, pat.serializeToNBT());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.petrak.hexcasting.common.lib;

import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.api.casting.eval.env.PlayerBasedCastEnv;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.RangedAttribute;
Expand All @@ -24,14 +25,32 @@ public static void register(BiConsumer<Attribute, ResourceLocation> r) {

private static final Map<ResourceLocation, Attribute> ATTRIBUTES = new LinkedHashMap<>();

private static final String MOD_ID = HexAPI.MOD_ID;

public static final Attribute GRID_ZOOM = make("grid_zoom", new RangedAttribute(
HexAPI.MOD_ID + ".attributes.grid_zoom", 1.0, 0.5, 4.0)).setSyncable(true);
MOD_ID + ".attributes.grid_zoom", 1.0, 0.5, 4.0)).setSyncable(true);

/**
* Whether you have the lens overlay when looking at something. 0 = no, > 0 = yes.
*/
public static final Attribute SCRY_SIGHT = make("scry_sight", new RangedAttribute(
HexAPI.MOD_ID + ".attributes.scry_sight", 0.0, 0.0, 1.0)).setSyncable(true);
MOD_ID + ".attributes.scry_sight", 0.0, 0.0, 1.0)).setSyncable(true);

//whether the player is allowed to use staffcasting and scrying lenses
public static final Attribute FEEBLE_MIND = make("feeble_mind", new RangedAttribute(
MOD_ID + ".attributes.feeble_mind", 0.0, 0.0, 1.0).setSyncable(true));

//a multiplier to adjust media consumption across the board
public static final Attribute MEDIA_CONSUMPTION_MODIFIER = make("media_consumption", new RangedAttribute(
MOD_ID + ".attributes.media_consumption", 1.0, 0.0, Double.MAX_VALUE).setSyncable(true));

public static final Attribute AMBIT_RADIUS = make("ambit_radius", new RangedAttribute(
MOD_ID + ".attributes.ambit_radius", PlayerBasedCastEnv.DEFAULT_AMBIT_RADIUS, 0.0, Double.MAX_VALUE).setSyncable(true));

public static final Attribute SENTINEL_RADIUS = make("sentinel_radius", new RangedAttribute(
MOD_ID + ".attributes.sentinel_radius", PlayerBasedCastEnv.DEFAULT_SENTINEL_RADIUS, 0.0, Double.MAX_VALUE).setSyncable(true));



private static <T extends Attribute> T make(String id, T attr) {
var old = ATTRIBUTES.put(modLoc(id), attr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,23 @@ public static void registerItemCreativeTab(CreativeModeTab.Output r, CreativeMod
public static final Supplier<ItemStack> BATTERY_DUST_STACK = addToTab(() -> ItemMediaBattery.withMedia(
new ItemStack(HexItems.BATTERY),
MediaConstants.DUST_UNIT * 64,
MediaConstants.DUST_UNIT * 64), HexCreativeTabs.MAIN);
MediaConstants.DUST_UNIT * 64), HexCreativeTabs.HEX);
public static final Supplier<ItemStack> BATTERY_SHARD_STACK = addToTab(() -> ItemMediaBattery.withMedia(
new ItemStack(HexItems.BATTERY),
MediaConstants.SHARD_UNIT * 64,
MediaConstants.SHARD_UNIT * 64), HexCreativeTabs.MAIN);
MediaConstants.SHARD_UNIT * 64), HexCreativeTabs.HEX);
public static final Supplier<ItemStack> BATTERY_CRYSTAL_STACK = addToTab(() -> ItemMediaBattery.withMedia(
new ItemStack(HexItems.BATTERY),
MediaConstants.CRYSTAL_UNIT * 64,
MediaConstants.CRYSTAL_UNIT * 64), HexCreativeTabs.MAIN);
MediaConstants.CRYSTAL_UNIT * 64), HexCreativeTabs.HEX);
public static final Supplier<ItemStack> BATTERY_QUENCHED_SHARD_STACK = addToTab(() -> ItemMediaBattery.withMedia(
new ItemStack(HexItems.BATTERY),
MediaConstants.QUENCHED_SHARD_UNIT * 64,
MediaConstants.QUENCHED_SHARD_UNIT * 64), HexCreativeTabs.MAIN);
MediaConstants.QUENCHED_SHARD_UNIT * 64), HexCreativeTabs.HEX);
public static final Supplier<ItemStack> BATTERY_QUENCHED_BLOCK_STACK = addToTab(() -> ItemMediaBattery.withMedia(
new ItemStack(HexItems.BATTERY),
MediaConstants.QUENCHED_BLOCK_UNIT * 64,
MediaConstants.QUENCHED_BLOCK_UNIT * 64), HexCreativeTabs.MAIN);
MediaConstants.QUENCHED_BLOCK_UNIT * 64), HexCreativeTabs.HEX);

public static final EnumMap<DyeColor, ItemDyePigment> DYE_PIGMENTS = Util.make(() -> {
var out = new EnumMap<DyeColor, ItemDyePigment>(DyeColor.class);
Expand Down Expand Up @@ -192,7 +192,7 @@ private static <T extends Item> T make(String id, T item, @Nullable CreativeMode
}

private static <T extends Item> T make(String id, T item) {
return make(modLoc(id), item, HexCreativeTabs.MAIN);
return make(modLoc(id), item, HexCreativeTabs.HEX);
}

private static Supplier<ItemStack> addToTab(Supplier<ItemStack> stack, CreativeModeTab tab) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,16 @@ public class HexActions {
new ActionRegistryEntry(HexPattern.fromAngles("adaa", HexDir.WEST), OpBeep.INSTANCE));

public static final ActionRegistryEntry CRAFT$CYPHER = make("craft/cypher", new ActionRegistryEntry(
HexPattern.fromAngles("waqqqqq", HexDir.EAST), new OpMakePackagedSpell<>(s -> (s.is(HexItems.CYPHER)||s.is(HexItems.ANCIENT_CYPHER)),
HexItems.CYPHER, MediaConstants.CRYSTAL_UNIT)
HexPattern.fromAngles("waqqqqq", HexDir.EAST),
new OpMakePackagedSpell(s -> (s.is(HexItems.CYPHER)||s.is(HexItems.ANCIENT_CYPHER)), HexItems.CYPHER.getDescription(), MediaConstants.CRYSTAL_UNIT)
));
public static final ActionRegistryEntry CRAFT$TRINKET = make("craft/trinket", new ActionRegistryEntry(
HexPattern.fromAngles(
"wwaqqqqqeaqeaeqqqeaeq", HexDir.EAST), new OpMakePackagedSpell<>(s -> s.is(HexItems.TRINKET),
HexItems.TRINKET, 5 * MediaConstants.CRYSTAL_UNIT)));
HexPattern.fromAngles("wwaqqqqqeaqeaeqqqeaeq", HexDir.EAST),
new OpMakePackagedSpell(HexItems.TRINKET, 5 * MediaConstants.CRYSTAL_UNIT)
));
public static final ActionRegistryEntry CRAFT$ARTIFACT = make("craft/artifact", new ActionRegistryEntry(
HexPattern.fromAngles("wwaqqqqqeawqwqwqwqwqwwqqeadaeqqeqqeadaeqq", HexDir.EAST),
new OpMakePackagedSpell<>(s -> s.is(HexItems.ARTIFACT), HexItems.ARTIFACT, 10 * MediaConstants.CRYSTAL_UNIT)
new OpMakePackagedSpell(HexItems.ARTIFACT, 10 * MediaConstants.CRYSTAL_UNIT)
));
public static final ActionRegistryEntry CRAFT$BATTERY = make("craft/battery", new ActionRegistryEntry(
HexPattern.fromAngles("aqqqaqwwaqqqqqeqaqqqawwqwqwqwqwqw", HexDir.SOUTH_WEST), OpMakeBattery.INSTANCE));
Expand Down
Loading

0 comments on commit 6702d99

Please sign in to comment.