loot finder, part 1

This commit is contained in:
Ellpeck 2020-02-28 15:36:12 +01:00
parent 4bd1f9eece
commit 391f5b13f5
11 changed files with 101 additions and 10 deletions

View file

@ -77,6 +77,11 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
NaturesAura.proxy.setParticleSpawnRange(range); NaturesAura.proxy.setParticleSpawnRange(range);
} }
@Override
public void setParticleCulling(boolean cull) {
NaturesAura.proxy.setParticleCulling(cull);
}
@Override @Override
public IMultiblock createMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers) { public IMultiblock createMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers) {
return new Multiblock(name, pattern, rawMatchers); return new Multiblock(name, pattern, rawMatchers);

View file

@ -274,6 +274,8 @@ public final class NaturesAuraAPI {
*/ */
void setParticleSpawnRange(int range); void setParticleSpawnRange(int range);
void setParticleCulling(boolean cull);
/** /**
* This method is used to create a custom multiblock from within the * This method is used to create a custom multiblock from within the
* API. The multiblock will automatically be registered both to Nature's * API. The multiblock will automatically be registered both to Nature's

View file

@ -46,6 +46,11 @@ public class StubHooks implements NaturesAuraAPI.IInternalHooks {
} }
@Override
public void setParticleCulling(boolean cull) {
}
@Override @Override
public IMultiblock createMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers) { public IMultiblock createMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers) {
return new StubMultiblock(); return new StubMultiblock();

View file

@ -27,6 +27,7 @@ public class ItemCaveFinder extends ItemImpl {
if (worldIn.isRemote) { if (worldIn.isRemote) {
inst.setParticleDepth(false); inst.setParticleDepth(false);
inst.setParticleSpawnRange(64); inst.setParticleSpawnRange(64);
inst.setParticleCulling(false);
BlockPos pos = playerIn.getPosition(); BlockPos pos = playerIn.getPosition();
int range = 30; int range = 30;
for (int x = -range; x <= range; x++) for (int x = -range; x <= range; x++)
@ -53,6 +54,7 @@ public class ItemCaveFinder extends ItemImpl {
} }
inst.setParticleDepth(true); inst.setParticleDepth(true);
inst.setParticleSpawnRange(32); inst.setParticleSpawnRange(32);
inst.setParticleCulling(true);
playerIn.swingArm(handIn); playerIn.swingArm(handIn);
} }

View file

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

View file

@ -47,4 +47,5 @@ public final class ModItems {
public static Item CRIMSON_MEAL; public static Item CRIMSON_MEAL;
public static Item DEATH_RING; public static Item DEATH_RING;
public static Item TAINTED_GOLD; public static Item TAINTED_GOLD;
public static Item LOOT_FINDER;
} }

View file

@ -28,9 +28,11 @@ public final class ParticleHandler {
private static final List<Particle> PARTICLES_NO_DEPTH = new ArrayList<>(); private static final List<Particle> PARTICLES_NO_DEPTH = new ArrayList<>();
public static boolean depthEnabled = true; public static boolean depthEnabled = true;
public static int range = 32; public static int range = 32;
public static boolean culling = true;
public static void spawnParticle(Supplier<Particle> particle, double x, double y, double z) { public static void spawnParticle(Supplier<Particle> particle, double x, double y, double z) {
if (Minecraft.getInstance().player.getDistanceSq(x, y, z) <= range * range) { if (Minecraft.getInstance().player.getDistanceSq(x, y, z) <= range * range) {
if (culling) {
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
if (ModConfig.instance.respectVanillaParticleSettings.get()) { if (ModConfig.instance.respectVanillaParticleSettings.get()) {
ParticleStatus setting = mc.gameSettings.particles; ParticleStatus setting = mc.gameSettings.particles;
@ -42,6 +44,7 @@ public final class ParticleHandler {
double setting = ModConfig.instance.particleAmount.get(); double setting = ModConfig.instance.particleAmount.get();
if (setting < 1 && mc.world.rand.nextDouble() > setting) if (setting < 1 && mc.world.rand.nextDouble() > setting)
return; return;
}
if (depthEnabled) if (depthEnabled)
PARTICLES.add(particle.get()); PARTICLES.add(particle.get());
@ -56,6 +59,7 @@ public final class ParticleHandler {
depthEnabled = true; depthEnabled = true;
range = 32; range = 32;
culling = true;
} }
private static void updateList(List<Particle> particles) { private static void updateList(List<Particle> particles) {

View file

@ -103,6 +103,11 @@ public class ClientProxy implements IProxy {
ParticleHandler.range = range; ParticleHandler.range = range;
} }
@Override
public void setParticleCulling(boolean cull) {
ParticleHandler.culling = cull;
}
@Override @Override
public <T extends Entity> void registerEntityRenderer(EntityType<T> entityClass, Supplier<IRenderFactory<T>> renderFactory) { public <T extends Entity> void registerEntityRenderer(EntityType<T> entityClass, Supplier<IRenderFactory<T>> renderFactory) {
RenderingRegistry.registerEntityRenderingHandler(entityClass, renderFactory.get()); RenderingRegistry.registerEntityRenderingHandler(entityClass, renderFactory.get());

View file

@ -29,6 +29,8 @@ public interface IProxy {
void setParticleSpawnRange(int range); void setParticleSpawnRange(int range);
void setParticleCulling(boolean cull);
<T extends Entity> void registerEntityRenderer(EntityType<T> entityClass, Supplier<IRenderFactory<T>> renderFactory); <T extends Entity> void registerEntityRenderer(EntityType<T> entityClass, Supplier<IRenderFactory<T>> renderFactory);
} }

View file

@ -57,6 +57,11 @@ public class ServerProxy implements IProxy {
} }
@Override
public void setParticleCulling(boolean cull) {
}
@Override @Override
public <T extends Entity> void registerEntityRenderer(EntityType<T> entityClass, Supplier<IRenderFactory<T>> renderFactory) { public <T extends Entity> void registerEntityRenderer(EntityType<T> entityClass, Supplier<IRenderFactory<T>> renderFactory) {

View file

@ -196,7 +196,8 @@ public final class ModRegistry {
new ItemCaveFinder(), new ItemCaveFinder(),
new ItemCrimsonMeal(), new ItemCrimsonMeal(),
new ItemDeathRing(), new ItemDeathRing(),
new ItemImpl("tainted_gold") new ItemImpl("tainted_gold"),
new ItemLootFinder()
); );
Helper.populateObjectHolders(ModItems.class, event.getRegistry()); Helper.populateObjectHolders(ModItems.class, event.getRegistry());
} }