move some API stuff around

This commit is contained in:
Ellpeck 2018-11-12 22:04:40 +01:00
parent a10210888c
commit 13d6cf778a
14 changed files with 94 additions and 97 deletions

View file

@ -1,10 +1,8 @@
package de.ellpeck.naturesaura; package de.ellpeck.naturesaura;
import baubles.api.BaublesApi; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.NACapabilities;
import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge; import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl; import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl;
import de.ellpeck.naturesaura.compat.Compat;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -16,6 +14,7 @@ import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents; import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
@ -27,10 +26,10 @@ import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.ChunkProviderServer; import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@ -174,13 +173,13 @@ public final class Helper {
@Override @Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) { public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
return capability == NACapabilities.auraRecharge; return capability == NaturesAuraAPI.capAuraRecharge;
} }
@Nullable @Nullable
@Override @Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) { public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
return capability == NACapabilities.auraRecharge ? (T) this.recharge : null; return capability == NaturesAuraAPI.capAuraRecharge ? (T) this.recharge : null;
} }
}; };
} }
@ -214,4 +213,19 @@ public final class Helper {
return state.withProperty(prop, value); return state.withProperty(prop, value);
return null; return null;
} }
public static <T> void registerCap(Class<T> type) {
CapabilityManager.INSTANCE.register(type, new Capability.IStorage<T>() {
@Nullable
@Override
public NBTBase writeNBT(Capability capability, Object instance, EnumFacing side) {
return null;
}
@Override
public void readNBT(Capability capability, Object instance, EnumFacing side, NBTBase nbt) {
}
}, () -> null);
}
} }

View file

