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