Skip to content

Commit

Permalink
[Release] still v0.1.1 just hexdoc bump. also add coping saw, script,…
Browse files Browse the repository at this point in the history
… and context modifiers
  • Loading branch information
SamsTheNerd committed Nov 23, 2023
1 parent b2c6739 commit 5f5f36d
Show file tree
Hide file tree
Showing 20 changed files with 266 additions and 23 deletions.
2 changes: 2 additions & 0 deletions common/src/main/java/com/samsthenerd/hexgloop/HexGloop.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.common.base.Suppliers;
import com.samsthenerd.hexgloop.blockentities.HexGloopBEs;
import com.samsthenerd.hexgloop.blocks.HexGloopBlocks;
import com.samsthenerd.hexgloop.casting.ContextModificationHandlers;
import com.samsthenerd.hexgloop.casting.HexGloopDiscoverers;
import com.samsthenerd.hexgloop.casting.HexGloopRegisterPatterns;
import com.samsthenerd.hexgloop.items.HexGloopItems;
Expand Down Expand Up @@ -52,5 +53,6 @@ public static void onInitialize() {
StringsToDirMap.init();
LabelTypes.registerIotaLabelFunctions();
HexGloopDiscoverers.init();
ContextModificationHandlers.init();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ private static void registerModelPredicates(){
return HexGloopItems.ESSENCE_STONE_ITEM.get().hasEssence(stack) ? 1 : 0;
});

ItemPropertiesRegistry.register(HexGloopItems.SCRIPT_ITEM.get(), ItemFocus.OVERLAY_PRED, (stack, level, holder, holderID) -> {
return HexGloopItems.SCRIPT_ITEM.get().readIotaTag(stack) == null ? 0 : 1;
});

