From c18697689847ce3ea4d206844291251e13bbd280 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 19 Feb 2019 17:23:03 +0100 Subject: [PATCH] added the rod of shadows --- .../de/ellpeck/naturesaura/InternalHooks.java | 10 +++ .../naturesaura/api/NaturesAuraAPI.java | 18 ++++++ .../naturesaura/api/internal/StubHooks.java | 10 +++ .../naturesaura/events/ClientEvents.java | 10 ++- .../naturesaura/items/ItemCaveFinder.java | 61 ++++++++++++++++++ .../ellpeck/naturesaura/items/ModItems.java | 1 + .../particles/ParticleHandler.java | 41 ++++++++---- .../naturesaura/proxy/ClientProxy.java | 12 +++- .../de/ellpeck/naturesaura/proxy/IProxy.java | 4 ++ .../naturesaura/proxy/ServerProxy.java | 10 +++ .../assets/naturesaura/lang/en_US.lang | 1 + .../naturesaura/models/item/cave_finder.json | 6 ++ .../textures/items/cave_finder.png | Bin 0 -> 352 bytes 13 files changed, 169 insertions(+), 15 deletions(-) create mode 100644 src/main/java/de/ellpeck/naturesaura/items/ItemCaveFinder.java create mode 100644 src/main/resources/assets/naturesaura/models/item/cave_finder.json create mode 100644 src/main/resources/assets/naturesaura/textures/items/cave_finder.png diff --git a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java index 6d802389..738177e4 100644 --- a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java +++ b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java @@ -89,6 +89,16 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks { } } + @Override + public void setParticleDepth(boolean depth) { + NaturesAura.proxy.setParticleDepth(depth); + } + + @Override + public void setParticleSpawnRange(int range) { + NaturesAura.proxy.setParticleSpawnRange(range); + } + @Override public IMultiblock createMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers) { return new Multiblock(name, pattern, rawMatchers); diff --git a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java index 58d27d78..30c9b705 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java +++ b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java @@ -242,6 +242,24 @@ public final class NaturesAuraAPI { */ void spawnParticleStream(float startX, float startY, float startZ, float endX, float endY, float endZ, float speed, int color, float scale); + /** + * Sets wether Nature's Aura particles that are spawned will be rendered + * with depth test enabled or not. Default value is true, please reset + * after changing. + * + * @param depth Wether depth test should be enabled or not + */ + void setParticleDepth(boolean depth); + + /** + * Sets the range that Nature's Aura particles that are spawned will + * have to have from the player at most to actually be spawned. Default + * value is 32, please reset after changing. + * + * @param range The range that particle spawning should have + */ + void setParticleSpawnRange(int range); + /** * This method is used to create a custom multiblock from within the * API. The multiblock will automatically be registered both to Nature's diff --git a/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java b/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java index f8be1c97..ea3c67de 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java +++ b/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java @@ -31,6 +31,16 @@ public class StubHooks implements NaturesAuraAPI.IInternalHooks { } + @Override + public void setParticleDepth(boolean depth) { + + } + + @Override + public void setParticleSpawnRange(int range) { + + } + @Override public IMultiblock createMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers) { return new StubMultiblock(); diff --git a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java index 78ab004a..58513157 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java @@ -72,7 +72,11 @@ public class ClientEvents { String prefix = TextFormatting.GREEN + "[" + NaturesAura.MOD_NAME + "]" + TextFormatting.RESET + " "; List left = event.getLeft(); left.add(""); - left.add(prefix + "Particles: " + ParticleHandler.getParticleAmount()); + + int depth = ParticleHandler.getParticleAmount(true); + int noDepth = ParticleHandler.getParticleAmount(false); + left.add(prefix + "P: " + (depth + noDepth) + " (D: " + depth + " nD: " + noDepth + ")"); + left.add(prefix + "PR: " + ParticleHandler.range + " PD: " + ParticleHandler.depthEnabled); if (mc.player.capabilities.isCreativeMode) { MutableInt amount = new MutableInt(IAuraChunk.DEFAULT_AURA); @@ -82,8 +86,8 @@ public class ClientEvents { amount.add(drainSpot); }); NumberFormat format = NumberFormat.getInstance(); - left.add(prefix + "Aura: " + format.format(amount.intValue()) + " in " + spots.intValue() + " spots (range 35)"); - left.add(prefix + "Type: " + IAuraType.forWorld(mc.world).getName()); + left.add(prefix + "A: " + format.format(amount.intValue()) + " (S: " + spots.intValue() + ")"); + left.add(prefix + "AT: " + IAuraType.forWorld(mc.world).getName()); } } mc.profiler.endSection(); diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemCaveFinder.java b/src/main/java/de/ellpeck/naturesaura/items/ItemCaveFinder.java new file mode 100644 index 00000000..46a2d5cf --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemCaveFinder.java @@ -0,0 +1,61 @@ +package de.ellpeck.naturesaura.items; + +import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.EnumSkyBlock; +import net.minecraft.world.World; + +public class ItemCaveFinder extends ItemImpl { + public ItemCaveFinder() { + super("cave_finder"); + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + NaturesAuraAPI.IInternalHooks inst = NaturesAuraAPI.instance(); + if (!inst.extractAuraFromPlayer(playerIn, 20000, worldIn.isRemote)) + return new ActionResult<>(EnumActionResult.FAIL, stack); + if (worldIn.isRemote) { + inst.setParticleDepth(false); + inst.setParticleSpawnRange(64); + BlockPos pos = playerIn.getPosition(); + int range = 30; + for (int x = -range; x <= range; x++) + for (int y = -range; y <= range; y++) + for (int z = -range; z <= range; z++) { + BlockPos offset = pos.add(x, y, z); + IBlockState state = worldIn.getBlockState(offset); + if (!state.getBlock().canCreatureSpawn(state, worldIn, offset, EntityLiving.SpawnPlacementType.ON_GROUND)) + continue; + + BlockPos offUp = offset.up(); + IBlockState stateUp = worldIn.getBlockState(offUp); + if (stateUp.isBlockNormalCube() || stateUp.getMaterial().isLiquid()) + continue; + + int sky = worldIn.getLightFor(EnumSkyBlock.SKY, offUp); + int block = worldIn.getLightFor(EnumSkyBlock.BLOCK, offUp); + if (sky > 7 || block > 7) + continue; + + inst.spawnMagicParticle( + offset.getX() + 0.5F, offset.getY() + 1.5F, offset.getZ() + 0.5F, + 0F, 0F, 0F, 0x992101, 2.5F, 20 * 30, 0F, false, true); + } + inst.setParticleDepth(true); + inst.setParticleSpawnRange(32); + + playerIn.swingArm(handIn); + } + playerIn.getCooldownTracker().setCooldown(this, 20 * 30); + return new ActionResult<>(EnumActionResult.SUCCESS, stack); + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java index e2859404..6a3990e2 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java @@ -55,4 +55,5 @@ public final class ModItems { public static final Item TOKEN_RAGE = new ItemImpl("token_rage"); public static final Item TOKEN_GRIEF = new ItemImpl("token_grief"); public static final Item ENDER_ACCESS = new ItemEnderAccess(); + public static final Item CAVE_FINDER = new ItemCaveFinder(); } diff --git a/src/main/java/de/ellpeck/naturesaura/particles/ParticleHandler.java b/src/main/java/de/ellpeck/naturesaura/particles/ParticleHandler.java index 490f99ed..5961b074 100644 --- a/src/main/java/de/ellpeck/naturesaura/particles/ParticleHandler.java +++ b/src/main/java/de/ellpeck/naturesaura/particles/ParticleHandler.java @@ -20,9 +20,12 @@ import java.util.function.Supplier; @SideOnly(Side.CLIENT) public final class ParticleHandler { + public static boolean depthEnabled = true; + public static int range = 32; private static final List PARTICLES = new ArrayList<>(); + private static final List PARTICLES_NO_DEPTH = new ArrayList<>(); - public static void spawnParticle(Supplier particle, double x, double y, double z, int range) { + public static void spawnParticle(Supplier particle, double x, double y, double z) { if (Minecraft.getMinecraft().player.getDistanceSq(x, y, z) <= range * range) { Minecraft mc = Minecraft.getMinecraft(); if (ModConfig.client.respectVanillaParticleSettings) { @@ -35,16 +38,25 @@ public final class ParticleHandler { double setting = ModConfig.client.particleAmount; if (setting < 1 && mc.world.rand.nextDouble() > setting) return; - PARTICLES.add(particle.get()); + + if (depthEnabled) + PARTICLES.add(particle.get()); + else + PARTICLES_NO_DEPTH.add(particle.get()); } } public static void updateParticles() { - for (int i = PARTICLES.size() - 1; i >= 0; i--) { - Particle particle = PARTICLES.get(i); + updateList(PARTICLES); + updateList(PARTICLES_NO_DEPTH); + } + + private static void updateList(List particles) { + for (int i = particles.size() - 1; i >= 0; i--) { + Particle particle = particles.get(i); particle.onUpdate(); if (!particle.isAlive()) - PARTICLES.remove(i); + particles.remove(i); } } @@ -70,6 +82,7 @@ public final class ParticleHandler { GlStateManager.enableBlend(); GlStateManager.alphaFunc(516, 0.003921569F); GlStateManager.disableCull(); + GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE); GlStateManager.depthMask(false); @@ -77,13 +90,18 @@ public final class ParticleHandler { Tessellator tessy = Tessellator.getInstance(); BufferBuilder buffer = tessy.getBuffer(); - GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE); buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP); for (Particle particle : PARTICLES) particle.renderParticle(buffer, player, partialTicks, x, xz, z, yz, xy); - tessy.draw(); + GlStateManager.disableDepth(); + buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP); + for (Particle particle : PARTICLES_NO_DEPTH) + particle.renderParticle(buffer, player, partialTicks, x, xz, z, yz, xy); + tessy.draw(); + GlStateManager.enableDepth(); + GlStateManager.enableCull(); GlStateManager.depthMask(true); GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); @@ -94,13 +112,14 @@ public final class ParticleHandler { } } - public static int getParticleAmount() { - return PARTICLES.size(); + public static int getParticleAmount(boolean depth) { + return depth ? PARTICLES.size() : PARTICLES_NO_DEPTH.size(); } public static void clearParticles() { - if (!PARTICLES.isEmpty()) { + if (!PARTICLES.isEmpty()) PARTICLES.clear(); - } + if (!PARTICLES_NO_DEPTH.isEmpty()) + PARTICLES_NO_DEPTH.clear(); } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java index c61e010e..2e06fd16 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java @@ -90,7 +90,17 @@ public class ClientProxy implements IProxy { ParticleHandler.spawnParticle(() -> new ParticleMagic(Minecraft.getMinecraft().world, posX, posY, posZ, motionX, motionY, motionZ, - color, scale, maxAge, gravity, collision, fade), posX, posY, posZ, 32); + color, scale, maxAge, gravity, collision, fade), posX, posY, posZ); + } + + @Override + public void setParticleDepth(boolean depth) { + ParticleHandler.depthEnabled = depth; + } + + @Override + public void setParticleSpawnRange(int range) { + ParticleHandler.range = range; } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java index 6bf5747d..1f60469d 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java @@ -32,5 +32,9 @@ public interface IProxy { void spawnMagicParticle(double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade); + void setParticleDepth(boolean depth); + + void setParticleSpawnRange(int range); + void scheduleTask(Runnable runnable); } diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java index e047067c..2676d656 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java @@ -61,6 +61,16 @@ public class ServerProxy implements IProxy { } + @Override + public void setParticleDepth(boolean depth) { + + } + + @Override + public void setParticleSpawnRange(int range) { + + } + @Override public void scheduleTask(Runnable runnable) { FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(runnable); diff --git a/src/main/resources/assets/naturesaura/lang/en_US.lang b/src/main/resources/assets/naturesaura/lang/en_US.lang index f44a729b..97eab86f 100644 --- a/src/main/resources/assets/naturesaura/lang/en_US.lang +++ b/src/main/resources/assets/naturesaura/lang/en_US.lang @@ -91,6 +91,7 @@ item.naturesaura.token_rage.name=Token of Rage item.naturesaura.token_sorrow.name=Token of Sorrow item.naturesaura.token_terror.name=Token of Terror item.naturesaura.ender_access.name=Ender Ocular +item.naturesaura.cave_finder.name=Staff of Shadows container.naturesaura.tree_ritual.name=Ritual of the Forest container.naturesaura.altar.name=Natural Altar Infusion diff --git a/src/main/resources/assets/naturesaura/models/item/cave_finder.json b/src/main/resources/assets/naturesaura/models/item/cave_finder.json new file mode 100644 index 00000000..d0b2c6aa --- /dev/null +++ b/src/main/resources/assets/naturesaura/models/item/cave_finder.json @@ -0,0 +1,6 @@ +{ + "parent": "item/handheld", + "textures": { + "layer0": "naturesaura:items/cave_finder" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/textures/items/cave_finder.png b/src/main/resources/assets/naturesaura/textures/items/cave_finder.png new file mode 100644 index 0000000000000000000000000000000000000000..2b2a29fea542ecdcb9384affbfc3bf2cb17062fc GIT binary patch literal 352 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`3dtTpz6=aistgPb%?u1b{{!il z3=E|P3=FRl7#OT(FffScPl`Y422{&g;1OBOz`)H7!i>2rE!%;D5+$w?CBgY=CFO}l zsSE{)nRz98d8s7|CVGZ?rYY_bAX^W4x;Tbd_|KhSD0E0cz;!2s`G%4yBIgp^6%Q}D z=w{Qh)qTUJjm5{5D>q#|ei?fBy!B-pu}g*dY%T3dB1&E z`7%fB`!2h;?{tnw;DiN&mrA!QJ--t$n@!b2vXwN5pOYfR}>W9*UCyP@ii23DvrWr-5 rwF?Ms+UXKyz>?%`6uf6ne^`Ft!AA>coV0ic^bLcjtDnm{r-UW|B}9I= literal 0 HcmV?d00001