diff --git a/src/main/java/de/ellpeck/naturesaura/NaturesAura.java b/src/main/java/de/ellpeck/naturesaura/NaturesAura.java index fd3c4eb7..8d111a63 100644 --- a/src/main/java/de/ellpeck/naturesaura/NaturesAura.java +++ b/src/main/java/de/ellpeck/naturesaura/NaturesAura.java @@ -1,6 +1,7 @@ package de.ellpeck.naturesaura; import de.ellpeck.naturesaura.blocks.ModBlocks; +import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.proxy.IProxy; import de.ellpeck.naturesaura.reg.ModRegistry; @@ -32,13 +33,14 @@ public final class NaturesAura { public static final CreativeTabs CREATIVE_TAB = new CreativeTabs(MOD_ID) { @Override public ItemStack createIcon() { - return new ItemStack(Items.BEETROOT); + return new ItemStack(ModItems.EYE); } }; @EventHandler public void preInit(FMLPreInitializationEvent event) { new ModBlocks(); + new ModItems(); PacketHandler.init(); ModRegistry.preInit(event); proxy.preInit(event); diff --git a/src/main/java/de/ellpeck/naturesaura/aura/IAuraContainerProvider.java b/src/main/java/de/ellpeck/naturesaura/aura/IAuraContainerProvider.java index 438e342a..8737c9be 100644 --- a/src/main/java/de/ellpeck/naturesaura/aura/IAuraContainerProvider.java +++ b/src/main/java/de/ellpeck/naturesaura/aura/IAuraContainerProvider.java @@ -3,4 +3,6 @@ package de.ellpeck.naturesaura.aura; public interface IAuraContainerProvider { IAuraContainer container(); + + boolean isArtificial(); } 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 59d822aa..afddff5c 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAncientLeaves.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAncientLeaves.java @@ -28,6 +28,11 @@ public class TileEntityAncientLeaves extends TileEntityImpl implements IAuraCont 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/TileEntityNatureAltar.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java index 2d6b8a52..e331e67f 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java @@ -62,7 +62,7 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable, new BlockPos(-1, -1, -1), new BlockPos(1, -1, -1) }; - private static final BlockPos[] GRASS_POSITIONS = new BlockPos[]{ + private static final BlockPos[] WOOD_POSITIONS = new BlockPos[]{ new BlockPos(-1, -1, 0), new BlockPos(1, -1, 0), new BlockPos(0, -1, -1), @@ -101,10 +101,10 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable, if (!this.world.isRemote) { if (this.world.getTotalWorldTime() % 40 == 0) { - boolean fine = this.check(BRICK_POSITIONS, Blocks.STONEBRICK.getDefaultState()) - && this.check(MOSSY_POSITIONS, Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, EnumType.MOSSY)) - && this.check(CHISELED_POSITIONS, Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, EnumType.CHISELED)) - && this.check(GRASS_POSITIONS, Blocks.GRASS.getDefaultState()); + boolean fine = this.check(BRICK_POSITIONS, Blocks.STONEBRICK.getDefaultState(), false) + && this.check(MOSSY_POSITIONS, Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, EnumType.MOSSY), false) + && this.check(CHISELED_POSITIONS, Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, EnumType.CHISELED), false) + && this.check(WOOD_POSITIONS, Blocks.PLANKS.getDefaultState(), true); if (fine != this.structureFine) { this.structureFine = fine; this.sendToClients(); @@ -173,9 +173,10 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable, } } - private boolean check(BlockPos[] positions, IBlockState state) { + private boolean check(BlockPos[] positions, IBlockState state, boolean blockOnly) { for (BlockPos offset : positions) { - if (this.world.getBlockState(this.pos.add(offset)) != state) { + IBlockState world = this.world.getBlockState(this.pos.add(offset)); + if (blockOnly ? world.getBlock() != state.getBlock() : world != state) { return false; } } @@ -200,4 +201,9 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable, public IAuraContainer container() { return this.container; } + + @Override + public boolean isArtificial() { + return true; + } } diff --git a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java index 262ee538..17e540cd 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java @@ -1,11 +1,20 @@ package de.ellpeck.naturesaura.events; +import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.aura.IAuraContainer; +import de.ellpeck.naturesaura.aura.IAuraContainerProvider; +import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.particles.ParticleHandler; import de.ellpeck.naturesaura.particles.ParticleMagic; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -48,4 +57,45 @@ public class ClientEvents { ParticleHandler.clearParticles(); } } + + @SubscribeEvent + public void onOverlayRender(RenderGameOverlayEvent.Post event) { + Minecraft mc = Minecraft.getMinecraft(); + if (event.getType() == ElementType.ALL && mc.currentScreen == null) { + ScaledResolution res = event.getResolution(); + if (mc.player != null) { + ItemStack stack = mc.player.getHeldItemMainhand(); + if (!stack.isEmpty() && stack.getItem() == ModItems.EYE) { + int maxAura = 0; + int aura = 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(); + } + } + } + String area = "Aura in the area: " + aura + " / " + maxAura; + mc.fontRenderer.drawString(area, 5, 5, 0xFFFFFF, true); + + 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(); + String s = "Aura stored: " + container.getStoredAura() + " / " + container.getMaxAura(); + mc.fontRenderer.drawString(s, + (res.getScaledWidth() - mc.fontRenderer.getStringWidth(s)) / 2, res.getScaledHeight() / 4 * 3, + container.getAuraColor(), true); + } + } + } + } + } + } + } } diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java b/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java new file mode 100644 index 00000000..c869af31 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java @@ -0,0 +1,8 @@ +package de.ellpeck.naturesaura.items; + +public class ItemEye extends ItemImpl { + + public ItemEye() { + super("eye"); + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemImpl.java b/src/main/java/de/ellpeck/naturesaura/items/ItemImpl.java new file mode 100644 index 00000000..23ef9b03 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemImpl.java @@ -0,0 +1,55 @@ +package de.ellpeck.naturesaura.items; + +import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.reg.IModItem; +import de.ellpeck.naturesaura.reg.IModelProvider; +import de.ellpeck.naturesaura.reg.ModRegistry; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; + +import java.util.Collections; +import java.util.Map; + +public class ItemImpl extends Item implements IModItem, IModelProvider { + + private final String baseName; + + public ItemImpl(String baseName) { + this.baseName = baseName; + ModRegistry.addItemOrBlock(this); + } + + @Override + public String getBaseName() { + return this.baseName; + } + + @Override + public boolean shouldAddCreative() { + return true; + } + + @Override + public void onPreInit(FMLPreInitializationEvent event) { + + } + + @Override + public void onInit(FMLInitializationEvent event) { + + } + + @Override + public void onPostInit(FMLPostInitializationEvent event) { + + } + + @Override + public Map getModelLocations() { + return Collections.singletonMap(new ItemStack(this), new ModelVariant(new ResourceLocation(NaturesAura.MOD_ID, this.getBaseName()), "inventory")); + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java new file mode 100644 index 00000000..dc1104ea --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java @@ -0,0 +1,8 @@ +package de.ellpeck.naturesaura.items; + +import net.minecraft.item.Item; + +public final class ModItems { + + public static final Item EYE = new ItemEye(); +} diff --git a/src/main/java/de/ellpeck/naturesaura/particles/ParticleHandler.java b/src/main/java/de/ellpeck/naturesaura/particles/ParticleHandler.java index 8b09bd9c..61ff9a8b 100644 --- a/src/main/java/de/ellpeck/naturesaura/particles/ParticleHandler.java +++ b/src/main/java/de/ellpeck/naturesaura/particles/ParticleHandler.java @@ -15,26 +15,31 @@ import org.lwjgl.opengl.GL11; import java.util.ArrayList; import java.util.List; +import java.util.function.Supplier; @SideOnly(Side.CLIENT) public final class ParticleHandler { private static final List PARTICLES = new ArrayList<>(); - public static void spawnParticle(Particle particle, double x, double y, double z, int range) { - if (particle != null && Minecraft.getMinecraft().player.getDistanceSq(x, y, z) <= range * range) { - PARTICLES.add(particle); + public static void spawnParticle(Supplier particle, double x, double y, double z, int range) { + if (Minecraft.getMinecraft().player.getDistanceSq(x, y, z) <= range * range) { + Minecraft mc = Minecraft.getMinecraft(); + int setting = mc.gameSettings.particleSetting; + if (setting == 0 || + setting == 1 && mc.world.rand.nextInt(3) == 0 || + setting == 2 && mc.world.rand.nextInt(10) == 0) { + PARTICLES.add(particle.get()); + } } } public static void updateParticles() { - for (int i = 0; i < PARTICLES.size(); i++) { + for (int i = PARTICLES.size() - 1; i >= 0; i--) { Particle particle = PARTICLES.get(i); particle.onUpdate(); - if (!particle.isAlive()) { PARTICLES.remove(i); - i--; } } } diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java index e636ad1a..047c16dd 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java @@ -63,8 +63,7 @@ public class ClientProxy implements IProxy { @Override public void spawnMagicParticle(World world, double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade) { - ParticleMagic particle = new ParticleMagic(world, posX, posY, posZ, motionX, motionY, motionZ, color, scale, maxAge, gravity, collision, fade); - ParticleHandler.spawnParticle(particle, posX, posY, posZ, 32); + ParticleHandler.spawnParticle(() -> new ParticleMagic(world, posX, posY, posZ, motionX, motionY, motionZ, color, scale, maxAge, gravity, collision, fade), posX, posY, posZ, 32); } @Override diff --git a/src/main/resources/assets/naturesaura/lang/en_US.lang b/src/main/resources/assets/naturesaura/lang/en_US.lang index f4011779..3b2aaf56 100644 --- a/src/main/resources/assets/naturesaura/lang/en_US.lang +++ b/src/main/resources/assets/naturesaura/lang/en_US.lang @@ -5,4 +5,6 @@ tile.naturesaura.ancient_bark.name=Ancient Bark tile.naturesaura.ancient_leaves.name=Ancient Leaves tile.naturesaura.ancient_sapling.name=Ancient Sapling tile.naturesaura.nature_altar.name=Natural Altar -tile.naturesaura.decayed_leaves.name=Decayed Leaves \ No newline at end of file +tile.naturesaura.decayed_leaves.name=Decayed Leaves + +item.naturesaura.eye.name=Environmental Eye \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/models/item/eye.json b/src/main/resources/assets/naturesaura/models/item/eye.json new file mode 100644 index 00000000..ba954b5a --- /dev/null +++ b/src/main/resources/assets/naturesaura/models/item/eye.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "naturesaura:items/eye" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/textures/items/eye.png b/src/main/resources/assets/naturesaura/textures/items/eye.png new file mode 100644 index 00000000..db9c31d3 Binary files /dev/null and b/src/main/resources/assets/naturesaura/textures/items/eye.png differ