added the rod of shadows

This commit is contained in:
Ellpeck 2019-02-19 17:23:03 +01:00
parent c97a13f737
commit c186976898
13 changed files with 169 additions and 15 deletions

View file

@ -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);

View file

@ -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

View file

@ -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();

View file

@ -72,7 +72,11 @@ public class ClientEvents {
String prefix = TextFormatting.GREEN + "[" + NaturesAura.MOD_NAME + "]" + TextFormatting.RESET + " ";
List<String> 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();

View file

@ -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<ItemStack> 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);
}
}

View file

@ -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();
}

View file

@ -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<Particle> PARTICLES = new ArrayList<>();
private static final List<Particle> PARTICLES_NO_DEPTH = new ArrayList<>();
public static void spawnParticle(Supplier<Particle> particle, double x, double y, double z, int range) {
public static void spawnParticle(Supplier<Particle> 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<Particle> 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();
}
}

View file

@ -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

View file

@ -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);
}

View file

@ -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);

View file

@ -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

View file

@ -0,0 +1,6 @@
{
"parent": "item/handheld",
"textures": {
"layer0": "naturesaura:items/cave_finder"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B