Skip to content

Commit

Permalink
Merge pull request #39 from enjarai/improved-capitalism
Browse files Browse the repository at this point in the history
Squishy
  • Loading branch information
StellarWitch7 authored Aug 25, 2024
2 parents 160d849 + 352ca5c commit ebf57d1
Show file tree
Hide file tree
Showing 32 changed files with 509 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial
@Override
public void mount(ParentComponent parent, int x, int y) {
super.mount(parent, x, y);
parent.childById(ButtonComponent.class, "load-button").onPress(this::loadSpellToGame);


var loadButton = parent.childById(ButtonComponent.class, "load-button");
if (loadButton != null) {
loadButton.onPress(this::loadSpellToGame);
}
}

public void loadSpellToGame(ButtonComponent button) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/resources/trickster.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"SillyHairsFeatureRendererMixin",
"WorldRendererAccessor",
"accessories.AccessoriesScreenMixin",
"figura.AvatarManagerMixin",
"sodium.WorldSliceMixin",
"tooltip.TooltipComponentMixin",
"figura.AvatarManagerMixin"
"tooltip.TooltipComponentMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// 1.21 2024-07-15T21:34:42.9793041 Trickster/Model Definitions
b9b893ec0a8cd31d7398651d871e15a392ea76b2 assets\trickster\models\item\spell_resonator.json
9d5d343103d621d1a2f492cec156c06274efdc15 assets\trickster\blockstates\spell_resonator.json
// 1.21 2024-08-22T17:14:21.48955409 Trickster/Model Definitions
b9b893ec0a8cd31d7398651d871e15a392ea76b2 assets/trickster/models/item/spell_resonator.json
9d5d343103d621d1a2f492cec156c06274efdc15 assets/trickster/blockstates/spell_resonator.json
13 changes: 13 additions & 0 deletions src/main/java/dev/enjarai/trickster/Trickster.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
import dev.enjarai.trickster.net.ModNetworking;
import dev.enjarai.trickster.particle.ModParticles;
import dev.enjarai.trickster.screen.ModScreenHandlers;
import dev.enjarai.trickster.spell.ItemTriggerHelper;
import dev.enjarai.trickster.spell.fragment.VectorFragment;
import dev.enjarai.trickster.spell.trick.Tricks;
import net.fabricmc.api.ModInitializer;

import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import nl.enjarai.cicada.api.conversation.ConversationManager;
import nl.enjarai.cicada.api.util.CicadaEntrypoint;
Expand Down Expand Up @@ -57,6 +61,15 @@ public void onInitialize() {
Tricks.register();
ModCriteria.register();

PlayerBlockBreakEvents.BEFORE.register((world, player, pos, state, blockEntity) -> {
if (player instanceof ServerPlayerEntity serverPlayer)
ItemTriggerHelper.triggerMainHand(serverPlayer, false, VectorFragment.of(pos));
else return true;

var newState = world.getBlockState(pos);
return newState.getBlock() == state.getBlock() || newState.getHardness(world, pos) > 0;
});

CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
TricksterCommand.register(dispatcher);
});
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/dev/enjarai/trickster/cca/CasterComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.ladysnake.cca.api.v3.component.sync.AutoSyncedComponent;
import org.ladysnake.cca.api.v3.component.tick.ServerTickingComponent;

import javax.swing.text.html.Option;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -135,7 +136,7 @@ public boolean queueSpell(SpellPart spell, List<Fragment> arguments) {
return executionManager.queue(spell, arguments);
}