@ -1,7 +1,6 @@
package de.ellpeck.naturesaura; package de.ellpeck.naturesaura;
import baubles.api.BaublesApi; import baubles.api.BaublesApi;
import de.ellpeck.naturesaura.api.NACapabilities;
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.compat.Compat; import de.ellpeck.naturesaura.compat.Compat;
@ -26,8 +25,8 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
IItemHandler baubles = BaublesApi.getBaublesHandler(player); IItemHandler baubles = BaublesApi.getBaublesHandler(player);
for (int i = 0; i < baubles.getSlots(); i++) { for (int i = 0; i < baubles.getSlots(); i++) {
ItemStack stack = baubles.getStackInSlot(i); ItemStack stack = baubles.getStackInSlot(i);
if (!stack.isEmpty() && stack.hasCapability(NACapabilities.auraContainer, null)) { if (!stack.isEmpty() && stack.hasCapability(NaturesAuraAPI.capAuraContainer, null)) {
amount -= stack.getCapability(NACapabilities.auraContainer, null).drainAura(amount, simulate); amount -= stack.getCapability(NaturesAuraAPI.capAuraContainer, null).drainAura(amount, simulate);
if (amount <= 0) if (amount <= 0)
return true; return true;
} }
@ -36,8 +35,8 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
for (int i = 0; i < player.inventory.getSizeInventory(); i++) { for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack stack = player.inventory.getStackInSlot(i); ItemStack stack = player.inventory.getStackInSlot(i);
if (!stack.isEmpty() && stack.hasCapability(NACapabilities.auraContainer, null)) { if (!stack.isEmpty() && stack.hasCapability(NaturesAuraAPI.capAuraContainer, null)) {
amount -= stack.getCapability(NACapabilities.auraContainer, null).drainAura(amount, simulate); amount -= stack.getCapability(NaturesAuraAPI.capAuraContainer, null).drainAura(amount, simulate);
if (amount <= 0) if (amount <= 0)
return true; return true;
} }
@ -58,8 +57,8 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
for (int z = (pos.getZ() - radius) >> 4; z <= (pos.getZ() + radius) >> 4; z++) { for (int z = (pos.getZ() - radius) >> 4; z <= (pos.getZ() + radius) >> 4; z++) {
if (Helper.isChunkLoaded(world, x, z)) { if (Helper.isChunkLoaded(world, x, z)) {
Chunk chunk = world.getChunk(x, z); Chunk chunk = world.getChunk(x, z);
if (chunk.hasCapability(NACapabilities.auraChunk, null)) { if (chunk.hasCapability(NaturesAuraAPI.capAuraChunk, null)) {
IAuraChunk auraChunk = chunk.getCapability(NACapabilities.auraChunk, null); IAuraChunk auraChunk = chunk.getCapability(NaturesAuraAPI.capAuraChunk, null);
auraChunk.getSpotsInArea(pos, radius, consumer); auraChunk.getSpotsInArea(pos, radius, consumer);
} }
} }

View file

@ -1,6 +1,5 @@
package de.ellpeck.naturesaura; package de.ellpeck.naturesaura;
import de.ellpeck.naturesaura.api.NACapabilities.StorageImpl;
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.aura.container.IAuraContainer;
@ -21,7 +20,6 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.SidedProxy;
@ -56,9 +54,9 @@ public final class NaturesAura {
@EventHandler @EventHandler
public void preInit(FMLPreInitializationEvent event) { public void preInit(FMLPreInitializationEvent event) {
NaturesAuraAPI.setInstance(new InternalHooks()); NaturesAuraAPI.setInstance(new InternalHooks());
CapabilityManager.INSTANCE.register(IAuraContainer.class, new StorageImpl<>(), () -> null); Helper.registerCap(IAuraContainer.class);
CapabilityManager.INSTANCE.register(IAuraRecharge.class, new StorageImpl<>(), () -> null); Helper.registerCap(IAuraRecharge.class);
CapabilityManager.INSTANCE.register(IAuraChunk.class, new StorageImpl<>(), () -> null); Helper.registerCap(IAuraChunk.class);
new ModBlocks(); new ModBlocks();
new ModItems(); new ModItems();

View file

@ -1,38 +0,0 @@
package de.ellpeck.naturesaura.api;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge;
import net.minecraft.nbt.NBTBase;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.Capability.IStorage;
import net.minecraftforge.common.capabilities.CapabilityInject;
import javax.annotation.Nullable;
public final class NACapabilities {
@CapabilityInject(IAuraContainer.class)
public static Capability<IAuraContainer> auraContainer;
@CapabilityInject(IAuraRecharge.class)
public static Capability<IAuraRecharge> auraRecharge;
@CapabilityInject(IAuraChunk.class)
public static Capability<IAuraChunk> auraChunk;
public static class StorageImpl<T> implements IStorage<T> {
@Nullable
@Override
public NBTBase writeNBT(Capability<T> capability, T instance, EnumFacing side) {
return null;
}
@Override
public void readNBT(Capability<T> capability, T instance, EnumFacing side, NBTBase nbt) {
}
}
}

View file

@ -2,6 +2,7 @@ package de.ellpeck.naturesaura.api;
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.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge;
import de.ellpeck.naturesaura.api.aura.type.BasicAuraType; import de.ellpeck.naturesaura.api.aura.type.BasicAuraType;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.api.internal.StubHooks; import de.ellpeck.naturesaura.api.internal.StubHooks;
@ -14,6 +15,8 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.DimensionType; import net.minecraft.world.DimensionType;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.mutable.MutableInt;
import java.util.ArrayList; import java.util.ArrayList;
@ -66,6 +69,29 @@ public final class NaturesAuraAPI {
public static final IAuraType TYPE_END = new BasicAuraType(new ResourceLocation(MOD_ID, "end"), DimensionType.THE_END, 0x302624).register(); public static final IAuraType TYPE_END = new BasicAuraType(new ResourceLocation(MOD_ID, "end"), DimensionType.THE_END, 0x302624).register();
public static final IAuraType TYPE_OTHER = new BasicAuraType(new ResourceLocation(MOD_ID, "other"), null, 0x2fa8a0).register(); public static final IAuraType TYPE_OTHER = new BasicAuraType(new ResourceLocation(MOD_ID, "other"), null, 0x2fa8a0).register();
/**
* The capability for any item or block that stores Aura in the form of an
* {@link IAuraContainer}
*/
@CapabilityInject(IAuraContainer.class)
public static Capability<IAuraContainer> capAuraContainer;
/**
* 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
*/
@CapabilityInject(IAuraRecharge.class)
public static Capability<IAuraRecharge> capAuraRecharge;
/**
* The capability that any chunk in a world has to store Aura in it. As this
* is only applicable to chunks and all chunks in the world automatically
* get assigned this capability, using it directly is not necessary for
* addon developers. To retrieve this capability from any chunk, use the
* helper method {@link IAuraChunk#getAuraChunk(World, BlockPos)}.
*/
@CapabilityInject(IAuraChunk.class)
public static Capability<IAuraChunk> capAuraChunk;
/** /**
* This method returns the active {@link IInternalHooks} instance which can * This method returns the active {@link IInternalHooks} instance which can
* be used to hook into the mod's internal functionalities. This is * be used to hook into the mod's internal functionalities. This is

View file

@ -1,6 +1,5 @@
package de.ellpeck.naturesaura.api.aura.chunk; package de.ellpeck.naturesaura.api.aura.chunk;
import de.ellpeck.naturesaura.api.NACapabilities;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -37,8 +36,8 @@ public interface IAuraChunk extends ICapabilityProvider, INBTSerializable<NBTTag
*/ */
static IAuraChunk getAuraChunk(World world, BlockPos pos) { static IAuraChunk getAuraChunk(World world, BlockPos pos) {
Chunk chunk = world.getChunk(pos); Chunk chunk = world.getChunk(pos);
if (chunk.hasCapability(NACapabilities.auraChunk, null)) { if (chunk.hasCapability(NaturesAuraAPI.capAuraChunk, null)) {
return chunk.getCapability(NACapabilities.auraChunk, null); return chunk.getCapability(NaturesAuraAPI.capAuraChunk, null);
} else { } else {
return null; return null;
} }

View file

@ -1,7 +1,7 @@
package de.ellpeck.naturesaura.aura.chunk; package de.ellpeck.naturesaura.aura.chunk;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NACapabilities; 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.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
@ -129,13 +129,13 @@ public class AuraChunk implements IAuraChunk {
@Override @Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) { public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
return capability == NACapabilities.auraChunk; return capability == NaturesAuraAPI.capAuraChunk;
} }
@Nullable @Nullable
@Override @Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) { public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
return capability == NACapabilities.auraChunk ? (T) this : null; return capability == NaturesAuraAPI.capAuraChunk ? (T) this : null;
} }
@Override @Override

View file

@ -1,7 +1,7 @@
package de.ellpeck.naturesaura.aura.chunk.effect; package de.ellpeck.naturesaura.aura.chunk.effect;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NACapabilities; 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;
@ -22,8 +22,8 @@ public class ReplenishingEffect implements IDrainSpotEffect {
if (amount < 0) { if (amount < 0) {
List<ISpotDrainable> tiles = new ArrayList<>(); List<ISpotDrainable> tiles = new ArrayList<>();
Helper.getTileEntitiesInArea(world, pos, 25, tile -> { Helper.getTileEntitiesInArea(world, pos, 25, tile -> {
if (tile.hasCapability(NACapabilities.auraContainer, null)) { if (tile.hasCapability(NaturesAuraAPI.capAuraContainer, null)) {
IAuraContainer container = tile.getCapability(NACapabilities.auraContainer, null); IAuraContainer container = tile.getCapability(NaturesAuraAPI.capAuraContainer, null);
if (container instanceof ISpotDrainable) { if (container instanceof ISpotDrainable) {
tiles.add((ISpotDrainable) container); tiles.add((ISpotDrainable) container);
} }

View file

@ -1,6 +1,6 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.NACapabilities; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -94,7 +94,7 @@ public class TileEntityImpl extends TileEntity {
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) { public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
return this.getItemHandler(facing) != null; return this.getItemHandler(facing) != null;
} else if (capability == NACapabilities.auraContainer) { } else if (capability == NaturesAuraAPI.capAuraContainer) {
return this.getAuraContainer(facing) != null; return this.getAuraContainer(facing) != null;
} else { } else {
return super.hasCapability(capability, facing); return super.hasCapability(capability, facing);
@ -106,7 +106,7 @@ public class TileEntityImpl extends TileEntity {
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) { public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
return (T) this.getItemHandler(facing); return (T) this.getItemHandler(facing);
} else if (capability == NACapabilities.auraContainer) { } else if (capability == NaturesAuraAPI.capAuraContainer) {
return (T) this.getAuraContainer(facing); return (T) this.getAuraContainer(facing);
} else { } else {
return super.getCapability(capability, facing); return super.getCapability(capability, facing);

View file

@ -1,7 +1,6 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NACapabilities;
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.BasicAuraContainer; import de.ellpeck.naturesaura.api.aura.container.BasicAuraContainer;
@ -39,13 +38,13 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable {
@Override @Override
protected boolean canInsert(ItemStack stack, int slot) { protected boolean canInsert(ItemStack stack, int slot) {
return getRecipeForInput(stack) != null || stack.hasCapability(NACapabilities.auraContainer, null); return getRecipeForInput(stack) != null || stack.hasCapability(NaturesAuraAPI.capAuraContainer, null);
} }
@Override @Override
protected boolean canExtract(ItemStack stack, int slot, int amount) { protected boolean canExtract(ItemStack stack, int slot, int amount) {
if (stack.hasCapability(NACapabilities.auraContainer, null)) if (stack.hasCapability(NaturesAuraAPI.capAuraContainer, null))
return stack.getCapability(NACapabilities.auraContainer, null).storeAura(1, true) <= 0; return stack.getCapability(NaturesAuraAPI.capAuraContainer, null).storeAura(1, true) <= 0;
else else
return getRecipeForInput(stack) == null; return getRecipeForInput(stack) == null;
} }
@ -98,8 +97,8 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable {
} }
ItemStack stack = this.items.getStackInSlot(0); ItemStack stack = this.items.getStackInSlot(0);
if (!stack.isEmpty() && stack.hasCapability(NACapabilities.auraContainer, null)) { if (!stack.isEmpty() && stack.hasCapability(NaturesAuraAPI.capAuraContainer, null)) {
IAuraContainer container = stack.getCapability(NACapabilities.auraContainer, null); IAuraContainer container = stack.getCapability(NaturesAuraAPI.capAuraContainer, null);
int theoreticalDrain = this.container.drainAura(10, true); int theoreticalDrain = this.container.drainAura(10, true);
if (theoreticalDrain > 0) { if (theoreticalDrain > 0) {
int stored = container.storeAura(theoreticalDrain, false); int stored = container.storeAura(theoreticalDrain, false);

View file

@ -2,7 +2,7 @@ package de.ellpeck.naturesaura.events;
import baubles.api.BaublesApi; import baubles.api.BaublesApi;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NACapabilities; 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.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
@ -124,7 +124,7 @@ public class ClientEvents {
} }
if (!cache.isEmpty()) { if (!cache.isEmpty()) {
IAuraContainer container = cache.getCapability(NACapabilities.auraContainer, null); IAuraContainer container = cache.getCapability(NaturesAuraAPI.capAuraContainer, null);
int width = MathHelper.ceil(container.getStoredAura() / (float) container.getMaxAura() * 80); int width = MathHelper.ceil(container.getStoredAura() / (float) container.getMaxAura() * 80);
int x = res.getScaledWidth() / 2 - 173 - (mc.player.getHeldItemOffhand().isEmpty() ? 0 : 29); int x = res.getScaledWidth() / 2 - 173 - (mc.player.getHeldItemOffhand().isEmpty() ? 0 : 29);
int y = res.getScaledHeight() - 8; int y = res.getScaledHeight() - 8;
@ -177,8 +177,8 @@ public class ClientEvents {
BlockPos pos = mc.objectMouseOver.getBlockPos(); BlockPos pos = mc.objectMouseOver.getBlockPos();
if (pos != null) { if (pos != null) {
TileEntity tile = mc.world.getTileEntity(pos); TileEntity tile = mc.world.getTileEntity(pos);
if (tile != null && tile.hasCapability(NACapabilities.auraContainer, null)) { if (tile != null && tile.hasCapability(NaturesAuraAPI.capAuraContainer, null)) {
IAuraContainer container = tile.getCapability(NACapabilities.auraContainer, null); IAuraContainer container = tile.getCapability(NaturesAuraAPI.capAuraContainer, null);
IBlockState state = mc.world.getBlockState(pos); IBlockState state = mc.world.getBlockState(pos);
ItemStack blockStack = state.getBlock().getPickBlock(state, mc.objectMouseOver, mc.world, pos, mc.player); ItemStack blockStack = state.getBlock().getPickBlock(state, mc.objectMouseOver, mc.world, pos, mc.player);
@ -186,8 +186,8 @@ public class ClientEvents {
if (tile instanceof TileEntityNatureAltar) { if (tile instanceof TileEntityNatureAltar) {
ItemStack tileStack = ((TileEntityNatureAltar) tile).getItemHandler(null).getStackInSlot(0); ItemStack tileStack = ((TileEntityNatureAltar) tile).getItemHandler(null).getStackInSlot(0);
if (!tileStack.isEmpty() && tileStack.hasCapability(NACapabilities.auraContainer, null)) { if (!tileStack.isEmpty() && tileStack.hasCapability(NaturesAuraAPI.capAuraContainer, null)) {
IAuraContainer stackContainer = tileStack.getCapability(NACapabilities.auraContainer, null); IAuraContainer stackContainer = tileStack.getCapability(NaturesAuraAPI.capAuraContainer, null);
this.drawContainerInfo(stackContainer, mc, res, 55, tileStack.getDisplayName()); this.drawContainerInfo(stackContainer, mc, res, 55, tileStack.getDisplayName());
} }
} }

View file

@ -2,7 +2,7 @@ package de.ellpeck.naturesaura.events;
import de.ellpeck.naturesaura.ModConfig; import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NACapabilities; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.aura.chunk.AuraChunk; import de.ellpeck.naturesaura.aura.chunk.AuraChunk;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
@ -36,8 +36,8 @@ public class CommonEvents {
Iterator<Chunk> chunks = event.world.getPersistentChunkIterable(((WorldServer) event.world).getPlayerChunkMap().getChunkIterator()); Iterator<Chunk> chunks = event.world.getPersistentChunkIterable(((WorldServer) event.world).getPlayerChunkMap().getChunkIterator());
while (chunks.hasNext()) { while (chunks.hasNext()) {
Chunk chunk = chunks.next(); Chunk chunk = chunks.next();
if (chunk.hasCapability(NACapabilities.auraChunk, null)) { if (chunk.hasCapability(NaturesAuraAPI.capAuraChunk, null)) {
AuraChunk auraChunk = (AuraChunk) chunk.getCapability(NACapabilities.auraChunk, null); AuraChunk auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.capAuraChunk, null);
auraChunk.update(); auraChunk.update();
} }
} }
@ -49,8 +49,8 @@ public class CommonEvents {
@SubscribeEvent @SubscribeEvent
public void onChunkWatch(ChunkWatchEvent.Watch event) { public void onChunkWatch(ChunkWatchEvent.Watch event) {
Chunk chunk = event.getChunkInstance(); Chunk chunk = event.getChunkInstance();
if (!chunk.getWorld().isRemote && chunk.hasCapability(NACapabilities.auraChunk, null)) { if (!chunk.getWorld().isRemote && chunk.hasCapability(NaturesAuraAPI.capAuraChunk, null)) {
AuraChunk auraChunk = (AuraChunk) chunk.getCapability(NACapabilities.auraChunk, null); AuraChunk auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.capAuraChunk, null);
PacketHandler.sendTo(event.getPlayer(), auraChunk.makePacket()); PacketHandler.sendTo(event.getPlayer(), auraChunk.makePacket());
} }
} }

View file

@ -1,7 +1,7 @@
package de.ellpeck.naturesaura.items; package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NACapabilities; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; 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.renderers.ITrinketItem; import de.ellpeck.naturesaura.renderers.ITrinketItem;
@ -37,9 +37,9 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem {
EntityPlayer player = (EntityPlayer) entityIn; EntityPlayer player = (EntityPlayer) entityIn;
if (player.isSneaking()) { if (player.isSneaking()) {
ItemStack stack = player.getHeldItemMainhand(); ItemStack stack = player.getHeldItemMainhand();
if (stack.hasCapability(NACapabilities.auraRecharge, null)) { if (stack.hasCapability(NaturesAuraAPI.capAuraRecharge, null)) {
IAuraContainer container = stackIn.getCapability(NACapabilities.auraContainer, null); IAuraContainer container = stackIn.getCapability(NaturesAuraAPI.capAuraContainer, null);
stack.getCapability(NACapabilities.auraRecharge, null).rechargeFromContainer(container); stack.getCapability(NaturesAuraAPI.capAuraRecharge, null).rechargeFromContainer(container);
} }
} }
} }
@ -51,7 +51,7 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem {
items.add(new ItemStack(this)); items.add(new ItemStack(this));
ItemStack stack = new ItemStack(this); ItemStack stack = new ItemStack(this);
IAuraContainer container = stack.getCapability(NACapabilities.auraContainer, null); IAuraContainer container = stack.getCapability(NaturesAuraAPI.capAuraContainer, null);
container.storeAura(container.getMaxAura(), false); container.storeAura(container.getMaxAura(), false);
items.add(stack); items.add(stack);
} }
@ -64,8 +64,8 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem {
@Override @Override
public double getDurabilityForDisplay(ItemStack stack) { public double getDurabilityForDisplay(ItemStack stack) {
if (stack.hasCapability(NACapabilities.auraContainer, null)) { if (stack.hasCapability(NaturesAuraAPI.capAuraContainer, null)) {
IAuraContainer container = stack.getCapability(NACapabilities.auraContainer, null); IAuraContainer container = stack.getCapability(NaturesAuraAPI.capAuraContainer, null);
return 1 - container.getStoredAura() / (double) container.getMaxAura(); return 1 - container.getStoredAura() / (double) container.getMaxAura();
} else { } else {
return 0; return 0;
@ -80,13 +80,13 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem {
@Override @Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) { public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
return capability == NACapabilities.auraContainer; return capability == NaturesAuraAPI.capAuraContainer;
} }
@Nullable @Nullable
@Override @Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) { public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
if (capability == NACapabilities.auraContainer) { if (capability == NaturesAuraAPI.capAuraContainer) {
return (T) this.container; return (T) this.container;
} else { } else {
return null; return null;

View file

@ -1,7 +1,7 @@
package de.ellpeck.naturesaura.packet; package de.ellpeck.naturesaura.packet;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NACapabilities; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.aura.chunk.AuraChunk; import de.ellpeck.naturesaura.aura.chunk.AuraChunk;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -70,8 +70,8 @@ public class PacketAuraChunk implements IMessage {
World world = Minecraft.getMinecraft().world; World world = Minecraft.getMinecraft().world;
if (world != null) { if (world != null) {
Chunk chunk = world.getChunk(message.chunkX, message.chunkZ); Chunk chunk = world.getChunk(message.chunkX, message.chunkZ);
if (chunk.hasCapability(NACapabilities.auraChunk, null)) { if (chunk.hasCapability(NaturesAuraAPI.capAuraChunk, null)) {
AuraChunk auraChunk = (AuraChunk) chunk.getCapability(NACapabilities.auraChunk, null); AuraChunk auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.capAuraChunk, null);
auraChunk.setSpots(message.drainSpots); auraChunk.setSpots(message.drainSpots);
} }
} }