mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-25 14:24:35 +00:00
Introduce bounds to search for sparkles! (#5343)
* Address c368692a3; create upper bound on number of blocks scanned and reduce memory utilization * Final cleanup on sparkle overhaul; all multiblock structures should now sparkle in < 1ms on average * Remove timing info; either enable sparkles or the message (not both)
This commit is contained in:
1 parent
6e3b3fcf56
commit
9456b68529
6 files changed
+90
-89
No files matched your search
@@ -146,6 +146,7 @@ import mekanism.common.item.ItemPortableTeleporter;
|
||||
import mekanism.common.item.ItemSeismicReader;
|
||||
import mekanism.common.item.ItemWalkieTalkie;
|
||||
import mekanism.common.multiblock.MultiblockManager;
|
||||
import mekanism.common.multiblock.UpdateProtocol.NodeChecker;
|
||||
import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterMessage;
|
||||
import mekanism.common.tile.TileEntityAdvancedFactory;
|
||||
import mekanism.common.tile.TileEntityAmbientAccumulator;
|
||||
@@ -999,30 +1000,30 @@ public class ClientProxy extends CommonProxy {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doGenericSparkle(TileEntity tileEntity, INodeChecker checker) {
|
||||
private void doSparkle(TileEntity tileEntity, SparkleAnimation anim) {
|
||||
EntityPlayerSP player = Minecraft.getMinecraft().player;
|
||||
if (tileEntity.getPos().distanceSq(player.getPosition()) <= 100) {
|
||||
player.sendStatusMessage(
|
||||
new TextComponentGroup(TextFormatting.BLUE).translation("chat.mek.multiblockformed"), true);
|
||||
// If player is within 16 blocks (256 = 16^2), show the status message/sparkles
|
||||
if (tileEntity.getPos().distanceSq(player.getPosition()) <= 256) {
|
||||
if (client.enableMultiblockFormationParticles) {
|
||||
new SparkleAnimation(tileEntity, checker).run();
|
||||
anim.run();
|
||||
} else {
|
||||
player.sendStatusMessage(
|
||||
new TextComponentGroup(TextFormatting.BLUE).translation("chat.mek.multiblockformed"), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doMultiblockSparkle(final TileEntityMultiblock<?> tileEntity) {
|
||||
EntityPlayerSP player = Minecraft.getMinecraft().player;
|
||||
if (tileEntity.getPos().distanceSq(player.getPosition()) <= 100) {
|
||||
player.sendStatusMessage(
|
||||
new TextComponentGroup(TextFormatting.BLUE).translation("chat.mek.multiblockformed"), true);
|
||||
if (client.enableMultiblockFormationParticles) {
|
||||
new SparkleAnimation(tileEntity, tile -> MultiblockManager.areEqual(tile, tileEntity)).run();
|
||||
}
|
||||
}
|
||||
public void doMultiblockSparkle(TileEntity tileEntity, BlockPos renderLoc, int length, int width, int height, INodeChecker checker) {
|
||||
doSparkle(tileEntity, new SparkleAnimation(tileEntity, renderLoc, length, width, height, checker));
|
||||
}
|
||||
|
||||
|
||||
public void doMultiblockSparkle(TileEntity tileEntity, BlockPos corner1, BlockPos corner2, INodeChecker checker) {
|
||||
doSparkle(tileEntity, new SparkleAnimation(tileEntity, corner1, corner2, checker));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package mekanism.client;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import mekanism.api.Coord4D;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.MekanismSounds;
|
||||
import mekanism.common.config.MekanismConfig.general;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -17,79 +17,64 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SparkleAnimation {
|
||||
|
||||
public TileEntity pointer;
|
||||
private TileEntity tile;
|
||||
private BlockPos corner1;
|
||||
private BlockPos corner2;
|
||||
private INodeChecker nodeChecker;
|
||||
|
||||
public Random random = new Random();
|
||||
|
||||
public Set<Coord4D> iteratedNodes = new HashSet<>();
|
||||
|
||||
public INodeChecker nodeChecker;
|
||||
|
||||
public SparkleAnimation(TileEntity tileEntity, INodeChecker checker) {
|
||||
pointer = tileEntity;
|
||||
nodeChecker = checker;
|
||||
public SparkleAnimation(TileEntity tileEntity, BlockPos corner1, BlockPos corner2, INodeChecker checker) {
|
||||
this.tile = tileEntity;
|
||||
this.corner1 = corner1;
|
||||
this.corner2 = corner2;
|
||||
this.nodeChecker = checker;
|
||||
}
|
||||
|
||||
public SparkleAnimation(TileEntity tileEntity, BlockPos renderLoc, int length, int width, int height, INodeChecker checker) {
|
||||
this.tile = tileEntity;
|
||||
this.corner1 = new BlockPos(renderLoc.getX(), renderLoc.getY() - 1, renderLoc.getZ());
|
||||
this.corner2 = new BlockPos(renderLoc.getX() + length, renderLoc.getY() + height - 2, renderLoc.getZ() + width - 1);
|
||||
this.nodeChecker = checker;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
if (general.dynamicTankEasterEgg) {
|
||||
pointer.getWorld()
|
||||
.playSound(null, pointer.getPos().getX(), pointer.getPos().getY(), pointer.getPos().getZ(),
|
||||
MekanismSounds.CJ_EASTER_EGG, SoundCategory.BLOCKS, 1F, 1F);
|
||||
if (general.dynamicTankEasterEgg) {
|
||||
tile.getWorld()
|
||||
.playSound(null, tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(),
|
||||
MekanismSounds.CJ_EASTER_EGG, SoundCategory.BLOCKS, 1F, 1F);
|
||||
}
|
||||
|
||||
// Using the provided radius, get an iterable over all the positions within the radius
|
||||
Iterator<MutableBlockPos> itr = BlockPos.getAllInBoxMutable(corner1, corner2).iterator();
|
||||
|
||||
World world = tile.getWorld();
|
||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
|
||||
while (itr.hasNext()) {
|
||||
BlockPos pos = itr.next();
|
||||
if (world.isAirBlock(pos)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
loop(pointer);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
TileEntity t = world.getTileEntity(pos);
|
||||
if (t == null || !nodeChecker.isNode(t)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
new Thread(() ->
|
||||
{
|
||||
World world = pointer.getWorld();
|
||||
|
||||
for (Coord4D coord : iteratedNodes) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, coord.x + random.nextDouble(), coord.y + -.01,
|
||||
coord.z + random.nextDouble(), 0, 0, 0);
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, coord.x + random.nextDouble(), coord.y + 1.01,
|
||||
coord.z + random.nextDouble(), 0, 0, 0);
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, coord.x + random.nextDouble(),
|
||||
coord.y + random.nextDouble(), coord.z + -.01, 0, 0, 0);
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, coord.x + random.nextDouble(),
|
||||
coord.y + random.nextDouble(), coord.z + 1.01, 0, 0, 0);
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, coord.x + -.01, coord.y + random.nextDouble(),
|
||||
coord.z + random.nextDouble(), 0, 0, 0);
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, coord.x + 1.01, coord.y + random.nextDouble(),
|
||||
coord.z + random.nextDouble(), 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public void loop(TileEntity tileEntity) {
|
||||
iteratedNodes.add(Coord4D.get(tileEntity));
|
||||
|
||||
for (EnumFacing side : EnumFacing.VALUES) {
|
||||
Coord4D coord = Coord4D.get(tileEntity).offset(side);
|
||||
|
||||
if (coord.exists(pointer.getWorld())) {
|
||||
TileEntity tile = coord.getTileEntity(pointer.getWorld());
|
||||
|
||||
if (tile != null && isNode(tile) && !iteratedNodes.contains(coord)) {
|
||||
loop(tile);
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + random.nextDouble(),
|
||||
pos.getY() + random.nextDouble(), pos.getZ() + -.01, 0, 0, 0);
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + random.nextDouble(),
|
||||
pos.getY() + random.nextDouble(), pos.getZ() + 1.01, 0, 0, 0);
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + -.01,
|
||||
pos.getY() + random.nextDouble(), pos.getZ() + random.nextDouble(), 0, 0, 0);
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + 1.01,
|
||||
pos.getY() + random.nextDouble(), pos.getZ() + random.nextDouble(), 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNode(TileEntity tile) {
|
||||
return nodeChecker.isNode(tile);
|
||||
}
|
||||
|
||||
public interface INodeChecker {
|
||||
|
||||
boolean isNode(TileEntity tile);
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,7 @@ import mekanism.common.inventory.container.robit.ContainerRobitMain;
|
||||
import mekanism.common.inventory.container.robit.ContainerRobitRepair;
|
||||
import mekanism.common.inventory.container.robit.ContainerRobitSmelting;
|
||||
import mekanism.common.item.ItemPortableTeleporter;
|
||||
import mekanism.common.multiblock.UpdateProtocol.NodeChecker;
|
||||
import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterMessage;
|
||||
import mekanism.common.tile.TileEntityChanceMachine;
|
||||
import mekanism.common.tile.TileEntityChemicalCrystallizer;
|
||||
@@ -511,16 +512,15 @@ public class CommonProxy implements IGuiProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a generic creation animation, starting from the rendering block.
|
||||
* Does the multiblock creation animation, starting from the rendering block.
|
||||
*/
|
||||
public void doGenericSparkle(TileEntity tileEntity, INodeChecker checker) {
|
||||
}
|
||||
public void doMultiblockSparkle(TileEntity tileEntity, BlockPos corner1, BlockPos corner2, INodeChecker checker) {}
|
||||
|
||||
/**
|
||||
* Does the multiblock creation animation, starting from the rendering block.
|
||||
*/
|
||||
public void doMultiblockSparkle(TileEntityMultiblock<?> tileEntity) {
|
||||
}
|
||||
public void doMultiblockSparkle(TileEntity tileEntity, BlockPos renderLoc, int length, int width, int height,
|
||||
INodeChecker checker) {}
|
||||
|
||||
@Override
|
||||
public Object getClientGui(int ID, EntityPlayer player, World world, BlockPos pos) {
|
||||
|
||||
@@ -79,7 +79,8 @@ public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extend
|
||||
|
||||
if (structure != null && clientHasStructure && isRendering) {
|
||||
if (!prevStructure) {
|
||||
Mekanism.proxy.doMultiblockSparkle(this);
|
||||
Mekanism.proxy.doMultiblockSparkle(this, structure.renderLocation.getPos(), structure.volLength,
|
||||
structure.volWidth, structure.volHeight, tile -> MultiblockManager.areEqual(this, tile));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,12 +26,15 @@ import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.TileUtils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumFacing.Axis;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
@@ -501,7 +504,13 @@ public class TileEntityThermalEvaporationController extends TileEntityThermalEva
|
||||
MekanismUtils.updateBlock(world, getPos());
|
||||
|
||||
if (structured) {
|
||||
Mekanism.proxy.doGenericSparkle(this, tile -> tile instanceof TileEntityThermalEvaporationBlock);
|
||||
// Calculate the two corners of the evap tower using the render location as basis (which is the
|
||||
// lowest rightmost corner inside the tower, relative to the controller).
|
||||
BlockPos corner1 = getRenderLocation().getPos().offset(facing).offset(facing.rotateYCCW()).down();
|
||||
BlockPos corner2 = corner1.offset(facing.getOpposite(), 3).offset(facing.rotateYCCW().getOpposite(), 3).up(height-1);
|
||||
// Use the corners to spin up the sparkle
|
||||
Mekanism.proxy.doMultiblockSparkle(this, corner1, corner2,
|
||||
tile -> tile instanceof TileEntityThermalEvaporationBlock);
|
||||
}
|
||||
|
||||
clientStructured = structured;
|
||||
|
||||
+6
-1
@@ -19,6 +19,7 @@ import mekanism.generators.common.FusionReactor;
|
||||
import mekanism.generators.common.item.ItemHohlraum;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.ISound;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -26,6 +27,8 @@ import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
@@ -257,7 +260,9 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
|
||||
|
||||
if (formed) {
|
||||
if (getReactor() == null || !getReactor().formed) {
|
||||
Mekanism.proxy.doGenericSparkle(this, tile -> tile instanceof TileEntityReactorBlock);
|
||||
BlockPos corner = getPos().subtract(new Vec3i(2, 4, 2));
|
||||
Mekanism.proxy.doMultiblockSparkle(this, corner, 5, 5, 6,
|
||||
tile -> tile instanceof TileEntityReactorBlock);
|
||||
}
|
||||
|
||||
if (getReactor() == null) {
|
||||
|
||||
Reference in new issue
Block a user