Skip to content

Commit

Permalink
update registries and rework disabling spells via config
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Dec 9, 2023
1 parent 385c955 commit 09c6740
Show file tree
Hide file tree
Showing 40 changed files with 322 additions and 301 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ quilted_fabric_api = "7.4.0+0.90.0-1.20.1"
midnightlib = "1.4.1-quilt"
mixinextras = "0.3.1"
cca = "5.2.2"
sparkweave = "0.3.0"
sparkweave = "0.3.2"
modmenu = "7.2.2"
lazydfu = "0.1.3"

Expand Down
33 changes: 18 additions & 15 deletions src/main/java/dev/cammiescorner/arcanus/Arcanus.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.cammiescorner.arcanus.spell.Spell;
import dev.cammiescorner.arcanus.util.ArcanusConfig;
import dev.cammiescorner.arcanus.util.EventHandler;
import dev.upcraft.sparkweave.api.registry.RegistryService;
import eu.midnightdust.lib.config.MidnightConfig;
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.minecraft.ChatFormatting;
Expand All @@ -24,14 +25,14 @@

public class Arcanus implements ModInitializer {

public static final String MOD_ID = "arcanus";
public static final String MODID = "arcanus";
public static final Logger LOGGER = LogManager.getLogger("Arcanus");

public static final ResourceKey<Registry<Spell>> SPELL_KEY = ResourceKey.createRegistryKey(id("spell"));
public static final Registry<Spell> SPELL = FabricRegistryBuilder.createSimple(SPELL_KEY).buildAndRegister();

public static ResourceLocation id(String name) {
return new ResourceLocation(MOD_ID, name);
return new ResourceLocation(MODID, name);
}

public static MutableComponent translate(@Nullable String prefix, String... value) {
Expand All @@ -43,7 +44,7 @@ public static MutableComponent translate(@Nullable String prefix, String value,
}

public static String translationKey(@Nullable String prefix, String... value) {
String translationKey = Arcanus.MOD_ID + "." + String.join(".", value);
String translationKey = Arcanus.MODID + "." + String.join(".", value);
return prefix != null ? (prefix + "." + translationKey) : translationKey;
}

Expand All @@ -53,22 +54,24 @@ public static MutableComponent getSpellInputs(List<Spell.Pattern> pattern, int i

@Override
public void onInitialize(ModContainer mod) {
MidnightConfig.init(MOD_ID, ArcanusConfig.class);
MidnightConfig.init(MODID, ArcanusConfig.class);

ServerPlayNetworking.registerGlobalReceiver(CastSpellPacket.ID, CastSpellPacket::handle);

ArcanusBlocks.register();
ArcanusItems.register();
ArcanusBlockEntities.register();
RegistryService registryService = RegistryService.get();
ArcanusEntityAttributes.register(registryService);
ArcanusEntities.ENTITIES.accept(registryService);
ArcanusBlocks.BLOCKS.accept(registryService);
ArcanusItems.CREATIVE_TABS.accept(registryService);
ArcanusItems.ITEMS.accept(registryService);
ArcanusBlockEntities.BLOCK_ENTITIES.accept(registryService);
ArcanusParticles.PARTICLES.accept(registryService);
ArcanusScreens.SCREENS.accept(registryService);
ArcanusLootFunctions.LOOT_FUNCTIONS.accept(registryService);
ArcanusSoundEvents.SOUND_EVENTS.accept(registryService);
ArcanusStructureProcessors.STRUCTURE_PROCESSORS.accept(registryService);
ArcanusSpells.SPELLS.accept(registryService);
ArcanusCommands.register();
ArcanusEntities.register();
ArcanusEntityAttributes.register();
ArcanusLootFunctions.register();
ArcanusParticles.register();
ArcanusScreens.register();
ArcanusSoundEvents.register();
ArcanusSpells.register();
ArcanusStructureProcessors.register();

EventHandler.commonEvents();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.cammiescorner.arcanus.block;

import dev.cammiescorner.arcanus.block.entity.DisplayCaseBlockEntity;
import dev.upcraft.sparkweave.api.registry.block.BlockItemProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundEvents;
Expand All @@ -10,6 +11,8 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
Expand All @@ -28,7 +31,7 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

public class DisplayCaseBlock extends BaseEntityBlock {
public class DisplayCaseBlock extends BaseEntityBlock implements BlockItemProvider {
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final BooleanProperty OPEN = BlockStateProperties.OPEN;
private static final VoxelShape SHAPE = Shapes.or(
Expand All @@ -44,6 +47,11 @@ public DisplayCaseBlock(Properties settings) {
registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH).setValue(OPEN, false));
}

@Override
public Item createItem() {
return new BlockItem(this, new Item.Properties());
}

@Deprecated
@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package dev.cammiescorner.arcanus.block;

import dev.cammiescorner.arcanus.block.entity.FillableBookshelfBlockEntity;
import dev.upcraft.sparkweave.api.registry.block.BlockItemProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.world.Containers;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
Expand All @@ -19,14 +22,19 @@
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;

public class FillableBookshelfBlock extends BaseEntityBlock {
public class FillableBookshelfBlock extends BaseEntityBlock implements BlockItemProvider {
public static final IntegerProperty BOOK_COUNT = IntegerProperty.create("book_count", 0, 16);

public FillableBookshelfBlock(Properties settings) {
super(settings);
registerDefaultState(defaultBlockState().setValue(BOOK_COUNT, 0));
}

@Override
public Item createItem() {
return new BlockItem(this, new Item.Properties());
}

@Deprecated
@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DisplayCaseBlockEntity extends BlockEntity implements Container {
private final NonNullList<ItemStack> inventory = NonNullList.withSize(1, ItemStack.EMPTY);

public DisplayCaseBlockEntity(BlockPos pos, BlockState state) {
super(ArcanusBlockEntities.DISPLAY_CASE, pos, state);
super(ArcanusBlockEntities.DISPLAY_CASE.get(), pos, state);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class FillableBookshelfBlockEntity extends BlockEntity implements MenuPro
private final NonNullList<ItemStack> inventory = NonNullList.withSize(16, ItemStack.EMPTY);

public FillableBookshelfBlockEntity(BlockPos pos, BlockState state) {
super(ArcanusBlockEntities.FILLABLE_BOOKSHELF, pos, state);
super(ArcanusBlockEntities.FILLABLE_BOOKSHELF.get(), pos, state);
}

@Override
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/dev/cammiescorner/arcanus/client/ArcanusClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,24 @@ public static RenderType getMagicCircles(ResourceLocation texture) {

@Override
public void onInitializeClient(ModContainer mod) {
MenuScreens.register(ArcanusScreens.BOOKSHELF_SCREEN_HANDLER, BookshelfScreen::new);
MenuScreens.register(ArcanusScreens.BOOKSHELF_SCREEN_HANDLER.get(), BookshelfScreen::new);

EntityRendererRegistry.register(ArcanusEntities.SOLAR_STRIKE, SolarStrikeEntityRenderer::new);
EntityRendererRegistry.register(ArcanusEntities.ARCANE_BARRIER, ArcaneBarrierEntityRenderer::new);
EntityRendererRegistry.register(ArcanusEntities.MAGIC_MISSILE, MagicMissileEntityRenderer::new);
EntityRendererRegistry.register(ArcanusEntities.SOLAR_STRIKE.get(), SolarStrikeEntityRenderer::new);
EntityRendererRegistry.register(ArcanusEntities.ARCANE_BARRIER.get(), ArcaneBarrierEntityRenderer::new);
EntityRendererRegistry.register(ArcanusEntities.MAGIC_MISSILE.get(), MagicMissileEntityRenderer::new);

ParticleFactoryRegistry.getInstance().register(ArcanusParticles.MAGIC_MISSILE, MagicMissileParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(ArcanusParticles.TELEKINETIC_SHOCK, TelekineticShockParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(ArcanusParticles.HEAL, HealParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(ArcanusParticles.DISCOMBOBULATE, DiscombobulateParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(ArcanusParticles.MAGIC_MISSILE.get(), MagicMissileParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(ArcanusParticles.TELEKINETIC_SHOCK.get(), TelekineticShockParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(ArcanusParticles.HEAL.get(), HealParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(ArcanusParticles.DISCOMBOBULATE.get(), DiscombobulateParticle.Factory::new);

BlockEntityRenderers.register(ArcanusBlockEntities.DISPLAY_CASE, DisplayCaseBlockEntityRenderer::new);
BlockRenderLayerMap.put(RenderType.cutout(), ArcanusBlocks.DISPLAY_CASE);
BlockEntityRenderers.register(ArcanusBlockEntities.DISPLAY_CASE.get(), DisplayCaseBlockEntityRenderer::new);
BlockRenderLayerMap.put(RenderType.cutout(), ArcanusBlocks.DISPLAY_CASE.get());

EventHandler.clientEvents();

ItemProperties.registerGeneric(Arcanus.id("mana"), (stack, world, entity, seed) -> {
CompoundTag tag = stack.getTagElement(Arcanus.MOD_ID);
CompoundTag tag = stack.getTagElement(Arcanus.MODID);

if (tag == null)
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ArcaneBarrierEntity extends Entity {
private Player owner;

public ArcaneBarrierEntity(Level world) {
super(ArcanusEntities.ARCANE_BARRIER, world);
super(ArcanusEntities.ARCANE_BARRIER.get(), world);
}

public ArcaneBarrierEntity(Level world, double x, double y, double z) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class MagicMissileEntity extends AbstractArrow {

public MagicMissileEntity(LivingEntity owner, Level world) {
super(ArcanusEntities.MAGIC_MISSILE, owner, world);
super(ArcanusEntities.MAGIC_MISSILE.get(), owner, world);
setNoGravity(true);
setBaseDamage(1.5D);
}
Expand All @@ -43,7 +43,7 @@ public void tick() {
double deltaY = (random.nextInt(3) - 1) * random.nextDouble();
double deltaZ = (random.nextInt(3) - 1) * random.nextDouble();

PlayerLookup.tracking(this).forEach(player -> ((ServerLevel) level()).sendParticles(player, (ParticleOptions) ArcanusParticles.MAGIC_MISSILE, true, x, y, z, 1, deltaX, deltaY, deltaZ, 0.1));
PlayerLookup.tracking(this).forEach(player -> ((ServerLevel) level()).sendParticles(player, ArcanusParticles.MAGIC_MISSILE.get(), true, x, y, z, 1, deltaX, deltaY, deltaZ, 0.1));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SolarStrikeEntity extends AbstractArrow {
public final List<Entity> hasHit = new ArrayList<>();

public SolarStrikeEntity(LivingEntity owner, Level world) {
super(ArcanusEntities.SOLAR_STRIKE, owner, world);
super(ArcanusEntities.SOLAR_STRIKE.get(), owner, world);
}

public SolarStrikeEntity(EntityType<? extends SolarStrikeEntity> type, Level world) {
Expand Down Expand Up @@ -60,7 +60,7 @@ public void tick() {
kill();
} else {
if (tickCount == 1)
level().playLocalSound(getX(), getY(), getZ(), ArcanusSoundEvents.SOLAR_STRIKE, SoundSource.PLAYERS, Mth.clamp(1 - (Minecraft.getInstance().player.distanceTo(this) / 256F), 0, 1), (1.0F + (random.nextFloat() - random.nextFloat()) * 0.2F) * 0.7F, false);
level().playLocalSound(getX(), getY(), getZ(), ArcanusSoundEvents.SOLAR_STRIKE.get(), SoundSource.PLAYERS, Mth.clamp(1 - (Minecraft.getInstance().player.distanceTo(this) / 256F), 0, 1), (1.0F + (random.nextFloat() - random.nextFloat()) * 0.2F) * 0.7F, false);

if (tickCount >= 2 && tickCount <= 5) {
level().addParticle(ParticleTypes.EXPLOSION_EMITTER, getX() + 2, getY(), getZ(), 1.0D, 0.0D, 0.0D);
Expand Down
25 changes: 10 additions & 15 deletions src/main/java/dev/cammiescorner/arcanus/item/ManaFlaskItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,28 @@
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.util.*;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ItemUtils;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.item.*;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.gameevent.GameEvent;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class ManaFlaskItem extends Item {
public ManaFlaskItem() {
super(new Item.Properties().stacksTo(1).food(new FoodProperties.Builder().alwaysEat().build()));

public ManaFlaskItem(Properties properties) {
super(properties);
}

@Override
public ItemStack finishUsingItem(ItemStack stack, Level world, LivingEntity user) {
if (!world.isClientSide() && user instanceof Player player) {
MagicCaster caster = player.getComponent(ArcanusComponents.MAGIC_CASTER);
CompoundTag tag = stack.getOrCreateTagElement(Arcanus.MOD_ID);
CompoundTag tag = stack.getOrCreateTagElement(Arcanus.MODID);

if (player.isShiftKeyDown() && tag.getInt("Mana") < 4 && caster.getMana() >= 5) {
if (!player.isCreative()) {
Expand Down Expand Up @@ -62,7 +57,7 @@ public ItemStack finishUsingItem(ItemStack stack, Level world, LivingEntity user

@Override
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
CompoundTag tag = user.getItemInHand(hand).getOrCreateTagElement(Arcanus.MOD_ID);
CompoundTag tag = user.getItemInHand(hand).getOrCreateTagElement(Arcanus.MODID);
MagicCaster caster = user.getComponent(ArcanusComponents.MAGIC_CASTER);

tag.putBoolean("Filling", user.isShiftKeyDown() && tag.getInt("Mana") < 4 && caster.getMana() >= 5);
Expand All @@ -76,13 +71,13 @@ public InteractionResultHolder<ItemStack> use(Level world, Player user, Interact

@Override
public boolean isBarVisible(ItemStack stack) {
int mana = stack.getOrCreateTagElement(Arcanus.MOD_ID).getInt("Mana");
int mana = stack.getOrCreateTagElement(Arcanus.MODID).getInt("Mana");
return mana > 0;
}

@Override
public int getBarWidth(ItemStack stack) {
int mana = stack.getOrCreateTagElement(Arcanus.MOD_ID).getInt("Mana");
int mana = stack.getOrCreateTagElement(Arcanus.MODID).getInt("Mana");
return Math.round((mana * 13F) / 4F);
}

Expand All @@ -93,13 +88,13 @@ public int getBarColor(ItemStack stack) {

@Override
public UseAnim getUseAnimation(ItemStack stack) {
CompoundTag tag = stack.getTagElement(Arcanus.MOD_ID);
CompoundTag tag = stack.getTagElement(Arcanus.MODID);
return tag == null || tag.getBoolean("Filling") ? UseAnim.BOW : UseAnim.DRINK;
}

@Override
public String getDescriptionId(ItemStack stack) {
CompoundTag tag = stack.getTagElement(Arcanus.MOD_ID);
CompoundTag tag = stack.getTagElement(Arcanus.MODID);

if (tag == null || tag.getInt("Mana") <= 0) {
return Util.makeDescriptionId("item", BuiltInRegistries.ITEM.getKey(this)) + "_empty";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/cammiescorner/arcanus/item/WandItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public WandItem(float castingMultiplier, int maxExp, @Nullable Supplier<Item> up
this.maxExp = maxExp;
this.upgrade = upgrade;
ImmutableMultimap.Builder<Attribute, AttributeModifier> builder = ImmutableMultimap.builder();
builder.put(ArcanusEntityAttributes.MANA_COST, new AttributeModifier(MANA_COST, "Mana Cost", castingMultiplier, AttributeModifier.Operation.MULTIPLY_TOTAL));
builder.put(ArcanusEntityAttributes.MANA_COST.get(), new AttributeModifier(MANA_COST, "Mana Cost", castingMultiplier, AttributeModifier.Operation.MULTIPLY_TOTAL));
this.attributeModifiers = builder.build();
}

@Override
public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> tooltip, TooltipFlag context) {
CompoundTag nbt = stack.getTagElement(Arcanus.MOD_ID);
CompoundTag nbt = stack.getTagElement(Arcanus.MODID);
int xp = nbt != null ? nbt.getInt("Exp") : 0;
tooltip.add(Component.literal(xp + "/" + getMaxExp()).append(" Exp").withStyle(ChatFormatting.DARK_AQUA));
if (hasUpgrade()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected ItemStack run(ItemStack stack, LootContext context) {

@Override
public LootItemFunctionType getType() {
return ArcanusLootFunctions.SET_SPELL_BOOK_NBT;
return ArcanusLootFunctions.SET_SPELL_BOOK_NBT.get();
}

public static class Builder extends LootItemConditionalFunction.Builder<SetSpellBookNbtLootFunction.Builder> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ private PlayerMixin(EntityType<? extends LivingEntity> entityType, Level world)

@ModifyReturnValue(method = "createAttributes", at = @At("RETURN"))
private static AttributeSupplier.Builder createAttributes(AttributeSupplier.Builder builder) {
return builder.add(ArcanusEntityAttributes.MANA_COST).add(ArcanusEntityAttributes.MANA_REGEN).add(ArcanusEntityAttributes.BURNOUT_REGEN).add(ArcanusEntityAttributes.MANA_LOCK);
if (!ArcanusEntityAttributes.isInitialized()) return builder;
return builder.add(ArcanusEntityAttributes.MANA_COST.get()).add(ArcanusEntityAttributes.MANA_REGEN.get()).add(ArcanusEntityAttributes.BURNOUT_REGEN.get()).add(ArcanusEntityAttributes.MANA_LOCK.get());
}
}
Loading

0 comments on commit 09c6740

Please sign in to comment.