mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 03:43:30 +01:00
loot finder, part 1
This commit is contained in:
parent
4bd1f9eece
commit
391f5b13f5
11 changed files with 101 additions and 10 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<ItemStack> 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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -28,20 +28,23 @@ public final class ParticleHandler {
|
|||
private static final List<Particle> 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> 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<Particle> particles) {
|
||||
|
|
|
@ -103,6 +103,11 @@ public class ClientProxy implements IProxy {
|
|||
ParticleHandler.range = range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParticleCulling(boolean cull) {
|
||||
ParticleHandler.culling = cull;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Entity> void registerEntityRenderer(EntityType<T> entityClass, Supplier<IRenderFactory<T>> renderFactory) {
|
||||
RenderingRegistry.registerEntityRenderingHandler(entityClass, renderFactory.get());
|
||||
|
|
|
@ -29,6 +29,8 @@ public interface IProxy {
|
|||
|
||||
void setParticleSpawnRange(int range);
|
||||
|
||||
void setParticleCulling(boolean cull);
|
||||
|
||||
<T extends Entity> void registerEntityRenderer(EntityType<T> entityClass, Supplier<IRenderFactory<T>> renderFactory);
|
||||
|
||||
}
|
||||
|
|
|
@ -57,6 +57,11 @@ public class ServerProxy implements IProxy {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParticleCulling(boolean cull) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Entity> void registerEntityRenderer(EntityType<T> entityClass, Supplier<IRenderFactory<T>> renderFactory) {
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue