From f3906141a12d0e104a9617782c45744396e84307 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 20 Oct 2018 21:19:08 +0200 Subject: [PATCH] added aura cache --- .../java/de/ellpeck/naturesaura/Helper.java | 30 ++++ .../de/ellpeck/naturesaura/NaturesAura.java | 12 +- .../naturesaura/aura/BasicAuraContainer.java | 9 +- .../naturesaura/aura/Capabilities.java | 45 +++++ .../naturesaura/aura/FiniteAuraContainer.java | 4 +- .../naturesaura/aura/IAuraContainer.java | 2 + .../aura/IAuraContainerProvider.java | 8 - .../naturesaura/aura/IAuraRecharge.java | 7 + .../naturesaura/aura/ItemAuraContainer.java | 68 ++++++++ .../blocks/BlockAncientLeaves.java | 5 +- .../ellpeck/naturesaura/blocks/ModBlocks.java | 1 + .../blocks/tiles/TileEntityAncientLeaves.java | 13 +- .../blocks/tiles/TileEntityImpl.java | 11 +- .../blocks/tiles/TileEntityNatureAltar.java | 83 +++++---- .../naturesaura/compat/BaublesCompat.java | 31 ++-- .../naturesaura/events/ClientEvents.java | 163 +++++++++++------- .../naturesaura/items/ItemAuraCache.java | 92 ++++++++++ .../de/ellpeck/naturesaura/items/ItemEye.java | 1 + .../ellpeck/naturesaura/items/ModItems.java | 1 + .../naturesaura/items/tools/ItemAxeNA.java | 13 ++ .../naturesaura/items/tools/ItemHoeNA.java | 13 ++ .../items/tools/ItemPickaxeNA.java | 15 ++ .../naturesaura/items/tools/ItemShovelNA.java | 13 ++ .../naturesaura/items/tools/ItemSwordNA.java | 15 ++ .../naturesaura/recipes/ModRecipes.java | 3 +- .../blockstates/infused_stone.json | 14 ++ .../assets/naturesaura/lang/en_US.lang | 2 + .../naturesaura/models/item/aura_cache.json | 6 + .../naturesaura/recipes/aura_cache.json | 22 +++ .../textures/blocks/infused_stone.png | Bin 0 -> 314 bytes .../naturesaura/textures/gui/overlays.png | Bin 1304 -> 1301 bytes .../naturesaura/textures/items/aura_cache.png | Bin 0 -> 756 bytes 32 files changed, 567 insertions(+), 135 deletions(-) create mode 100644 src/main/java/de/ellpeck/naturesaura/aura/Capabilities.java delete mode 100644 src/main/java/de/ellpeck/naturesaura/aura/IAuraContainerProvider.java create mode 100644 src/main/java/de/ellpeck/naturesaura/aura/IAuraRecharge.java create mode 100644 src/main/java/de/ellpeck/naturesaura/aura/ItemAuraContainer.java create mode 100644 src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java create mode 100644 src/main/resources/assets/naturesaura/blockstates/infused_stone.json create mode 100644 src/main/resources/assets/naturesaura/models/item/aura_cache.json create mode 100644 src/main/resources/assets/naturesaura/recipes/aura_cache.json create mode 100644 src/main/resources/assets/naturesaura/textures/blocks/infused_stone.png create mode 100644 src/main/resources/assets/naturesaura/textures/items/aura_cache.png diff --git a/src/main/java/de/ellpeck/naturesaura/Helper.java b/src/main/java/de/ellpeck/naturesaura/Helper.java index 17abd30d..70928f9c 100644 --- a/src/main/java/de/ellpeck/naturesaura/Helper.java +++ b/src/main/java/de/ellpeck/naturesaura/Helper.java @@ -1,5 +1,7 @@ package de.ellpeck.naturesaura; +import de.ellpeck.naturesaura.aura.Capabilities; +import de.ellpeck.naturesaura.aura.IAuraRecharge; import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -9,14 +11,19 @@ import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.IItemHandlerModifiable; import org.lwjgl.opengl.GL11; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; @@ -122,4 +129,27 @@ public final class Helper { } return false; } + + public static ICapabilityProvider makeRechargeProvider(ItemStack stack) { + return new ICapabilityProvider() { + private final IAuraRecharge recharge = () -> { + if (stack.getItemDamage() > 0) { + stack.setItemDamage(stack.getItemDamage() - 1); + return true; + } + return false; + }; + + @Override + public boolean hasCapability(@Nonnull Capability capability, @Nullable EnumFacing facing) { + return capability == Capabilities.auraRecharge; + } + + @Nullable + @Override + public T getCapability(@Nonnull Capability capability, @Nullable EnumFacing facing) { + return capability == Capabilities.auraRecharge ? (T) this.recharge : null; + } + }; + } } diff --git a/src/main/java/de/ellpeck/naturesaura/NaturesAura.java b/src/main/java/de/ellpeck/naturesaura/NaturesAura.java index 7678bba4..6dda54f2 100644 --- a/src/main/java/de/ellpeck/naturesaura/NaturesAura.java +++ b/src/main/java/de/ellpeck/naturesaura/NaturesAura.java @@ -1,5 +1,9 @@ package de.ellpeck.naturesaura; +import de.ellpeck.naturesaura.aura.Capabilities.CapabilityAuraContainer; +import de.ellpeck.naturesaura.aura.Capabilities.CapabilityAuraRecharge; +import de.ellpeck.naturesaura.aura.IAuraContainer; +import de.ellpeck.naturesaura.aura.IAuraRecharge; import de.ellpeck.naturesaura.blocks.ModBlocks; import de.ellpeck.naturesaura.compat.Compat; import de.ellpeck.naturesaura.events.TerrainGenEvents; @@ -11,10 +15,13 @@ import de.ellpeck.naturesaura.reg.ModRegistry; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.capabilities.CapabilityManager; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.SidedProxy; -import net.minecraftforge.fml.common.event.*; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -40,6 +47,9 @@ public final class NaturesAura { @EventHandler public void preInit(FMLPreInitializationEvent event) { + CapabilityManager.INSTANCE.register(IAuraContainer.class, new CapabilityAuraContainer(), () -> null); + CapabilityManager.INSTANCE.register(IAuraRecharge.class, new CapabilityAuraRecharge(), () -> null); + new ModBlocks(); new ModItems(); diff --git a/src/main/java/de/ellpeck/naturesaura/aura/BasicAuraContainer.java b/src/main/java/de/ellpeck/naturesaura/aura/BasicAuraContainer.java index ef31f45c..00b6e772 100644 --- a/src/main/java/de/ellpeck/naturesaura/aura/BasicAuraContainer.java +++ b/src/main/java/de/ellpeck/naturesaura/aura/BasicAuraContainer.java @@ -5,10 +5,12 @@ import net.minecraft.nbt.NBTTagCompound; public class BasicAuraContainer implements IAuraContainer { protected final int maxAura; + protected final boolean artificial; protected int aura; - public BasicAuraContainer(int maxAura) { + public BasicAuraContainer(int maxAura, boolean artificial) { this.maxAura = maxAura; + this.artificial = artificial; } @Override @@ -44,6 +46,11 @@ public class BasicAuraContainer implements IAuraContainer { return 0x1E891E; } + @Override + public boolean isArtificial() { + return this.artificial; + } + public void writeNBT(NBTTagCompound compound) { compound.setInteger("aura", this.aura); } diff --git a/src/main/java/de/ellpeck/naturesaura/aura/Capabilities.java b/src/main/java/de/ellpeck/naturesaura/aura/Capabilities.java new file mode 100644 index 00000000..b1504ac2 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/aura/Capabilities.java @@ -0,0 +1,45 @@ +package de.ellpeck.naturesaura.aura; + +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 Capabilities { + + @CapabilityInject(IAuraContainer.class) + public static Capability auraContainer; + + @CapabilityInject(IAuraRecharge.class) + public static Capability auraRecharge; + + public static class CapabilityAuraContainer implements IStorage { + + @Override + public NBTBase writeNBT(Capability capability, IAuraContainer instance, EnumFacing side) { + return null; + } + + @Override + public void readNBT(Capability capability, IAuraContainer instance, EnumFacing side, NBTBase nbt) { + + } + } + + public static class CapabilityAuraRecharge implements IStorage{ + + @Nullable + @Override + public NBTBase writeNBT(Capability capability, IAuraRecharge instance, EnumFacing side) { + return null; + } + + @Override + public void readNBT(Capability capability, IAuraRecharge instance, EnumFacing side, NBTBase nbt) { + + } + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/aura/FiniteAuraContainer.java b/src/main/java/de/ellpeck/naturesaura/aura/FiniteAuraContainer.java index 3fc6ce32..54f97d38 100644 --- a/src/main/java/de/ellpeck/naturesaura/aura/FiniteAuraContainer.java +++ b/src/main/java/de/ellpeck/naturesaura/aura/FiniteAuraContainer.java @@ -2,8 +2,8 @@ package de.ellpeck.naturesaura.aura; public class FiniteAuraContainer extends BasicAuraContainer { - public FiniteAuraContainer(int aura) { - super(aura); + public FiniteAuraContainer(int aura, boolean artificial) { + super(aura, artificial); this.aura = aura; } diff --git a/src/main/java/de/ellpeck/naturesaura/aura/IAuraContainer.java b/src/main/java/de/ellpeck/naturesaura/aura/IAuraContainer.java index 8499ad94..a532f596 100644 --- a/src/main/java/de/ellpeck/naturesaura/aura/IAuraContainer.java +++ b/src/main/java/de/ellpeck/naturesaura/aura/IAuraContainer.java @@ -10,4 +10,6 @@ public interface IAuraContainer { int getMaxAura(); int getAuraColor(); + + boolean isArtificial(); } diff --git a/src/main/java/de/ellpeck/naturesaura/aura/IAuraContainerProvider.java b/src/main/java/de/ellpeck/naturesaura/aura/IAuraContainerProvider.java deleted file mode 100644 index 8737c9be..00000000 --- a/src/main/java/de/ellpeck/naturesaura/aura/IAuraContainerProvider.java +++ /dev/null @@ -1,8 +0,0 @@ -package de.ellpeck.naturesaura.aura; - -public interface IAuraContainerProvider { - - IAuraContainer container(); - - boolean isArtificial(); -} diff --git a/src/main/java/de/ellpeck/naturesaura/aura/IAuraRecharge.java b/src/main/java/de/ellpeck/naturesaura/aura/IAuraRecharge.java new file mode 100644 index 00000000..96fadc2d --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/aura/IAuraRecharge.java @@ -0,0 +1,7 @@ +package de.ellpeck.naturesaura.aura; + +public interface IAuraRecharge { + + boolean recharge(); + +} diff --git a/src/main/java/de/ellpeck/naturesaura/aura/ItemAuraContainer.java b/src/main/java/de/ellpeck/naturesaura/aura/ItemAuraContainer.java new file mode 100644 index 00000000..ed6d77c3 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/aura/ItemAuraContainer.java @@ -0,0 +1,68 @@ +package de.ellpeck.naturesaura.aura; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class ItemAuraContainer implements IAuraContainer { + + protected final ItemStack stack; + protected final int maxAura; + protected final boolean artificial; + + public ItemAuraContainer(ItemStack stack, int maxAura, boolean artificial) { + this.stack = stack; + this.maxAura = maxAura; + this.artificial = artificial; + } + + @Override + public int storeAura(int amountToStore, boolean simulate) { + int aura = this.getStoredAura(); + int actual = Math.min(amountToStore, this.getMaxAura() - aura); + if (!simulate) { + this.setAura(aura + actual); + } + return actual; + } + + @Override + public int drainAura(int amountToDrain, boolean simulate) { + int aura = this.getStoredAura(); + int actual = Math.min(amountToDrain, aura); + if (!simulate) { + this.setAura(aura - actual); + } + return actual; + } + + private void setAura(int amount) { + if (!this.stack.hasTagCompound()) { + this.stack.setTagCompound(new NBTTagCompound()); + } + this.stack.getTagCompound().setInteger("aura", amount); + } + + @Override + public int getStoredAura() { + if (this.stack.hasTagCompound()) { + return this.stack.getTagCompound().getInteger("aura"); + } else { + return 0; + } + } + + @Override + public int getMaxAura() { + return this.maxAura; + } + + @Override + public int getAuraColor() { + return 0x42a6bc; + } + + @Override + public boolean isArtificial() { + return this.artificial; + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockAncientLeaves.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockAncientLeaves.java index ccfecec4..237da3bd 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockAncientLeaves.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockAncientLeaves.java @@ -27,7 +27,6 @@ import net.minecraftforge.fml.relauncher.SideOnly; import javax.annotation.Nullable; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Random; public class BlockAncientLeaves extends BlockLeaves implements @@ -132,7 +131,7 @@ public class BlockAncientLeaves extends BlockLeaves implements if (rand.nextFloat() >= 0.95F && !worldIn.getBlockState(pos.down()).isFullBlock()) { TileEntity tile = worldIn.getTileEntity(pos); if (tile instanceof TileEntityAncientLeaves) { - if (((TileEntityAncientLeaves) tile).container().getStoredAura() > 0) { + if (((TileEntityAncientLeaves) tile).getAuraContainer(null).getStoredAura() > 0) { NaturesAura.proxy.spawnMagicParticle(worldIn, pos.getX() + rand.nextDouble(), pos.getY(), pos.getZ() + rand.nextDouble(), 0F, 0F, 0F, 0xc46df9, @@ -156,7 +155,7 @@ public class BlockAncientLeaves extends BlockLeaves implements if (!worldIn.isRemote) { TileEntity tile = worldIn.getTileEntity(pos); if (tile instanceof TileEntityAncientLeaves) { - if (((TileEntityAncientLeaves) tile).container().getStoredAura() <= 0) { + if (((TileEntityAncientLeaves) tile).getAuraContainer(null).getStoredAura() <= 0) { worldIn.setBlockState(pos, ModBlocks.DECAYED_LEAVES.getDefaultState()); } } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java index f7b18a66..22e3623b 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java @@ -16,4 +16,5 @@ public final class ModBlocks { public static final Block GOLDEN_LEAVES = new BlockGoldenLeaves(); public static final Block GOLD_POWDER = new BlockGoldPowder(); public static final Block WOOD_STAND = new BlockWoodStand(); + public static final Block INFUSED_STONE = new BlockImpl("infused_stone", Material.ROCK).setSoundType(SoundType.STONE).setHardness(1.75F); } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAncientLeaves.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAncientLeaves.java index afddff5c..02ba0f1e 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAncientLeaves.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAncientLeaves.java @@ -2,12 +2,12 @@ package de.ellpeck.naturesaura.blocks.tiles; import de.ellpeck.naturesaura.aura.FiniteAuraContainer; import de.ellpeck.naturesaura.aura.IAuraContainer; -import de.ellpeck.naturesaura.aura.IAuraContainerProvider; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; -public class TileEntityAncientLeaves extends TileEntityImpl implements IAuraContainerProvider { +public class TileEntityAncientLeaves extends TileEntityImpl { - private final FiniteAuraContainer container = new FiniteAuraContainer(20) { + private final FiniteAuraContainer container = new FiniteAuraContainer(20, false) { @Override public int getAuraColor() { return 0xc46df9; @@ -24,15 +24,10 @@ public class TileEntityAncientLeaves extends TileEntityImpl implements IAuraCont }; @Override - public IAuraContainer container() { + public IAuraContainer getAuraContainer(EnumFacing facing) { return this.container; } - @Override - public boolean isArtificial() { - return false; - } - @Override public void writeNBT(NBTTagCompound compound, boolean syncing) { super.writeNBT(compound, syncing); diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityImpl.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityImpl.java index a35c1689..8cd0f497 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityImpl.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityImpl.java @@ -1,5 +1,7 @@ package de.ellpeck.naturesaura.blocks.tiles; +import de.ellpeck.naturesaura.aura.Capabilities; +import de.ellpeck.naturesaura.aura.IAuraContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; @@ -12,7 +14,6 @@ import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.items.CapabilityItemHandler; -import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; import javax.annotation.Nullable; @@ -79,10 +80,16 @@ public class TileEntityImpl extends TileEntity { return null; } + public IAuraContainer getAuraContainer(EnumFacing facing) { + return null; + } + @Override public boolean hasCapability(Capability capability, @Nullable EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return this.getItemHandler(facing) != null; + } else if (capability == Capabilities.auraContainer) { + return this.getAuraContainer(facing) != null; } else { return super.hasCapability(capability, facing); } @@ -93,6 +100,8 @@ public class TileEntityImpl extends TileEntity { public T getCapability(Capability capability, @Nullable EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return (T) this.getItemHandler(facing); + } else if (capability == Capabilities.auraContainer) { + return (T) this.getAuraContainer(facing); } else { return super.getCapability(capability, facing); } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java index 1edaec6d..fe77a7d2 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java @@ -3,8 +3,8 @@ package de.ellpeck.naturesaura.blocks.tiles; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.aura.BasicAuraContainer; +import de.ellpeck.naturesaura.aura.Capabilities; import de.ellpeck.naturesaura.aura.IAuraContainer; -import de.ellpeck.naturesaura.aura.IAuraContainerProvider; import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketParticleStream; import de.ellpeck.naturesaura.packet.PacketParticles; @@ -26,7 +26,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -public class TileEntityNatureAltar extends TileEntityImpl implements ITickable, IAuraContainerProvider { +public class TileEntityNatureAltar extends TileEntityImpl implements ITickable { private static final BlockPos[] BRICK_POSITIONS = new BlockPos[]{ new BlockPos(-2, -1, 0), @@ -101,7 +101,7 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable, @Override protected boolean canInsert(ItemStack stack, int slot) { - return AltarRecipe.forInput(stack) != null; + return AltarRecipe.forInput(stack) != null || stack.hasCapability(Capabilities.auraContainer, null); } @Override @@ -110,8 +110,8 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable, } }; - private final List cachedProviders = new ArrayList<>(); - private final BasicAuraContainer container = new BasicAuraContainer(5000); + private final List cachedProviders = new ArrayList<>(); + private final BasicAuraContainer container = new BasicAuraContainer(5000, true); public boolean structureFine; private AltarRecipe currentRecipe; @@ -139,25 +139,26 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable, if (this.world.getTotalWorldTime() % 100 == 0) { this.cachedProviders.clear(); for (TileEntity tile : Helper.getTileEntitiesInArea(this.world, this.pos, 15)) { - if (tile instanceof IAuraContainerProvider && tile != this) { - this.cachedProviders.add((IAuraContainerProvider) tile); + if (tile.hasCapability(Capabilities.auraContainer, null) && tile != this) { + this.cachedProviders.add(tile); } } } if (!this.cachedProviders.isEmpty()) { int index = rand.nextInt(this.cachedProviders.size()); - IAuraContainerProvider provider = this.cachedProviders.get(index); - if (!((TileEntity) provider).isInvalid()) { - int stored = this.container.storeAura(provider.container().drainAura(5, true), false); + TileEntity provider = this.cachedProviders.get(index); + if (!provider.isInvalid() && provider.hasCapability(Capabilities.auraContainer, null)) { + IAuraContainer container = provider.getCapability(Capabilities.auraContainer, null); + int stored = this.container.storeAura(container.drainAura(5, true), false); if (stored > 0) { - provider.container().drainAura(stored, false); + container.drainAura(stored, false); - BlockPos pos = ((TileEntity) provider).getPos(); + BlockPos pos = provider.getPos(); PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticleStream( pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, this.pos.getX() + 0.5F, this.pos.getY() + 0.5F, this.pos.getZ() + 0.5F, - rand.nextFloat() * 0.05F + 0.05F, provider.container().getAuraColor(), rand.nextFloat() * 1F + 1F + rand.nextFloat() * 0.05F + 0.05F, container.getAuraColor(), rand.nextFloat() * 1F + 1F )); } } else { @@ -166,27 +167,42 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable, } ItemStack stack = this.items.getStackInSlot(0); - if (this.currentRecipe == null) { - if (!stack.isEmpty()) { - this.currentRecipe = AltarRecipe.forInput(stack); - } - } else { - if (stack.isEmpty() || !stack.isItemEqual(this.currentRecipe.input)) { - this.currentRecipe = null; - } else { - int req = this.currentRecipe.aura / this.currentRecipe.time; - if (this.container.getStoredAura() >= req) { - this.container.drainAura(req, false); + if (!stack.isEmpty() && stack.hasCapability(Capabilities.auraContainer, null)) { + IAuraContainer container = stack.getCapability(Capabilities.auraContainer, null); + int theoreticalDrain = this.container.drainAura(10, true); + if (theoreticalDrain > 0) { + int stored = container.storeAura(theoreticalDrain, false); + if (stored > 0) { + this.container.drainAura(stored, false); - if (this.timer % 4 == 0) { + if (this.world.getTotalWorldTime() % 4 == 0) { PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), 4)); } + } + } + } else { + if (this.currentRecipe == null) { + if (!stack.isEmpty()) { + this.currentRecipe = AltarRecipe.forInput(stack); + } + } else { + if (stack.isEmpty() || !stack.isItemEqual(this.currentRecipe.input)) { + this.currentRecipe = null; + } else { + int req = this.currentRecipe.aura / this.currentRecipe.time; + if (this.container.getStoredAura() >= req) { + this.container.drainAura(req, false); - this.timer++; - if (this.timer >= this.currentRecipe.time) { - this.items.setStackInSlot(0, this.currentRecipe.output.copy()); - this.currentRecipe = null; - this.timer = 0; + if (this.timer % 4 == 0) { + PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), 4)); + } + + this.timer++; + if (this.timer >= this.currentRecipe.time) { + this.items.setStackInSlot(0, this.currentRecipe.output.copy()); + this.currentRecipe = null; + this.timer = 0; + } } } } @@ -262,15 +278,10 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable, } @Override - public IAuraContainer container() { + public IAuraContainer getAuraContainer(EnumFacing facing) { return this.container; } - @Override - public boolean isArtificial() { - return true; - } - @Override public IItemHandlerModifiable getItemHandler(EnumFacing facing) { return this.items; diff --git a/src/main/java/de/ellpeck/naturesaura/compat/BaublesCompat.java b/src/main/java/de/ellpeck/naturesaura/compat/BaublesCompat.java index 6d54f94e..c003a699 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/BaublesCompat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/BaublesCompat.java @@ -20,23 +20,30 @@ import javax.annotation.Nullable; public class BaublesCompat { private final IBauble eye = stack -> BaubleType.CHARM; + private final IBauble cache = stack -> BaubleType.BELT; @SubscribeEvent public void onCapabilitiesAttach(AttachCapabilitiesEvent event) { Item item = event.getObject().getItem(); if (item == ModItems.EYE) { - event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "bauble"), new ICapabilityProvider() { - @Override - public boolean hasCapability(@Nonnull Capability capability, @Nullable EnumFacing facing) { - return capability == BaublesCapabilities.CAPABILITY_ITEM_BAUBLE; - } - - @Nullable - @Override - public T getCapability(@Nonnull Capability capability, @Nullable EnumFacing facing) { - return capability == BaublesCapabilities.CAPABILITY_ITEM_BAUBLE ? (T) BaublesCompat.this.eye : null; - } - }); + this.addCap(event, this.eye); + } else if (item == ModItems.AURA_CACHE) { + this.addCap(event, this.cache); } } + + private void addCap(AttachCapabilitiesEvent event, IBauble type) { + event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "bauble"), new ICapabilityProvider() { + @Override + public boolean hasCapability(@Nonnull Capability capability, @Nullable EnumFacing facing) { + return capability == BaublesCapabilities.CAPABILITY_ITEM_BAUBLE; + } + + @Nullable + @Override + public T getCapability(@Nonnull Capability capability, @Nullable EnumFacing facing) { + return capability == BaublesCapabilities.CAPABILITY_ITEM_BAUBLE ? (T) type : null; + } + }); + } } diff --git a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java index c5c7bba9..6a5bb012 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java @@ -3,8 +3,9 @@ package de.ellpeck.naturesaura.events; import baubles.api.BaublesApi; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.aura.Capabilities; import de.ellpeck.naturesaura.aura.IAuraContainer; -import de.ellpeck.naturesaura.aura.IAuraContainerProvider; +import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar; import de.ellpeck.naturesaura.compat.Compat; import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.particles.ParticleHandler; @@ -35,7 +36,7 @@ import java.util.List; @SideOnly(Side.CLIENT) public class ClientEvents { - private static final ResourceLocation OVERLAYS = new ResourceLocation(NaturesAura.MOD_ID, "textures/gui/overlays.png"); + public static final ResourceLocation OVERLAYS = new ResourceLocation(NaturesAura.MOD_ID, "textures/gui/overlays.png"); @SubscribeEvent public void onDebugRender(RenderGameOverlayEvent.Text event) { @@ -71,84 +72,124 @@ public class ClientEvents { @SubscribeEvent public void onOverlayRender(RenderGameOverlayEvent.Post event) { Minecraft mc = Minecraft.getMinecraft(); - if (event.getType() == ElementType.ALL && mc.currentScreen == null) { + if (event.getType() == ElementType.ALL) { ScaledResolution res = event.getResolution(); if (mc.player != null) { ItemStack stack = mc.player.getHeldItemMainhand(); - if (!stack.isEmpty() && stack.getItem() == ModItems.EYE || Compat.baubles && BaublesApi.isBaubleEquipped(mc.player, ModItems.EYE) >= 0) { - int maxAura = 0; - int aura = 0; - int total = 0; + if (mc.currentScreen == null) { + if (!stack.isEmpty() && stack.getItem() == ModItems.EYE || Compat.baubles && BaublesApi.isBaubleEquipped(mc.player, ModItems.EYE) >= 0) { + int maxAura = 0; + int aura = 0; + int total = 0; - for (TileEntity tile : Helper.getTileEntitiesInArea(mc.world, mc.player.getPosition(), 15)) { - if (tile instanceof IAuraContainerProvider) { - IAuraContainerProvider provider = (IAuraContainerProvider) tile; - if (!provider.isArtificial()) { - IAuraContainer container = provider.container(); - maxAura += container.getMaxAura(); - aura += container.getStoredAura(); - total++; + for (TileEntity tile : Helper.getTileEntitiesInArea(mc.world, mc.player.getPosition(), 15)) { + if (tile.hasCapability(Capabilities.auraContainer, null)) { + IAuraContainer container = tile.getCapability(Capabilities.auraContainer, null); + if (!container.isArtificial()) { + maxAura += container.getMaxAura(); + aura += container.getStoredAura(); + total++; + } } } - } - GlStateManager.pushMatrix(); - mc.getTextureManager().bindTexture(OVERLAYS); + GlStateManager.pushMatrix(); + mc.getTextureManager().bindTexture(OVERLAYS); - GlStateManager.color(0.8F, 0.25F, 0.25F); - float totalPercentage = total / 1500F; - int tHeight = MathHelper.ceil(Math.min(1F, totalPercentage) * 75); - if (tHeight < 75) - Gui.drawModalRectWithCustomSizedTexture(3, 17, 6, 12, 6, 75 - tHeight, 256, 256); - if (tHeight > 0) - Gui.drawModalRectWithCustomSizedTexture(3, 17 + 75 - tHeight, 0, 12 + 75 - tHeight, 6, tHeight, 256, 256); + GlStateManager.color(0.8F, 0.25F, 0.25F); + float totalPercentage = total / 1500F; + int tHeight = MathHelper.ceil(Math.min(1F, totalPercentage) * 50); + if (tHeight < 50) + Gui.drawModalRectWithCustomSizedTexture(3, 17, 6, 12, 6, 50 - tHeight, 256, 256); + if (tHeight > 0) + Gui.drawModalRectWithCustomSizedTexture(3, 17 + 50 - tHeight, 0, 12 + 50 - tHeight, 6, tHeight, 256, 256); - GlStateManager.color(0.25F, 0.8F, 0.25F); - int aHeight = MathHelper.ceil(aura / (float) maxAura * 75); - if (aHeight < 75) - Gui.drawModalRectWithCustomSizedTexture(12, 17, 6, 12, 6, 75 - aHeight, 256, 256); - if (aHeight > 0) - Gui.drawModalRectWithCustomSizedTexture(12, 17 + 75 - aHeight, 0, 12 + 75 - aHeight, 6, aHeight, 256, 256); + GlStateManager.color(0.25F, 0.8F, 0.25F); + int aHeight = MathHelper.ceil(aura / (float) maxAura * 50); + if (aHeight < 50) + Gui.drawModalRectWithCustomSizedTexture(12, 17, 6, 12, 6, 50 - aHeight, 256, 256); + if (aHeight > 0) + Gui.drawModalRectWithCustomSizedTexture(12, 17 + 50 - aHeight, 0, 12 + 50 - aHeight, 6, aHeight, 256, 256); - if (mc.objectMouseOver != null) { - BlockPos pos = mc.objectMouseOver.getBlockPos(); - if (pos != null) { - TileEntity tile = mc.world.getTileEntity(pos); - if (tile instanceof IAuraContainerProvider) { - IAuraContainer container = ((IAuraContainerProvider) tile).container(); + if (mc.objectMouseOver != null) { + BlockPos pos = mc.objectMouseOver.getBlockPos(); + if (pos != null) { + TileEntity tile = mc.world.getTileEntity(pos); + if (tile != null && tile.hasCapability(Capabilities.auraContainer, null)) { + IAuraContainer container = tile.getCapability(Capabilities.auraContainer, null); - int color = container.getAuraColor(); - GlStateManager.color((color >> 16 & 255) / 255F, (color >> 8 & 255) / 255F, (color & 255) / 255F); + IBlockState state = mc.world.getBlockState(pos); + ItemStack blockStack = state.getBlock().getPickBlock(state, mc.objectMouseOver, mc.world, pos, mc.player); + this.drawContainerInfo(container, mc, res, 25, blockStack.getDisplayName()); - int x = res.getScaledWidth() / 2 - 50; - int y = res.getScaledHeight() / 2 + 25; - int width = MathHelper.ceil(container.getStoredAura() / (float) container.getMaxAura() * 100F); - - if (width < 100) - Gui.drawModalRectWithCustomSizedTexture(x + width, y, width, 0, 100 - width, 6, 256, 256); - if (width > 0) - Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 6, width, 6, 256, 256); - - IBlockState state = mc.world.getBlockState(pos); - ItemStack blockStack = state.getBlock().getPickBlock(state, mc.objectMouseOver, mc.world, pos, mc.player); - String s = blockStack.getDisplayName(); - mc.fontRenderer.drawString(s, x + 50 - mc.fontRenderer.getStringWidth(s) / 2F, y - 9, color, true); + if (tile instanceof TileEntityNatureAltar) { + ItemStack tileStack = ((TileEntityNatureAltar) tile).getItemHandler(null).getStackInSlot(0); + if (!tileStack.isEmpty() && tileStack.hasCapability(Capabilities.auraContainer, null)) { + IAuraContainer stackContainer = tileStack.getCapability(Capabilities.auraContainer, null); + this.drawContainerInfo(stackContainer, mc, res, 45, tileStack.getDisplayName()); + } + } + } } } + + if (totalPercentage > 1F) { + mc.fontRenderer.drawString("+", 3F, 9.5F, 0xBB3333, true); + } + + float scale = 0.75F; + GlStateManager.scale(scale, scale, scale); + mc.fontRenderer.drawString(I18n.format("info." + NaturesAura.MOD_ID + ".aura_in_area"), 3 / scale, 3 / scale, 0xBB3333, true); + mc.fontRenderer.drawString(I18n.format("info." + NaturesAura.MOD_ID + ".aura_percentage"), 12 / scale, 10 / scale, 0x33BB33, true); + + GlStateManager.popMatrix(); } + } - if (totalPercentage > 1F) { - mc.fontRenderer.drawString("+", 3F, 9.5F, 0xBB3333, true); + for (int i = 0; i < mc.player.inventory.getSizeInventory(); i++) { + ItemStack slot = mc.player.inventory.getStackInSlot(i); + if (!slot.isEmpty() && slot.getItem() == ModItems.AURA_CACHE) { + IAuraContainer container = slot.getCapability(Capabilities.auraContainer, null); + int width = MathHelper.ceil(container.getStoredAura() / (float) container.getMaxAura() * 80); + int x = res.getScaledWidth() / 2 - 173; + int y = res.getScaledHeight() - 8; + + GlStateManager.pushMatrix(); + int color = container.getAuraColor(); + GlStateManager.color((color >> 16 & 255) / 255F, (color >> 8 & 255) / 255F, (color & 255) / 255F); + mc.getTextureManager().bindTexture(OVERLAYS); + if (width < 80) + Gui.drawModalRectWithCustomSizedTexture(x + width, y, width, 0, 80 - width, 6, 256, 256); + if (width > 0) + Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 6, width, 6, 256, 256); + + float scale = 0.75F; + GlStateManager.scale(scale, scale, scale); + String s = slot.getDisplayName(); + mc.fontRenderer.drawString(s, (x + 80) / scale - mc.fontRenderer.getStringWidth(s), (y - 7) / scale, color, true); + GlStateManager.popMatrix(); + + break; } - - float scale = 0.75F; - GlStateManager.scale(scale, scale, scale); - mc.fontRenderer.drawString(I18n.format("info." + NaturesAura.MOD_ID + ".aura_in_area"), 3 / scale, 3 / scale, 0xBB3333, true); - mc.fontRenderer.drawString(I18n.format("info." + NaturesAura.MOD_ID + ".aura_percentage"), 12 / scale, 10 / scale, 0x33BB33, true); - - GlStateManager.popMatrix(); } } } } + + private void drawContainerInfo(IAuraContainer container, Minecraft mc, ScaledResolution res, int yOffset, String name) { + int color = container.getAuraColor(); + GlStateManager.color((color >> 16 & 255) / 255F, (color >> 8 & 255) / 255F, (color & 255) / 255F); + + int x = res.getScaledWidth() / 2 - 40; + int y = res.getScaledHeight() / 2 + yOffset; + int width = MathHelper.ceil(container.getStoredAura() / (float) container.getMaxAura() * 80); + + mc.getTextureManager().bindTexture(OVERLAYS); + if (width < 80) + Gui.drawModalRectWithCustomSizedTexture(x + width, y, width, 0, 80 - width, 6, 256, 256); + if (width > 0) + Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 6, width, 6, 256, 256); + + mc.fontRenderer.drawString(name, x + 40 - mc.fontRenderer.getStringWidth(name) / 2F, y - 9, color, true); + } } diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java b/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java new file mode 100644 index 00000000..9569fb47 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java @@ -0,0 +1,92 @@ +package de.ellpeck.naturesaura.items; + +import de.ellpeck.naturesaura.aura.Capabilities; +import de.ellpeck.naturesaura.aura.IAuraContainer; +import de.ellpeck.naturesaura.aura.ItemAuraContainer; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.NonNullList; +import net.minecraft.world.World; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ICapabilityProvider; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class ItemAuraCache extends ItemImpl { + + public ItemAuraCache() { + super("aura_cache"); + this.setMaxStackSize(1); + } + + @Override + public void onUpdate(ItemStack stackIn, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + if (!worldIn.isRemote && entityIn instanceof EntityPlayer) { + EntityPlayer player = (EntityPlayer) entityIn; + if (player.isSneaking()) { + ItemStack stack = player.getHeldItemMainhand(); + if (stack.hasCapability(Capabilities.auraRecharge, null)) { + IAuraContainer container = stackIn.getCapability(Capabilities.auraContainer, null); + if (container.getStoredAura() >= 3 && stack.getCapability(Capabilities.auraRecharge, null).recharge()) { + container.drainAura(4, false); + } + } + } + } + } + + @Override + public void getSubItems(CreativeTabs tab, NonNullList items) { + if (this.isInCreativeTab(tab)) { + items.add(new ItemStack(this)); + + ItemStack stack = new ItemStack(this); + IAuraContainer container = stack.getCapability(Capabilities.auraContainer, null); + container.storeAura(container.getMaxAura(), false); + items.add(stack); + } + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return true; + } + + @Override + public double getDurabilityForDisplay(ItemStack stack) { + if (stack.hasCapability(Capabilities.auraContainer, null)) { + IAuraContainer container = stack.getCapability(Capabilities.auraContainer, null); + return 1 - container.getStoredAura() / (double) container.getMaxAura(); + } else { + return 0; + } + } + + @Nullable + @Override + public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { + return new ICapabilityProvider() { + private final ItemAuraContainer container = new ItemAuraContainer(stack, 4000, true); + + @Override + public boolean hasCapability(@Nonnull Capability capability, @Nullable EnumFacing facing) { + return capability == Capabilities.auraContainer; + } + + @Nullable + @Override + public T getCapability(@Nonnull Capability capability, @Nullable EnumFacing facing) { + if (capability == Capabilities.auraContainer) { + return (T) this.container; + } else { + return null; + } + } + }; + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java b/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java index c869af31..1c86b9fa 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java @@ -4,5 +4,6 @@ public class ItemEye extends ItemImpl { public ItemEye() { super("eye"); + this.setMaxStackSize(1); } } diff --git a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java index 11941843..9d626815 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java @@ -22,4 +22,5 @@ public final class ModItems { public static final Item INFUSED_SHOVEL = new ItemShovelNA("infused_iron_shovel", TOOL_MATERIAL_INFUSED_IRON); public static final Item INFUSED_HOE = new ItemHoeNA("infused_iron_hoe", TOOL_MATERIAL_INFUSED_IRON); public static final Item INFUSED_SWORD = new ItemSwordNA("infused_iron_sword", TOOL_MATERIAL_INFUSED_IRON); + public static final Item AURA_CACHE = new ItemAuraCache(); } diff --git a/src/main/java/de/ellpeck/naturesaura/items/tools/ItemAxeNA.java b/src/main/java/de/ellpeck/naturesaura/items/tools/ItemAxeNA.java index cb360636..6e63f3d1 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/tools/ItemAxeNA.java +++ b/src/main/java/de/ellpeck/naturesaura/items/tools/ItemAxeNA.java @@ -1,5 +1,6 @@ package de.ellpeck.naturesaura.items.tools; +import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModelProvider; @@ -8,10 +9,14 @@ import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemAxe; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import javax.annotation.Nullable; + public class ItemAxeNA extends ItemAxe implements IModItem, IModelProvider { private final String baseName; @@ -53,4 +58,12 @@ public class ItemAxeNA extends ItemAxe implements IModItem, IModelProvider { return super.getDestroySpeed(stack, state); } } + + @Nullable + @Override + public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { + if (this == ModItems.INFUSED_AXE) + return Helper.makeRechargeProvider(stack); + else return null; + } } diff --git a/src/main/java/de/ellpeck/naturesaura/items/tools/ItemHoeNA.java b/src/main/java/de/ellpeck/naturesaura/items/tools/ItemHoeNA.java index 582452a6..79208a40 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/tools/ItemHoeNA.java +++ b/src/main/java/de/ellpeck/naturesaura/items/tools/ItemHoeNA.java @@ -1,5 +1,6 @@ package de.ellpeck.naturesaura.items.tools; +import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModelProvider; @@ -9,16 +10,20 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemHoe; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import javax.annotation.Nullable; + public class ItemHoeNA extends ItemHoe implements IModItem, IModelProvider { private final String baseName; @@ -80,4 +85,12 @@ public class ItemHoeNA extends ItemHoe implements IModItem, IModelProvider { public void onPostInit(FMLPostInitializationEvent event) { } + + @Nullable + @Override + public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { + if (this == ModItems.INFUSED_HOE) + return Helper.makeRechargeProvider(stack); + else return null; + } } diff --git a/src/main/java/de/ellpeck/naturesaura/items/tools/ItemPickaxeNA.java b/src/main/java/de/ellpeck/naturesaura/items/tools/ItemPickaxeNA.java index b65a62eb..eef0e37f 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/tools/ItemPickaxeNA.java +++ b/src/main/java/de/ellpeck/naturesaura/items/tools/ItemPickaxeNA.java @@ -1,13 +1,20 @@ package de.ellpeck.naturesaura.items.tools; +import de.ellpeck.naturesaura.Helper; +import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModelProvider; import de.ellpeck.naturesaura.reg.ModRegistry; import net.minecraft.item.ItemPickaxe; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import javax.annotation.Nullable; + public class ItemPickaxeNA extends ItemPickaxe implements IModItem, IModelProvider { private final String baseName; @@ -40,4 +47,12 @@ public class ItemPickaxeNA extends ItemPickaxe implements IModItem, IModelProvid @Override public void onPostInit(FMLPostInitializationEvent event) { } + + @Nullable + @Override + public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { + if (this == ModItems.INFUSED_PICKAXE) + return Helper.makeRechargeProvider(stack); + else return null; + } } diff --git a/src/main/java/de/ellpeck/naturesaura/items/tools/ItemShovelNA.java b/src/main/java/de/ellpeck/naturesaura/items/tools/ItemShovelNA.java index 0c7fc5f6..5a89b986 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/tools/ItemShovelNA.java +++ b/src/main/java/de/ellpeck/naturesaura/items/tools/ItemShovelNA.java @@ -1,5 +1,6 @@ package de.ellpeck.naturesaura.items.tools; +import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModelProvider; @@ -10,16 +11,20 @@ import net.minecraft.init.Blocks; import net.minecraft.init.SoundEvents; import net.minecraft.item.ItemSpade; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import javax.annotation.Nullable; + public class ItemShovelNA extends ItemSpade implements IModItem, IModelProvider { private final String baseName; @@ -82,4 +87,12 @@ public class ItemShovelNA extends ItemSpade implements IModItem, IModelProvider @Override public void onPostInit(FMLPostInitializationEvent event) { } + + @Nullable + @Override + public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { + if (this == ModItems.INFUSED_SHOVEL) + return Helper.makeRechargeProvider(stack); + else return null; + } } diff --git a/src/main/java/de/ellpeck/naturesaura/items/tools/ItemSwordNA.java b/src/main/java/de/ellpeck/naturesaura/items/tools/ItemSwordNA.java index df2b2723..b1e2ff81 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/tools/ItemSwordNA.java +++ b/src/main/java/de/ellpeck/naturesaura/items/tools/ItemSwordNA.java @@ -1,13 +1,20 @@ package de.ellpeck.naturesaura.items.tools; +import de.ellpeck.naturesaura.Helper; +import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModelProvider; import de.ellpeck.naturesaura.reg.ModRegistry; +import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import javax.annotation.Nullable; + public class ItemSwordNA extends ItemSword implements IModItem, IModelProvider { private final String baseName; @@ -41,4 +48,12 @@ public class ItemSwordNA extends ItemSword implements IModItem, IModelProvider { public void onPostInit(FMLPostInitializationEvent event) { } + + @Nullable + @Override + public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { + if (this == ModItems.INFUSED_SWORD) + return Helper.makeRechargeProvider(stack); + else return null; + } } diff --git a/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java b/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java index 5c6abee5..93a5b1fd 100644 --- a/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java +++ b/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java @@ -28,6 +28,7 @@ public final class ModRecipes { new ItemStack(Items.REEDS), new ItemStack(ModItems.GOLD_LEAF)).add(); - new AltarRecipe(new ItemStack(Items.IRON_INGOT), new ItemStack(ModItems.INFUSED_IRON), 200, 30).add(); + new AltarRecipe(new ItemStack(Items.IRON_INGOT), new ItemStack(ModItems.INFUSED_IRON), 300, 80).add(); + new AltarRecipe(new ItemStack(Blocks.STONE), new ItemStack(ModBlocks.INFUSED_STONE), 150, 40).add(); } } diff --git a/src/main/resources/assets/naturesaura/blockstates/infused_stone.json b/src/main/resources/assets/naturesaura/blockstates/infused_stone.json new file mode 100644 index 00000000..1b276290 --- /dev/null +++ b/src/main/resources/assets/naturesaura/blockstates/infused_stone.json @@ -0,0 +1,14 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "minecraft:cube_all", + "textures": { + "all": "naturesaura:blocks/infused_stone" + }, + "transform": "forge:default-block" + }, + "variants": { + "normal": [{}], + "inventory": [{}] + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/lang/en_US.lang b/src/main/resources/assets/naturesaura/lang/en_US.lang index f5bd9c24..d5f963fc 100644 --- a/src/main/resources/assets/naturesaura/lang/en_US.lang +++ b/src/main/resources/assets/naturesaura/lang/en_US.lang @@ -10,6 +10,7 @@ tile.naturesaura.golden_leaves.name=Golden Leaves tile.naturesaura.gold_powder.name=Gold Powder tile.naturesaura.wood_stand.name=Wooden Stand tile.naturesaura.ancient_planks.name=Ancient Planks +tile.naturesaura.infused_stone.name=Infused Rock item.naturesaura.eye.name=Environmental Eye item.naturesaura.gold_fiber.name=Brilliant Fiber @@ -21,6 +22,7 @@ item.naturesaura.infused_iron_shovel.name=Botanist's Shovel item.naturesaura.infused_iron_sword.name=Botanist's Blade item.naturesaura.infused_iron_hoe.name=Botanist's Hoe item.naturesaura.ancient_stick.name=Ancient Wood Rod +item.naturesaura.aura_cache.name=Aura Cache container.naturesaura.tree_ritual.name=Tree Infusion container.naturesaura.altar.name=Natural Altar diff --git a/src/main/resources/assets/naturesaura/models/item/aura_cache.json b/src/main/resources/assets/naturesaura/models/item/aura_cache.json new file mode 100644 index 00000000..bdb756ab --- /dev/null +++ b/src/main/resources/assets/naturesaura/models/item/aura_cache.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "naturesaura:items/aura_cache" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/recipes/aura_cache.json b/src/main/resources/assets/naturesaura/recipes/aura_cache.json new file mode 100644 index 00000000..f069a1ce --- /dev/null +++ b/src/main/resources/assets/naturesaura/recipes/aura_cache.json @@ -0,0 +1,22 @@ +{ + "type": "forge:ore_shaped", + "pattern": [ + "SIS", + "IBI", + "SIS" + ], + "key": { + "S": { + "item": "naturesaura:infused_stone" + }, + "I": { + "item": "naturesaura:infused_iron" + }, + "B": { + "item": "minecraft:bucket" + } + }, + "result": { + "item": "naturesaura:aura_cache" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/textures/blocks/infused_stone.png b/src/main/resources/assets/naturesaura/textures/blocks/infused_stone.png new file mode 100644 index 0000000000000000000000000000000000000000..6a7032dcfeccecccd907d2277dcaa0a1a6818314 GIT binary patch literal 314 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=Dh+L6~vJ#O${~L5ULAh?3y^w370~qEv>0#LT=By}Z;C1rt3(J;P+JIo?1uJ3L(+ zLoEDzCmZq|G7w<-```V7f>cY3i}T#+tZOeuJofIN~1y^McPS~lKwC$i`T8Yix1E(E4uWDUf-efF%Bfb9c0ne`{cGdmUCVk{p z+9k=%Sf)1brKZ3i_M-Ot4ccs{!h4QaxE+d_skk%auUN+CO=62#(|-j!JP}Egwsqcf zx|}g*or?9{rk|m2&S*riF0xLDfA-Pe#LSqzdf(C8{}|64WUAvhpi~F+1B0ilpUXO@ GgeCyDs(1VV literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/naturesaura/textures/gui/overlays.png b/src/main/resources/assets/naturesaura/textures/gui/overlays.png index 363cfa2b799344dc517168f7bc069b5e5d3328c9..573b9d93aab98dbe470050f1b901644c6dca6b3e 100644 GIT binary patch literal 1301 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6&2?&#~tz_78O`%fY(kk47* z5n0T@z_%BK8Qp(RSPK-CC~=J_3C>R|DNig)Whh9@%q!8$OD$0_(KFODOxBv?4K!!6 zr;B4qMcmt4hJG=bOs#=ok9$}nloYly2bDQKn!>A4sjYK>(fX5I)|af7)XH}y=5s@9 zpL@D%)iNGjUnRb(!u_P)(l=gu$`yyQ8sKY?L~m>ts}Zaby|-E-GJx;=Z` zw>i3F4*=_9Y=es{R&)n)= zB-b!~`t-~F^7cQZ^YinUU%!5R^W!r-4Aajs)HE@)k%Z+RbIBK!Z5)vdzK^8R~d`}fNAU1wuhcRHT$z{lDD|Ni{`cq?PW>!RYC zonN0b$ed+3@YR?>AdNxc41>cA#s&jshD0`oLp%&Ek_;U5kl4L*_ik(c1GjJAzG=wd zZp={dw~qI~>({SmGB)(h28#ZdY*;L7{`>IZ!!Q5+`}d|Im*K%KU|_v``SQ!BPetGU z{P~m3ASW+>e*aJY+;$E Z8H_juiwk;gWdMsX22WQ%mvv4FO#o?(WzGNq literal 1304 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6&2?&#~tz_78O`%fY(kk47* z5n0T@z_$;C8DBYVJOC7wC~=J_3C>R|DNig)Whh9@%q!8$OD$0_(KFODOxBv?4K!z( zr;B4qMcmt4hJG^KOs;`pk9$}nloYly2bDQKn!>A4sjYK>(fX5IRfy@KO*a0MCI3C2 zH>vN+E=I@j>&;oOURl`H{wjI+SN8d%qMZk3Tk8M&{rmUnyLazCJw082PxIrw_U8^3 z>ix5E{9rzpxuAw4KR;i8zJ2{OS(*2L3;B2$^3O8-VU}RH*B#wZ&#;|g&-Bk0b`^W} zKaN>5nWg@8WlVg0d|qCjU;O^Mr@edjJwN`t-s0R*E6)$x=ZOD5eE9Iw=jZ3|S$zEX z@nROJ9Us1YDf#*FF?;@-r%#`L`tzs8>Rcn^gSCF@9Idlw6( z(-{s-^nk39a6ul3_b-CZV`?+eg=IF&sx0E98Gc0kd(R-V|7ZOCaC<{97<5HgbW?9;ba!ELWdLwtX>N2bZe?^J zG%hhNF=Hy6O8@`@a!Eu%R5(vvQ`v6QP!RP)n}SNn(x8$e>Jaz@kf0*OPSTbqmLeWf z;3E)-ZGfUpupBojk8vw^U> zfm*2xz0^UyIsjMd;rvXMqhpx0G4ygD$Mrd)*%-Dz-Nx331VTGev>I~?&_zQVp<3ud zB=ss_Gs**)bl7UlgipSBjg@OFSiK%V;@}mU`k1Qd;hQlbn-YXIBMroY1gaL=s8@zm z;&&vTA0lI%;Boga*&nE-KIEr)l)ttq(1a=-i2!VV1ySM~Oh=J?`3AY>DRSm1vdv%E zYo8%go8sY@4&*0!Tun!WCX8{o0>@#+Aq7(*!Fg@#5_X$EvDZ1nKABP-Bcsot6nhB7 z*ARavBfJyAVzH2HZlh(pVzA=zw>Jgn-PUjHQ|7Ebg;E(oC1D>Obr9GLVEbbdq5Bb0 z0jL2!g|HGq=s^TB@z2#~P_>EcDRYL}s*nzegF~#}3kn*HacC9V% zNOdk*E%pUCUFeBDvo@qTnW0e~x&de&gb@70Lu6F?Xc}XoGIwHibCq~shWsoKje;0N zrC#l$MXh8E8}VQ+kVKD(vsUb)WBx!e6~>MCGUU&91T`MA8cm`}9ns4@Hvr*$3hYg7 zOf=?nkw#gKVg2qEL{l+@sJ%Ra9K1n+Sbe_FQ!Ex7!b@1p!z+s7;b0000