diff --git a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java index 190c7fb9..4034ad6a 100644 --- a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java +++ b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java @@ -77,6 +77,11 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks { NaturesAura.proxy.setParticleSpawnRange(range); } + @Override + public void setParticleCulling(boolean cull) { + NaturesAura.proxy.setParticleCulling(cull); + } + @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 0a00817d..bf9ecaf7 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java +++ b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java @@ -274,6 +274,8 @@ public final class NaturesAuraAPI { */ void setParticleSpawnRange(int range); + void setParticleCulling(boolean cull); + /** * 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 d300a12d..d1bba219 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java +++ b/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java @@ -46,6 +46,11 @@ public class StubHooks implements NaturesAuraAPI.IInternalHooks { } + @Override + public void setParticleCulling(boolean cull) { + + } + @Override public IMultiblock createMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers) { return new StubMultiblock(); diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemCaveFinder.java b/src/main/java/de/ellpeck/naturesaura/items/ItemCaveFinder.java index 28c7670d..cf60c3b5 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemCaveFinder.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemCaveFinder.java @@ -27,6 +27,7 @@ public class ItemCaveFinder extends ItemImpl { if (worldIn.isRemote) { inst.setParticleDepth(false); inst.setParticleSpawnRange(64); + inst.setParticleCulling(false); BlockPos pos = playerIn.getPosition(); int range = 30; for (int x = -range; x <= range; x++) @@ -53,6 +54,7 @@ public class ItemCaveFinder extends ItemImpl { } inst.setParticleDepth(true); inst.setParticleSpawnRange(32); + inst.setParticleCulling(true); playerIn.swingArm(handIn); } diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemLootFinder.java b/src/main/java/de/ellpeck/naturesaura/items/ItemLootFinder.java new file mode 100644 index 00000000..a6a2a082 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemLootFinder.java @@ -0,0 +1,59 @@ +package de.ellpeck.naturesaura.items; + +import de.ellpeck.naturesaura.Helper; +import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.ActionResultType; +import net.minecraft.util.Hand; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.items.CapabilityItemHandler; + +public class ItemLootFinder extends ItemImpl { + public ItemLootFinder() { + super("loot_finder"); + } + + @Override + public ActionResult onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + NaturesAuraAPI.IInternalHooks inst = NaturesAuraAPI.instance(); + if (!inst.extractAuraFromPlayer(playerIn, 100000, false)) + return new ActionResult<>(ActionResultType.FAIL, stack); + if (worldIn.isRemote) { + inst.setParticleDepth(false); + inst.setParticleSpawnRange(64); + inst.setParticleCulling(false); + + BlockPos pos = playerIn.getPosition(); + Helper.getTileEntitiesInArea(worldIn, pos, 64, tile -> { + if (tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).isPresent()) { + inst.spawnMagicParticle( + tile.getPos().getX() + 0.5F, tile.getPos().getY() + 0.5F, tile.getPos().getZ() + 0.5F, + 0F, 0F, 0F, 0xf5f10a, 6F, 20 * 60, 0F, false, true); + } + return false; + }); + for (Entity entity : worldIn.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(pos).grow(64))) { + if (!(entity instanceof LivingEntity) && entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).isPresent()) { + inst.spawnMagicParticle( + entity.getPosX(), entity.getPosYEye(), entity.getPosZ(), + 0F, 0F, 0F, 0xf5f10a, 6F, 20 * 60, 0F, false, true); + } + } + + inst.setParticleDepth(true); + inst.setParticleSpawnRange(32); + inst.setParticleCulling(true); + + playerIn.swingArm(handIn); + } + playerIn.getCooldownTracker().setCooldown(this, 20 * 60); + return new ActionResult<>(ActionResultType.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 722a8ec7..865bfbf0 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java @@ -47,4 +47,5 @@ public final class ModItems { public static Item CRIMSON_MEAL; public static Item DEATH_RING; public static Item TAINTED_GOLD; + public static Item LOOT_FINDER; } diff --git a/src/main/java/de/ellpeck/naturesaura/particles/ParticleHandler.java b/src/main/java/de/ellpeck/naturesaura/particles/ParticleHandler.java index 120e8a6f..d9c74d96 100644 --- a/src/main/java/de/ellpeck/naturesaura/particles/ParticleHandler.java +++ b/src/main/java/de/ellpeck/naturesaura/particles/ParticleHandler.java @@ -28,20 +28,23 @@ public final class ParticleHandler { private static final List PARTICLES_NO_DEPTH = new ArrayList<>(); public static boolean depthEnabled = true; public static int range = 32; + public static boolean culling = true; public static void spawnParticle(Supplier particle, double x, double y, double z) { if (Minecraft.getInstance().player.getDistanceSq(x, y, z) <= range * range) { - Minecraft mc = Minecraft.getInstance(); - if (ModConfig.instance.respectVanillaParticleSettings.get()) { - ParticleStatus setting = mc.gameSettings.particles; - if (setting != ParticleStatus.ALL && - (setting != ParticleStatus.DECREASED || mc.world.rand.nextInt(3) != 0) && - (setting != ParticleStatus.MINIMAL || mc.world.rand.nextInt(10) != 0)) + if (culling) { + Minecraft mc = Minecraft.getInstance(); + if (ModConfig.instance.respectVanillaParticleSettings.get()) { + ParticleStatus setting = mc.gameSettings.particles; + if (setting != ParticleStatus.ALL && + (setting != ParticleStatus.DECREASED || mc.world.rand.nextInt(3) != 0) && + (setting != ParticleStatus.MINIMAL || mc.world.rand.nextInt(10) != 0)) + return; + } + double setting = ModConfig.instance.particleAmount.get(); + if (setting < 1 && mc.world.rand.nextDouble() > setting) return; } - double setting = ModConfig.instance.particleAmount.get(); - if (setting < 1 && mc.world.rand.nextDouble() > setting) - return; if (depthEnabled) PARTICLES.add(particle.get()); @@ -56,6 +59,7 @@ public final class ParticleHandler { depthEnabled = true; range = 32; + culling = true; } private static void updateList(List particles) { diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java index c3bf674e..cadd4201 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java @@ -103,6 +103,11 @@ public class ClientProxy implements IProxy { ParticleHandler.range = range; } + @Override + public void setParticleCulling(boolean cull) { + ParticleHandler.culling = cull; + } + @Override public void registerEntityRenderer(EntityType entityClass, Supplier> renderFactory) { RenderingRegistry.registerEntityRenderingHandler(entityClass, renderFactory.get()); diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java index a43ac04e..aee2ef26 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java @@ -29,6 +29,8 @@ public interface IProxy { void setParticleSpawnRange(int range); + void setParticleCulling(boolean cull); + void registerEntityRenderer(EntityType entityClass, Supplier> renderFactory); } diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java index aea600f5..03d1738f 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java @@ -57,6 +57,11 @@ public class ServerProxy implements IProxy { } + @Override + public void setParticleCulling(boolean cull) { + + } + @Override public void registerEntityRenderer(EntityType entityClass, Supplier> renderFactory) { diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java index ff97c514..da294e6e 100644 --- a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java +++ b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java @@ -196,7 +196,8 @@ public final class ModRegistry { new ItemCaveFinder(), new ItemCrimsonMeal(), new ItemDeathRing(), - new ItemImpl("tainted_gold") + new ItemImpl("tainted_gold"), + new ItemLootFinder() ); Helper.populateObjectHolders(ModItems.class, event.getRegistry()); }