From 8adf52eb935ba3abb633ed53ef475a99b0438db6 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 23 Dec 2021 13:27:52 +0100 Subject: [PATCH] some refactoring --- .../java/de/ellpeck/naturesaura/Helper.java | 2 +- .../de/ellpeck/naturesaura/InternalHooks.java | 6 ++---- .../naturesaura/api/NaturesAuraAPI.java | 15 +++++++-------- .../naturesaura/api/aura/chunk/IAuraChunk.java | 2 +- .../naturesaura/api/misc/ILevelData.java | 2 +- .../blocks/tiles/BlockEntityImpl.java | 2 +- .../blocks/tiles/BlockEntityNatureAltar.java | 6 +++--- .../naturesaura/chunk/AuraChunkProvider.java | 2 +- .../chunk/effect/ReplenishingEffect.java | 3 +-- .../compat/jei/JEINaturesAuraPlugin.java | 2 +- .../enchant/AuraMendingEnchantment.java | 4 ++-- .../naturesaura/events/ClientEvents.java | 11 +++-------- .../naturesaura/events/CommonEvents.java | 6 +++--- .../naturesaura/items/ItemAuraCache.java | 18 ++++++++---------- .../de/ellpeck/naturesaura/misc/LevelData.java | 3 +-- .../naturesaura/packet/PacketAuraChunk.java | 3 +-- 16 files changed, 37 insertions(+), 50 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/Helper.java b/src/main/java/de/ellpeck/naturesaura/Helper.java index 4363c238..2a1236b6 100644 --- a/src/main/java/de/ellpeck/naturesaura/Helper.java +++ b/src/main/java/de/ellpeck/naturesaura/Helper.java @@ -207,7 +207,7 @@ public final class Helper { @Nullable @Override public LazyOptional getCapability(@Nonnull Capability capability, @Nullable Direction facing) { - if (capability == NaturesAuraAPI.capAuraRecharge) + if (capability == NaturesAuraAPI.CAP_AURA_RECHARGE) return this.recharge.cast(); return LazyOptional.empty(); } diff --git a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java index 606bc3d9..a020bad5 100644 --- a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java +++ b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java @@ -2,7 +2,6 @@ package de.ellpeck.naturesaura; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; -import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.multiblock.IMultiblock; import de.ellpeck.naturesaura.blocks.multi.Multiblock; @@ -11,7 +10,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Tuple; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; @@ -39,9 +37,9 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks { private boolean auraPlayerInteraction(Player player, int amount, boolean extract, boolean simulate) { if (extract && player.isCreative()) return true; - var stack = Helper.getEquippedItem(s -> s.getCapability(NaturesAuraAPI.capAuraContainer).isPresent(), player); + var stack = Helper.getEquippedItem(s -> s.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).isPresent(), player); if (!stack.isEmpty()) { - var container = stack.getCapability(NaturesAuraAPI.capAuraContainer).orElse(null); + var container = stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).orElse(null); if (extract) { return container.drainAura(amount, simulate) > 0; } else { diff --git a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java index eeac89cf..73bd1e56 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java +++ b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java @@ -43,8 +43,7 @@ import java.util.function.Supplier; public final class NaturesAuraAPI { public static final String MOD_ID = "naturesaura"; - public static final String API_ID = MOD_ID + "api"; - public static final String VERSION = "9"; + /** * A map of all the block states that the Botanist's Pickaxe can convert * into their mossy variations. Contains mossy brick and mossy cobblestone @@ -107,14 +106,14 @@ public final class NaturesAuraAPI { * The capability for any item or block that stores Aura in the form of an * {@link IAuraContainer} */ - public static Capability capAuraContainer = CapabilityManager.get(new CapabilityToken<>() { + public static final Capability CAP_AURA_CONTAINER = CapabilityManager.get(new CapabilityToken<>() { }); /** * The capability for any item that can be recharged from an Aura storage * container like the Aura Cache in the form of {@link IAuraRecharge} by a * player holding it in their hand */ - public static Capability capAuraRecharge = CapabilityManager.get(new CapabilityToken<>() { + public static final Capability CAP_AURA_RECHARGE = CapabilityManager.get(new CapabilityToken<>() { }); /** * The capability that any chunk in a level has to store Aura in it. As this @@ -124,7 +123,7 @@ public final class NaturesAuraAPI { * helper method {@link IAuraChunk#getAuraChunk(net.minecraft.world.level.Level, * BlockPos)}. */ - public static Capability capAuraChunk = CapabilityManager.get(new CapabilityToken<>() { + public static final Capability CAP_AURA_CHUNK = CapabilityManager.get(new CapabilityToken<>() { }); /** * The capability that any level has to store Nature's Aura specific data in @@ -132,14 +131,14 @@ public final class NaturesAuraAPI { * {@link ILevelData#getLevelData(net.minecraft.world.level.Level)} or * {@link ILevelData#getOverworldData(net.minecraft.world.level.Level)}. */ - public static Capability capLevelData = CapabilityManager.get(new CapabilityToken<>() { + public static final Capability CAP_LEVEL_DATA = CapabilityManager.get(new CapabilityToken<>() { }); private static final IInternalHooks INSTANCE; static { try { - INSTANCE = (IInternalHooks) Class.forName("de.ellpeck.naturesaura.InternalHooks").newInstance(); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + INSTANCE = (IInternalHooks) Class.forName("de.ellpeck.naturesaura.InternalHooks").getConstructor().newInstance(); + } catch (Exception e) { throw new RuntimeException(e); } } diff --git a/src/main/java/de/ellpeck/naturesaura/api/aura/chunk/IAuraChunk.java b/src/main/java/de/ellpeck/naturesaura/api/aura/chunk/IAuraChunk.java index c87360e2..23769a17 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/aura/chunk/IAuraChunk.java +++ b/src/main/java/de/ellpeck/naturesaura/api/aura/chunk/IAuraChunk.java @@ -36,7 +36,7 @@ public interface IAuraChunk extends INBTSerializable { */ static IAuraChunk getAuraChunk(Level level, BlockPos pos) { var chunk = (LevelChunk) level.getChunk(pos); - return chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null); + return chunk.getCapability(NaturesAuraAPI.CAP_AURA_CHUNK, null).orElse(null); } /** diff --git a/src/main/java/de/ellpeck/naturesaura/api/misc/ILevelData.java b/src/main/java/de/ellpeck/naturesaura/api/misc/ILevelData.java index 72f55d51..acd76ede 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/misc/ILevelData.java +++ b/src/main/java/de/ellpeck/naturesaura/api/misc/ILevelData.java @@ -10,7 +10,7 @@ import net.minecraftforge.items.IItemHandlerModifiable; public interface ILevelData extends ICapabilityProvider, INBTSerializable { static ILevelData getLevelData(Level level) { - return level.getCapability(NaturesAuraAPI.capLevelData, null).orElse(null); + return level.getCapability(NaturesAuraAPI.CAP_LEVEL_DATA, null).orElse(null); } static ILevelData getOverworldData(Level level) { diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/BlockEntityImpl.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/BlockEntityImpl.java index 1777f6d2..d9faad53 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/BlockEntityImpl.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/BlockEntityImpl.java @@ -114,7 +114,7 @@ public class BlockEntityImpl extends BlockEntity { this.itemHandler = handler == null ? LazyOptional.empty() : LazyOptional.of(() -> handler); } return this.itemHandler.cast(); - } else if (capability == NaturesAuraAPI.capAuraContainer) { + } else if (capability == NaturesAuraAPI.CAP_AURA_CONTAINER) { if (this.auraContainer == null) { var container = this.getAuraContainer(); this.auraContainer = container == null ? LazyOptional.empty() : LazyOptional.of(() -> container); diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/BlockEntityNatureAltar.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/BlockEntityNatureAltar.java index 56ded84b..bfc7682b 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/BlockEntityNatureAltar.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/BlockEntityNatureAltar.java @@ -42,12 +42,12 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable @Override protected boolean canInsert(ItemStack stack, int slot) { - return BlockEntityNatureAltar.this.getRecipeForInput(stack) != null || stack.getCapability(NaturesAuraAPI.capAuraContainer, null).isPresent(); + return BlockEntityNatureAltar.this.getRecipeForInput(stack) != null || stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER, null).isPresent(); } @Override protected boolean canExtract(ItemStack stack, int slot, int amount) { - var cap = stack.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null); + var cap = stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER, null).orElse(null); if (cap != null) { return cap.storeAura(1, true) <= 0; } else { @@ -119,7 +119,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable } var stack = this.items.getStackInSlot(0); - var container = stack.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null); + var container = stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER, null).orElse(null); if (!stack.isEmpty() && container != null) { var theoreticalDrain = this.container.drainAura(1000, true); if (theoreticalDrain > 0) { diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunkProvider.java b/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunkProvider.java index 61e9145b..8c664c2a 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunkProvider.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunkProvider.java @@ -33,7 +33,7 @@ public class AuraChunkProvider implements ICapabilityProvider, INBTSerializable< @Nullable @Override public LazyOptional getCapability(@Nonnull Capability capability, @Nullable Direction facing) { - return capability == NaturesAuraAPI.capAuraChunk ? this.lazyChunk.cast() : LazyOptional.empty(); + return capability == NaturesAuraAPI.CAP_AURA_CHUNK ? this.lazyChunk.cast() : LazyOptional.empty(); } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/ReplenishingEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/ReplenishingEffect.java index a69465ee..2f9269eb 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/ReplenishingEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/ReplenishingEffect.java @@ -6,7 +6,6 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect; import de.ellpeck.naturesaura.api.aura.chunk.ISpotDrainable; -import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.aura.type.IAuraType; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; @@ -25,7 +24,7 @@ public class ReplenishingEffect implements IDrainSpotEffect { if (spot < 0) { List tiles = new ArrayList<>(); Helper.getBlockEntitiesInArea(level, pos, 25, tile -> { - var container = tile.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null); + var container = tile.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER, null).orElse(null); if (container instanceof ISpotDrainable) tiles.add((ISpotDrainable) container); return false; diff --git a/src/main/java/de/ellpeck/naturesaura/compat/jei/JEINaturesAuraPlugin.java b/src/main/java/de/ellpeck/naturesaura/compat/jei/JEINaturesAuraPlugin.java index c6edf568..f6d951ec 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/jei/JEINaturesAuraPlugin.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/jei/JEINaturesAuraPlugin.java @@ -48,7 +48,7 @@ public class JEINaturesAuraPlugin implements IModPlugin { registration.registerSubtypeInterpreter(ModItems.AURA_BOTTLE, (stack, context) -> ItemAuraBottle.getType(stack).getName().toString()); var auraInterpreter = (IIngredientSubtypeInterpreter) (stack, context) -> { - var container = stack.getCapability(NaturesAuraAPI.capAuraContainer).orElse(null); + var container = stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).orElse(null); if (container != null) return String.valueOf(container.getStoredAura()); return IIngredientSubtypeInterpreter.NONE; diff --git a/src/main/java/de/ellpeck/naturesaura/enchant/AuraMendingEnchantment.java b/src/main/java/de/ellpeck/naturesaura/enchant/AuraMendingEnchantment.java index 5633627b..3ca4032d 100644 --- a/src/main/java/de/ellpeck/naturesaura/enchant/AuraMendingEnchantment.java +++ b/src/main/java/de/ellpeck/naturesaura/enchant/AuraMendingEnchantment.java @@ -20,12 +20,12 @@ public class AuraMendingEnchantment extends ModEnchantment { @Override public boolean canEnchant(ItemStack stack) { - return super.canEnchant(stack) && !stack.getCapability(NaturesAuraAPI.capAuraRecharge).isPresent(); + return super.canEnchant(stack) && !stack.getCapability(NaturesAuraAPI.CAP_AURA_RECHARGE).isPresent(); } @Override public boolean canApplyAtEnchantingTable(ItemStack stack) { - return super.canApplyAtEnchantingTable(stack) && !stack.getCapability(NaturesAuraAPI.capAuraRecharge).isPresent(); + return super.canApplyAtEnchantingTable(stack) && !stack.getCapability(NaturesAuraAPI.CAP_AURA_RECHARGE).isPresent(); } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java index 4ecb6440..82cf33ee 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java @@ -3,7 +3,6 @@ package de.ellpeck.naturesaura.events; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; -import com.mojang.math.Vector3d; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.ModConfig; import de.ellpeck.naturesaura.NaturesAura; @@ -27,16 +26,12 @@ import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.util.Tuple; -import net.minecraft.world.entity.Entity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.*; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.Heightmap; -import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.Vec3; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.event.RenderGameOverlayEvent; @@ -250,7 +245,7 @@ public class ClientEvents { var res = event.getWindow(); if (mc.player != null) { if (!heldCache.isEmpty()) { - var container = heldCache.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null); + var container = heldCache.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER, null).orElse(null); var width = Mth.ceil(container.getStoredAura() / (float) container.getMaxAura() * 80); int conf = ModConfig.instance.cacheBarLocation.get(); @@ -360,7 +355,7 @@ public class ClientEvents { IAuraContainer container; var x = res.getGuiScaledWidth() / 2; var y = res.getGuiScaledHeight() / 2; - if (tile != null && (container = tile.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null)) != null) { + if (tile != null && (container = tile.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER, null).orElse(null)) != null) { var state = mc.level.getBlockState(pos); var blockStack = state.getBlock().getCloneItemStack(state, blockHitResult, mc.level, pos, mc.player); this.drawContainerInfo(stack, container.getStoredAura(), container.getMaxAura(), container.getAuraColor(), @@ -369,7 +364,7 @@ public class ClientEvents { if (tile instanceof BlockEntityNatureAltar) { var tileStack = ((BlockEntityNatureAltar) tile).getItemHandler().getStackInSlot(0); if (!tileStack.isEmpty()) { - var stackCont = tileStack.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null); + var stackCont = tileStack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER, null).orElse(null); if (stackCont != null) { this.drawContainerInfo(stack, stackCont.getStoredAura(), stackCont.getMaxAura(), stackCont.getAuraColor(), mc, res, 55, tileStack.getDisplayName().getString(), null); diff --git a/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java b/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java index 22394012..b1d192d6 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java @@ -73,7 +73,7 @@ public class CommonEvents { public void onChunkUnload(ChunkEvent.Unload event) { var iChunk = event.getChunk(); if (iChunk instanceof LevelChunk chunk) { - var auraChunk = chunk.getCapability(NaturesAuraAPI.capAuraChunk).orElse(null); + var auraChunk = chunk.getCapability(NaturesAuraAPI.CAP_AURA_CHUNK).orElse(null); if (auraChunk instanceof AuraChunk) { var data = (LevelData) ILevelData.getLevelData(chunk.getLevel()); data.auraChunksWithSpots.remove(chunk.getPos().toLong()); @@ -109,7 +109,7 @@ public class CommonEvents { var chunk = holder.getTickingChunk(); if (chunk == null) continue; - var auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null); + var auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.CAP_AURA_CHUNK, null).orElse(null); if (auraChunk != null) auraChunk.update(); } @@ -149,7 +149,7 @@ public class CommonEvents { var chunk = Helper.getLoadedChunk(player.level, pos.x, pos.z); if (chunk == null) return false; - var auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null); + var auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.CAP_AURA_CHUNK, null).orElse(null); if (auraChunk == null) return false; PacketHandler.sendTo(player, auraChunk.makePacket()); diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java b/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java index 1dd9a7bf..4d962896 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java @@ -4,9 +4,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Vector3f; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.api.NaturesAuraAPI; -import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.aura.container.ItemAuraContainer; -import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge; import de.ellpeck.naturesaura.api.render.ITrinketItem; import de.ellpeck.naturesaura.enchant.ModEnchantments; import net.minecraft.client.Minecraft; @@ -44,14 +42,14 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem { @Override public void inventoryTick(ItemStack stackIn, Level levelIn, Entity entityIn, int itemSlot, boolean isSelected) { if (!levelIn.isClientSide && entityIn instanceof Player player) { - if (player.isCrouching() && stackIn.getCapability(NaturesAuraAPI.capAuraContainer).isPresent()) { - var container = stackIn.getCapability(NaturesAuraAPI.capAuraContainer).orElse(null); + if (player.isCrouching() && stackIn.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).isPresent()) { + var container = stackIn.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).orElse(null); if (container.getStoredAura() <= 0) { return; } for (var i = 0; i < player.getInventory().getContainerSize(); i++) { var stack = player.getInventory().getItem(i); - var recharge = stack.getCapability(NaturesAuraAPI.capAuraRecharge).orElse(null); + var recharge = stack.getCapability(NaturesAuraAPI.CAP_AURA_RECHARGE).orElse(null); if (recharge != null) { if (recharge.rechargeFromContainer(container, itemSlot, i, player.getInventory().selected == i)) break; @@ -72,7 +70,7 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem { items.add(new ItemStack(this)); var stack = new ItemStack(this); - stack.getCapability(NaturesAuraAPI.capAuraContainer).ifPresent(container -> { + stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).ifPresent(container -> { container.storeAura(container.getMaxAura(), false); items.add(stack); }); @@ -86,8 +84,8 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem { @Override public int getBarWidth(ItemStack stack) { - if (stack.getCapability(NaturesAuraAPI.capAuraContainer).isPresent()) { - var container = stack.getCapability(NaturesAuraAPI.capAuraContainer).orElse(null); + if (stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).isPresent()) { + var container = stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).orElse(null); return Math.round((container.getStoredAura() / (float) container.getMaxAura()) * 13); } return 0; @@ -95,7 +93,7 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem { @Override public int getBarColor(ItemStack stack) { - var cap = stack.getCapability(NaturesAuraAPI.capAuraContainer).orElse(null); + var cap = stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).orElse(null); return cap != null ? cap.getAuraColor() : super.getBarColor(stack); } @@ -108,7 +106,7 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem { @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability capability, @Nullable Direction facing) { - if (capability == NaturesAuraAPI.capAuraContainer) { + if (capability == NaturesAuraAPI.CAP_AURA_CONTAINER) { return this.container.cast(); } else { return LazyOptional.empty(); diff --git a/src/main/java/de/ellpeck/naturesaura/misc/LevelData.java b/src/main/java/de/ellpeck/naturesaura/misc/LevelData.java index e3db9488..c86a6af0 100644 --- a/src/main/java/de/ellpeck/naturesaura/misc/LevelData.java +++ b/src/main/java/de/ellpeck/naturesaura/misc/LevelData.java @@ -18,7 +18,6 @@ import net.minecraft.nbt.LongTag; import net.minecraft.nbt.Tag; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Tuple; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.Vec3; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; @@ -39,7 +38,7 @@ public class LevelData implements ILevelData { @Nullable @Override public LazyOptional getCapability(@Nonnull Capability capability, @Nullable Direction facing) { - return capability == NaturesAuraAPI.capLevelData ? this.lazyThis.cast() : LazyOptional.empty(); + return capability == NaturesAuraAPI.CAP_LEVEL_DATA ? this.lazyThis.cast() : LazyOptional.empty(); } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/packet/PacketAuraChunk.java b/src/main/java/de/ellpeck/naturesaura/packet/PacketAuraChunk.java index dedb8427..1e2a3911 100644 --- a/src/main/java/de/ellpeck/naturesaura/packet/PacketAuraChunk.java +++ b/src/main/java/de/ellpeck/naturesaura/packet/PacketAuraChunk.java @@ -7,7 +7,6 @@ import de.ellpeck.naturesaura.events.ClientEvents; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.level.Level; -import net.minecraft.world.level.chunk.LevelChunk; import net.minecraftforge.network.NetworkEvent; import org.apache.commons.lang3.mutable.MutableInt; @@ -68,7 +67,7 @@ public class PacketAuraChunk { var chunk = level.getChunk(this.chunkX, this.chunkZ); if (chunk.isEmpty()) return false; - var auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.capAuraChunk).orElse(null); + var auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.CAP_AURA_CHUNK).orElse(null); if (auraChunk == null) return false; auraChunk.setSpots(this.drainSpots);