public SpellQueueResult queueSpellAndCast(SpellPart spell, List<Fragment> arguments, ManaPool poolOverride) {
public SpellQueueResult queueSpellAndCast(SpellPart spell, List<Fragment> arguments, Optional<ManaPool> poolOverride) {
playCastSound(0.8f, 0.1f);
return executionManager.queueAndCast(spell, arguments, poolOverride);
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/dev/enjarai/trickster/item/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import io.wispforest.lavender.book.LavenderBookItem;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.minecraft.block.Block;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.ContainerComponent;
import net.minecraft.component.type.FoodComponent;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
Expand All @@ -18,7 +16,6 @@
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.text.Text;
import net.minecraft.util.collection.DefaultedList;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -63,6 +60,8 @@ public class ModItems {
public static final TagKey<Item> SCROLLS = TagKey.of(RegistryKeys.ITEM, Trickster.id("scrolls"));
// public static final TagKey<Item> IMMUTABLE_SPELL_HOLDERS = TagKey.of(RegistryKeys.ITEM, Trickster.id("immutable_spell_holders"));
public static final TagKey<Item> SPELL_COST = TagKey.of(RegistryKeys.ITEM, Trickster.id("spell_cost"));
public static final TagKey<Item> NO_SPELL_GLINT = TagKey.of(RegistryKeys.ITEM, Trickster.id("no_spell_glint"));
public static final TagKey<Item> WEAPON_SPELL_TRIGGERS = TagKey.of(RegistryKeys.ITEM, Trickster.id("weapon_spell_triggers"));
public static final TagKey<Block> CONJURABLE_FLOWERS = TagKey.of(RegistryKeys.BLOCK, Trickster.id("conjurable_flowers"));

public static final ItemGroup ITEM_GROUP = FabricItemGroup.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraft.world.World;

import java.util.List;
import java.util.Optional;

public class WrittenScrollItem extends Item {
public WrittenScrollItem(Settings settings) {
Expand All @@ -38,7 +39,7 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
if (!world.isClient()) {
var spell = stack.get(ModComponents.SPELL);
if (spell != null) {
var result = ModEntityCumponents.CASTER.get(user).queueSpellAndCast(spell.spell(), List.of(), SimpleManaPool.getSingleUse(meta.mana()));
var result = ModEntityCumponents.CASTER.get(user).queueSpellAndCast(spell.spell(), List.of(), Optional.of(SimpleManaPool.getSingleUse(meta.mana())));

if (result.type() != SpellQueueResult.Type.NOT_QUEUED && result.state().hasUsedMana())
stack.decrement(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,32 @@
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.ContainerComponent;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;

import java.util.ArrayList;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;

public record SpellComponent(SpellPart spell, boolean immutable, boolean closed) {
public record SpellComponent(SpellPart spell, Optional<String> name, boolean immutable, boolean closed) {
public static final Codec<SpellComponent> CODEC = RecordCodecBuilder.create(instance -> instance.group(
CodecUtils.toCodec(SpellPart.ENDEC).fieldOf("spell").forGetter(SpellComponent::spell),
Codec.STRING.optionalFieldOf("name").forGetter(SpellComponent::name),
Codec.BOOL.optionalFieldOf("immutable", false).forGetter(SpellComponent::immutable),
Codec.BOOL.optionalFieldOf("closed", false).forGetter(SpellComponent::closed)
).apply(instance, SpellComponent::new));

public SpellComponent(SpellPart spell) {
this(spell, false, false);
this(spell, Optional.empty(), false, false);
}

public SpellComponent(SpellPart spell, boolean immutable) {
this(spell, immutable, false);
this(spell, Optional.empty(), immutable, false);
}

public SpellComponent withClosed() {
return new SpellComponent(spell, immutable, true);
public SpellComponent withClosed(Optional<String> name) {
return new SpellComponent(spell, name, immutable, true);
}

public static Optional<SpellPart> getSpellPart(ItemStack stack) {
Expand All @@ -43,13 +45,13 @@ public static Optional<SpellPart> getSpellPart(ItemStack stack) {
.map(SpellComponent::spell);
}

public static boolean setSpellPart(ItemStack stack, SpellPart spell, boolean closed) {
public static boolean setSpellPart(ItemStack stack, SpellPart spell, Optional<String> name, boolean closed) {
return modifyReferencedStack(stack, stack2 -> {
if (stack2.contains(ModComponents.SPELL) && stack2.get(ModComponents.SPELL).immutable()) {
return false;
}

stack2.set(ModComponents.SPELL, new SpellComponent(spell, false, closed));
stack2.set(ModComponents.SPELL, new SpellComponent(spell, name, false, closed));
return true;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.world.World;

import java.util.Optional;

public class ScrollEnhancingRecipe extends SpecialCraftingRecipe {
public ScrollEnhancingRecipe(CraftingRecipeCategory craftingRecipeCategory) {
super(craftingRecipeCategory);
Expand Down Expand Up @@ -71,7 +73,7 @@ public ItemStack craft(CraftingRecipeInput craftingRecipeInput, RegistryWrapper.
var spell = itemStack.get(ModComponents.SPELL);
if (!itemStack.isEmpty() && i > 0 && meta != null && spell != null) {
var newMeta = meta.withExecutable(i * 100);
var newSpell = spell.withClosed();
var newSpell = spell.withClosed(Optional.empty());
ItemStack itemStack3 = itemStack.copyWithCount(1);
itemStack3.set(ModComponents.WRITTEN_SCROLL_META, newMeta);
itemStack3.set(ModComponents.SPELL, newSpell);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package dev.enjarai.trickster.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import com.llamalad7.mixinextras.sugar.ref.LocalIntRef;
import dev.enjarai.trickster.item.component.ModComponents;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.*;
import org.jetbrains.annotations.Nullable;
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.ModifyArg;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(AnvilScreenHandler.class)
public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler {
public AnvilScreenHandlerMixin(@Nullable ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory, ScreenHandlerContext context) {
super(type, syncId, playerInventory, context);
}

@Inject(
method = "updateResult",
at = @At(value = "INVOKE", target = "Lnet/minecraft/component/type/ItemEnchantmentsComponent;getEnchantmentEntries()Ljava/util/Set;")
)
private void enableSpellTransfer(CallbackInfo ci, @Local(ordinal = 0) LocalIntRef i, @Local(ordinal = 1) LocalBooleanRef bl2) {
var left = this.input.getStack(0);
var middle = this.input.getStack(1);

if (middle.contains(ModComponents.SPELL) && left.getCount() <= 1 && !left.isOf(Items.BOOK)) {
i.set(i.get() + 1);
bl2.set(true);
}
}

@ModifyArg(
method = "updateResult",
at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/CraftingResultInventory;setStack(ILnet/minecraft/item/ItemStack;)V"),
index = 1
)
private ItemStack applySpell(ItemStack stack) {
var spellComponent = this.input.getStack(1).get(ModComponents.SPELL);

if (spellComponent != null) {
stack.set(ModComponents.SPELL, spellComponent);
}

return stack;
}
}
62 changes: 62 additions & 0 deletions src/main/java/dev/enjarai/trickster/mixin/ItemMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package dev.enjarai.trickster.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import dev.enjarai.trickster.SpellTooltipData;
import dev.enjarai.trickster.item.ModItems;
import dev.enjarai.trickster.item.component.ModComponents;
import dev.enjarai.trickster.item.component.SpellComponent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipData;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;
import java.util.Optional;

@Mixin(Item.class)
public abstract class ItemMixin {
@ModifyReturnValue(
method = "hasGlint",
at = @At("RETURN")
)
private boolean spellGlint(boolean original, ItemStack stack) {
return original
|| (stack.get(ModComponents.SPELL) instanceof SpellComponent spellComponent)
&& !spellComponent.spell().isEmpty()
&& !stack.isIn(ModItems.NO_SPELL_GLINT);
}

@Inject(
method = "appendTooltip",
at = @At("HEAD")
)
private void addGarble(ItemStack stack, Item.TooltipContext context, List<Text> tooltip, TooltipType type, CallbackInfo ci) {
var spellComponent = stack.get(ModComponents.SPELL);

if (spellComponent != null && /*!spellComponent.spell().isEmpty() &&*/ spellComponent.closed()) {
tooltip.add(spellComponent.name()
.flatMap(str -> Optional.of(Text.literal(str)))
.orElse(Text.literal("Mortal eyes upon my carvings").setStyle(Style.EMPTY.withObfuscated(true))));
}
}

@Inject(
method = "getTooltipData",
at = @At("HEAD"),
cancellable = true
)
private void trickster$getSpellTooltipData(ItemStack stack, CallbackInfoReturnable<Optional<TooltipData>> cir) {
var spellComponent = stack.get(ModComponents.SPELL);

if (spellComponent != null && !spellComponent.spell().isEmpty() && !spellComponent.closed()) {
cir.setReturnValue(Optional.of(new SpellTooltipData(spellComponent.spell())));
}
}
}
23 changes: 21 additions & 2 deletions src/main/java/dev/enjarai/trickster/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import dev.enjarai.trickster.ModAttachments;
import dev.enjarai.trickster.cca.ModChunkCumponents;
import dev.enjarai.trickster.cca.ModEntityCumponents;
import dev.enjarai.trickster.spell.ItemTriggerHelper;
import dev.enjarai.trickster.spell.fragment.NumberFragment;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
Expand All @@ -16,6 +19,7 @@
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.EmptyChunk;
Expand All @@ -33,10 +37,12 @@
@SuppressWarnings("UnstableApiUsage")
@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin extends Entity {
@Shadow public abstract AttributeContainer getAttributes();

@Unique
private static final StatusEffectInstance PERM_BLINDNESS = new StatusEffectInstance(StatusEffects.BLINDNESS, 100, 2);

@Shadow
public abstract AttributeContainer getAttributes();

@Unique
private boolean inShadowBlock;

Expand Down Expand Up @@ -75,6 +81,19 @@ public StatusEffectInstance getStatusEffect(StatusEffectInstance original, Regis
return original;
}

@Inject(
method = "fall",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/LivingEntity;applyMovementEffects(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;)V"
)
)
private void triggerBoots(double heightDifference, boolean onGround, BlockState state, BlockPos landedPosition, CallbackInfo ci) {
if ((LivingEntity)(Object)this instanceof ServerPlayerEntity player) {
ItemTriggerHelper.triggerBoots(player, new NumberFragment(this.fallDistance));
}
}

@Inject(
method = "tick",
at = @At("TAIL")
Expand Down
25 changes: 0 additions & 25 deletions src/main/java/dev/enjarai/trickster/mixin/event/EntityMixin.java

This file was deleted.

Loading

0 comments on commit ebf57d1

Please sign in to comment.