ItemPropertiesRegistry.register(HexGloopItems.HEX_BLADE_ITEM.get(), ItemHexSword.TOOL_STATUS_PREDICATE, (stack, level, holder, holderID) -> {
if(!HexGloopItems.HEX_BLADE_ITEM.get().hasHex(stack)){
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
package com.samsthenerd.hexgloop.blocks;

import com.samsthenerd.hexgloop.casting.ContextModificationHandlers.Modification;

import at.petrak.hexcasting.api.spell.casting.CastingContext;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;

public class BlockSentinelBed extends Block implements ICatPost{
public BlockSentinelBed (Settings settings){
super(settings);
}

public static Modification ambitModifier(CastingContext ctx, Vec3d pos, Boolean original){
ServerPlayerEntity caster = ctx.getCaster();
if(!original && caster != null){
BlockState state = caster.getWorld().getBlockState(new BlockPos(pos));
if(state.getBlock() == HexGloopBlocks.SENTINEL_BED_BLOCK.get())
return Modification.ENABLE;
}
return Modification.NONE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.samsthenerd.hexgloop.casting;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.function.BiFunction;

import com.samsthenerd.hexgloop.blocks.BlockSentinelBed;
import com.samsthenerd.hexgloop.items.ItemCopingSaw;

import at.petrak.hexcasting.api.spell.casting.CastingContext;
import net.minecraft.data.client.BlockStateVariantMap.TriFunction;
import net.minecraft.util.Pair;
import net.minecraft.util.math.Vec3d;

// registry for various context modifiers, handled by mixins
public class ContextModificationHandlers {
public static Comparator<Pair<?, Integer>> comparator = (Pair<?, Integer> a, Pair<?, Integer> b) -> {
return b.getRight().compareTo(a.getRight());
};

public static Queue<Pair<BiFunction<CastingContext, Boolean, Modification>, Integer>> ENLIGHTENMENT_MODIFIERS = new PriorityQueue<>(comparator);
public static Queue<Pair<BiFunction<CastingContext, Boolean, Modification>, Integer>> OVERCAST_MODIFIERS = new PriorityQueue<>(comparator);
public static Queue<Pair<TriFunction<CastingContext, Vec3d, Boolean, Modification>, Integer>> AMBIT_MODIFIERS = new PriorityQueue<>(comparator);

public static enum Modification {
NONE,
ENABLE,
DISABLE
}

public static void registerEnlightenmentModifier(BiFunction<CastingContext, Boolean, Modification> modifier, int ordering){
ENLIGHTENMENT_MODIFIERS.add(new Pair<>(modifier, ordering));
}

public static void registerOvercastModifier(BiFunction<CastingContext, Boolean, Modification> modifier, int ordering){
OVERCAST_MODIFIERS.add(new Pair<>(modifier, ordering));
}

public static void registerAmbitModifier(TriFunction<CastingContext, Vec3d, Boolean, Modification> modifier, int ordering){
AMBIT_MODIFIERS.add(new Pair<>(modifier, ordering));
}

public static void init(){
registerAmbitModifier(BlockSentinelBed::ambitModifier, 0);
registerOvercastModifier(ItemCopingSaw::overcastModifer, 100000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public class HexGloopItems{
public static final RegistrySupplier<ItemEssenceStone> ESSENCE_STONE_ITEM = item("essence_stone",
() -> new ItemEssenceStone(defaultSettings().maxCount(1)));

public static final RegistrySupplier<ItemPatternScript> SCRIPT_ITEM = item("script",
() -> new ItemPatternScript(defaultSettings().maxCount(1)));

public static final RegistrySupplier<ItemCopingSaw> COPING_SAW_ITEM = item("coping_saw",
() -> new ItemCopingSaw(defaultSettings().maxCount(1)));

// fidgets -- todo: maybe move these out of here and into their own file

public static final RegistrySupplier<ItemFidget> COPPER_PEN_FIDGET = item("copper_pen_fidget",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.samsthenerd.hexgloop.items;

import com.samsthenerd.hexgloop.casting.ContextModificationHandlers.Modification;

import at.petrak.hexcasting.api.spell.casting.CastingContext;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.Item;

public class ItemCopingSaw extends Item{
public ItemCopingSaw(Settings settings){
super(settings);
}

public static Modification overcastModifer(CastingContext ctx, Boolean original){
if(ctx.getCaster() != null){
PlayerInventory pInv = ctx.getCaster().getInventory();
for(int i = 0; i < PlayerInventory.getHotbarSize(); i++){
if(pInv.getStack(i).getItem() == HexGloopItems.COPING_SAW_ITEM.get()){
return Modification.DISABLE;
}
}
}
return Modification.NONE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.samsthenerd.hexgloop.items;

import java.util.List;

import javax.annotation.Nullable;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;

public class ItemLibraryCard extends Item {

public static String TAG_DIMENSION = "bound_dimension";
public static String DIMENSION_PREDICATE = "hexgloop:dimension";

public ItemLibraryCard(Settings settings) {
super(settings);
}

public void setDimension(ItemStack stack, RegistryKey<World> dim){
stack.getOrCreateNbt().putString(TAG_DIMENSION, dim.getValue().toString());
}

@Nullable
public RegistryKey<World> getDimension(ItemStack stack){
NbtCompound nbt = stack.getNbt();
if(nbt == null || !nbt.contains(TAG_DIMENSION, NbtElement.STRING_TYPE))
return null;
return RegistryKey.of(Registry.WORLD_KEY, new Identifier(nbt.getString(TAG_DIMENSION)));
}

public static final List<RegistryKey<World>> DIMENSIONS = List.of(World.OVERWORLD, World.NETHER, World.END);

public float getPredicateValue(RegistryKey<World> dim){
if(dim == null)
return 0;

return 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.samsthenerd.hexgloop.mixins.castingmodifiers;

import java.util.function.BiFunction;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.samsthenerd.hexgloop.casting.ContextModificationHandlers;
import com.samsthenerd.hexgloop.casting.ContextModificationHandlers.Modification;

import at.petrak.hexcasting.api.spell.casting.CastingContext;
import net.minecraft.data.client.BlockStateVariantMap.TriFunction;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Pair;
import net.minecraft.util.math.Vec3d;

@Mixin(CastingContext.class)
public class MixinCastingContextModifiers {
@Shadow
@Final
private ServerPlayerEntity caster;

@ModifyReturnValue(method="isVecInRange(Lnet/minecraft/util/math/Vec3d;)Z",
at=@At("RETURN"))
public boolean doAmbitModification(boolean original, Vec3d pos){
boolean current = original;
for(Pair<TriFunction<CastingContext, Vec3d, Boolean, Modification>, Integer> pair : ContextModificationHandlers.AMBIT_MODIFIERS){
TriFunction<CastingContext, Vec3d, Boolean, Modification> modifier = pair.getLeft();
Modification mod = modifier.apply((CastingContext)(Object)this, pos, current);
if(mod != Modification.NONE){
current = (mod == Modification.ENABLE);
}
}
return current;
}

@ModifyReturnValue(method="isCasterEnlightened()Z", at=@At("RETURN"), remap = false)
public boolean doEnlightenmentModification(boolean original){
boolean current = original;
for(Pair<BiFunction<CastingContext, Boolean, Modification>, Integer> pair : ContextModificationHandlers.ENLIGHTENMENT_MODIFIERS){
BiFunction<CastingContext, Boolean, Modification> modifier = pair.getLeft();
Modification mod = modifier.apply((CastingContext)(Object)this, current);
if(mod != Modification.NONE){
current = (mod == Modification.ENABLE);
}
}
return current;
}

@ModifyReturnValue(method="getCanOvercast()Z", at=@At("RETURN"), remap = false)
public boolean doOvercastModification(boolean original){
boolean current = original;
for(Pair<BiFunction<CastingContext, Boolean, Modification>, Integer> pair : ContextModificationHandlers.OVERCAST_MODIFIERS){
BiFunction<CastingContext, Boolean, Modification> modifier = pair.getLeft();
Modification mod = modifier.apply((CastingContext)(Object)this, current);
if(mod != Modification.NONE){
current = (mod == Modification.ENABLE);
}
}
return current;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,21 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import com.samsthenerd.hexgloop.blocks.HexGloopBlocks;
import com.samsthenerd.hexgloop.casting.IContextHelper;
import com.samsthenerd.hexgloop.casting.inventorty.InventortyUtils.KittyContext;

import at.petrak.hexcasting.api.spell.casting.CastingContext;
import net.minecraft.block.BlockState;
import net.minecraft.inventory.StackReference;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;

@Mixin(CastingContext.class)
public class MixinContextHelper implements IContextHelper{
@Shadow
@Final
private ServerPlayerEntity caster;

// might use for more stuff in the future but it's fine for now
@Inject(method="isVecInRange(Lnet/minecraft/util/math/Vec3d;)Z",
at=@At("RETURN"), cancellable=true)
public void sentinelIsCozy(Vec3d pos, CallbackInfoReturnable<Boolean> cir){
if(!cir.getReturnValue() && caster != null){
BlockState state = caster.getWorld().getBlockState(new BlockPos(pos));
if(state.getBlock() == HexGloopBlocks.SENTINEL_BED_BLOCK.get())
cir.setReturnValue(true);
}
}

private ItemStack kittyStack = null;

public void setKitty(ItemStack kitty){
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/resources/assets/hexgloop/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
"item.hexgloop.covered_spellbook.sealed": "Sealed Covered Spellbook",
"item.hexgloop.hand_mirror.tooltip": "Reflects [%s]",
"item.hexgloop.hand_mirror.tooltip.not_activated": "Last Reflected [%s]",

"item.hexgloop.essence_stone": "Essence Stone",
"item.hexgloop.script": "Script",
"item.hexgloop.coping_saw": "Coping Saw",

"item.hexgloop.copper_pen_fidget": "Pen Fidget",
"item.hexgloop.rainbow_amogus_fidget": "Rainbow Amogus Pop It Fidget",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/handheld_rod",
"textures": {
"layer0": "hexgloop:item/coping_saw"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parent": "minecraft:item/handheld_rod",
"textures": {
"layer0": "hexgloop:item/morestaffs/longinus_staff"
"layer0": "hexgloop:item/morestaffs/longinus"
}
}
20 changes: 20 additions & 0 deletions common/src/main/resources/assets/hexgloop/models/item/script.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"parent": "minecraft:item/generated",
"overrides": [
{
"model": "hexgloop:item/script",
"predicate": {
"hexcasting:overlay_layer": 0.0
}
},
{
"model": "hexgloop:item/script_written",
"predicate": {
"hexcasting:overlay_layer": 1.0
}
}
],
"textures": {
"layer0": "hexgloop:item/script/base"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "hexgloop:item/script/base",
"layer1": "hexgloop:item/script/overlay"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"hexgloop:ice_staff",
"hexgloop:blaze_staff",
"hexgloop:pumpkin_staff",
"hexgloop:wither_staff"
"hexgloop:wither_staff",
"hexgloop:longinus_staff",
"hexgloop:owl_staff",
"hexgloop:ghost_staff",
"hexgloop:celestial_staff"
]
}
3 changes: 2 additions & 1 deletion common/src/main/resources/hexgloop-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"truenameclassactionmixins.MixinPlsAgreeToTheTruenameEULA",
"booktweaks.MixinCopyPatternToScrolls",
"misc.MixinExposeCursorStackRef",
"misc.MixinShowMediaWorth"
"misc.MixinShowMediaWorth",
"castingmodifiers.MixinCastingContextModifiers"
],
"client": [
"wnboi.SpellbookWNBOI",
Expand Down
1 change: 1 addition & 0 deletions doc/hexdoc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ regex = "{^_pattern_regex}"
[textures]
missing = [
"hexgloop:fake_spellbook_for_rei",
"minecraft:chest"
]

# platforms
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends "pages/patchouli/text.html.jinja" %}
{% include "common/macros.html.jinja" %}

{% block inner_body %}
{# {{ macros.recipe_block([page.recipe],
Expand Down
Loading

0 comments on commit 5f5f36d

Please sign in to comment.