Skip to content

Commit

Permalink
Update 922
Browse files Browse the repository at this point in the history
  • Loading branch information
ReikaKalseki committed Jul 2, 2020
1 parent ddeaaba commit a18df6c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
2 changes: 1 addition & 1 deletion ChromatiPackets.java
Expand Up @@ -992,7 +992,7 @@ public void handleData(PacketObj packet, World world, EntityPlayer ep) {
((TileEntityRouterHub)tile).addHighlight(new Coordinate(data[0], data[1], data[2]));
break;
case STRUCTFIND: {
ItemStructureFinder.doHeldFX(ep, dx, dy, dz, ChromaStructures.structureList[data[0]], data[1] > 0);
ItemStructureFinder.doHeldFX(ep, dx, dy, dz, ChromaStructures.structureList[data[0]], data[1] > 0, data[2] > 0);
break;
}
case DATASCAN:
Expand Down
45 changes: 26 additions & 19 deletions Items/Tools/Powered/ItemStructureFinder.java
Expand Up @@ -13,7 +13,6 @@
import java.util.Random;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
Expand All @@ -30,16 +29,16 @@
import Reika.ChromatiCraft.Registry.ExtraChromaIDs;
import Reika.ChromatiCraft.Render.Particle.EntityBlurFX;
import Reika.ChromatiCraft.World.IWG.DungeonGenerator;
import Reika.ChromatiCraft.World.IWG.DungeonGenerator.StructureSeekData;
import Reika.DragonAPI.DragonAPICore;
import Reika.DragonAPI.Auxiliary.Trackers.KeyWatcher;
import Reika.DragonAPI.Auxiliary.Trackers.KeyWatcher.Key;
import Reika.DragonAPI.Instantiable.Data.Immutable.WorldLocation;
import Reika.DragonAPI.Instantiable.Formula.MathExpression;
import Reika.DragonAPI.Instantiable.Formula.PeriodicExpression;
import Reika.DragonAPI.Instantiable.IO.PacketTarget;
import Reika.DragonAPI.Instantiable.ParticleController.FlashColorController;
import Reika.DragonAPI.Libraries.ReikaPlayerAPI;
import Reika.DragonAPI.Libraries.IO.ReikaChatHelper;
import Reika.DragonAPI.Libraries.IO.ReikaColorAPI;
import Reika.DragonAPI.Libraries.IO.ReikaPacketHelper;
import Reika.DragonAPI.Libraries.Java.ReikaObfuscationHelper;
import Reika.DragonAPI.Libraries.Java.ReikaRandomHelper;
Expand Down Expand Up @@ -84,42 +83,40 @@ public boolean doTick(ItemStack is, World world, EntityPlayer e, boolean held) {

int type = this.getStructureType(is);
if (world.provider.dimensionId == ExtraChromaIDs.DIMID.getValue()) {
this.sendParticle(e, e.posX, -50, e.posZ, TYPES[type], false);
this.sendParticle(e, e.posX, -50, e.posZ, TYPES[type], false, true);
return false;
}

WorldLocation loc = DungeonGenerator.instance.getNearestRealStructure(TYPES[type], (WorldServer)world, e.posX, e.posZ, RANGE, false);
StructureSeekData loc = DungeonGenerator.instance.getNearestRealStructure(TYPES[type], (WorldServer)world, e.posX, e.posZ, RANGE, false);
if (loc != null) {
double dist = loc.getDistanceTo(e);
double dist = loc.location.getDistanceTo(e);
double fz = ReikaObfuscationHelper.isDeObfEnvironment() && KeyWatcher.instance.isKeyDown(e, Key.LCTRL) && ReikaPlayerAPI.isReika(e) ? 0 : FUZZ;
if (dist <= fz) {
double px = ReikaRandomHelper.getRandomPlusMinus(e.posX, fz);
double py = ReikaRandomHelper.getRandomPlusMinus(e.posY, fz);
double pz = ReikaRandomHelper.getRandomPlusMinus(e.posZ, fz);
this.sendParticle(e, px, py, pz, TYPES[type], true);
this.sendParticle(e, px, py, pz, TYPES[type], true, loc.isKnownSuccess);
}
else {
double px = ReikaRandomHelper.getRandomPlusMinus(loc.xCoord+0.5, fz);
double px = ReikaRandomHelper.getRandomPlusMinus(loc.location.xCoord+0.5, fz);
double py = ReikaRandomHelper.getRandomPlusMinus(e.posY, fz);
double pz = ReikaRandomHelper.getRandomPlusMinus(loc.zCoord+0.5, fz);
this.sendParticle(e, px, py, pz, TYPES[type], false);
double pz = ReikaRandomHelper.getRandomPlusMinus(loc.location.zCoord+0.5, fz);
this.sendParticle(e, px, py, pz, TYPES[type], false, loc.isKnownSuccess);
}
}
}
return true;
}

private void sendParticle(EntityPlayer ep, double sx, double sy, double sz, ChromaStructures s, boolean close) {
private void sendParticle(EntityPlayer ep, double sx, double sy, double sz, ChromaStructures s, boolean close, boolean genned) {
if (ep instanceof EntityPlayerMP) {
PacketTarget pt = new PacketTarget.PlayerTarget((EntityPlayerMP)ep);
ReikaPacketHelper.sendPositionPacket(ChromatiCraft.packetChannel, ChromaPackets.STRUCTFIND.ordinal(), ep.worldObj, sx, sy, sz, pt, s.ordinal(), close ? 1 : 0);
ReikaPacketHelper.sendPositionPacket(ChromatiCraft.packetChannel, ChromaPackets.STRUCTFIND.ordinal(), ep.worldObj, sx, sy, sz, pt, s.ordinal(), close ? 1 : 0, genned ? 1 : 0);
}
}

@SideOnly(Side.CLIENT)
public static void doHeldFX(EntityPlayer ep, double sx, double sy, double sz, ChromaStructures s, boolean close) {
if (GuiScreen.isCtrlKeyDown() && rand.nextInt(20) == 0)
ReikaChatHelper.write(sx+", "+sz);
public static void doHeldFX(EntityPlayer ep, double sx, double sy, double sz, ChromaStructures s, boolean close, boolean genned) {
double[] xyz = ReikaPhysicsHelper.polarToCartesian(0.0625, -ep.rotationPitch, ep.rotationYawHead+90+60);
double px = ep.posX+xyz[0];
double py = ep.posY+xyz[1];
Expand All @@ -129,12 +126,20 @@ public static void doHeldFX(EntityPlayer ep, double sx, double sy, double sz, Ch
double dz = sz-pz;
double dd = ReikaMathLibrary.py3d(dx, dy, dz);
double v = 0.03125/2;
double vx = dx/dd*v;
double vy = dy/dd*v;
double vz = dz/dd*v;
float sc = 0.125F+rand.nextFloat()*0.25F;
int l = 10;
int c = COLORS[s.ordinal()];
if (!genned) {
if (ep.getRNG().nextInt(3) == 0)
return;
c = ReikaColorAPI.getColorWithBrightnessMultiplier(c, 0.5F);
l = 15;
sc *= 1.25;
v *= 0.67;
}
double vx = dx/dd*v;
double vy = dy/dd*v;
double vz = dz/dd*v;
EntityBlurFX fx = new EntityBlurFX(ep.worldObj, px, py, pz, vx, vy, vz);
if (close) {
l *= 2;
Expand All @@ -147,7 +152,9 @@ public static void doHeldFX(EntityPlayer ep, double sx, double sy, double sz, Ch
fx.motionY *= 0.375;
fx.motionZ *= 0.375;
}
fx.setLife(10).setScale(sc).setColor(c);
if (!genned)
fx.setIcon(ChromaIcons.FADE_GENTLE);
fx.setLife(l).setScale(sc).setColor(c);
if (sy == -50) {
fx.setLife(40+rand.nextInt(21));
fx.setColliding();
Expand Down
2 changes: 1 addition & 1 deletion Registry/ChromaPackets.java
Expand Up @@ -169,7 +169,7 @@ public enum ChromaPackets {
RELAYFILTER(2),
ROUTERFILTERFLAG(1),
ROUTERLINK(3),
STRUCTFIND(2),
STRUCTFIND(3),
DATASCAN(),
LORENOTE(1),
LOREPUZZLECOMPLETE(),
Expand Down
22 changes: 20 additions & 2 deletions World/IWG/DungeonGenerator.java
Expand Up @@ -166,7 +166,7 @@ private WorldLocation getNearestZone(ChromaStructures s, WorldServer world, doub
}

/** Block coords! */
public WorldLocation getNearestRealStructure(ChromaStructures s, WorldServer world, double x, double z, double r, boolean requireGenned) {
public StructureSeekData getNearestRealStructure(ChromaStructures s, WorldServer world, double x, double z, double r, boolean requireGenned) {
this.updateNoisemaps(world);
WorldLocation src = new WorldLocation(world, x, 0, z);
TileEntityCache<StructureGenData> cache = structureMap.get(s);
Expand All @@ -183,7 +183,9 @@ else if (requireGenned && !stat.isGenerated())
else if (stat == StructureGenStatus.INERT || stat == StructureGenStatus.INERT_GEN)
it.remove();
}
boolean genned = true;
if (!requireGenned && li.isEmpty()) { //no generated valid, consult noise
genned = false;
Collection<DecimalPosition> li2 = structs.get(s).getCellsWithin2D(x, z, r);
Iterator<DecimalPosition> it2 = li2.iterator();
while (it2.hasNext()) {
Expand All @@ -195,6 +197,8 @@ else if (requireGenned && !stat.isGenerated())
it2.remove();
else if (stat == StructureGenStatus.INERT || stat == StructureGenStatus.INERT_GEN)
it2.remove();
else if (!isValidBiomeNear(world, MathHelper.floor_double(loc.xCoord), MathHelper.floor_double(loc.zCoord), s))
it2.remove();
}
if (li2.isEmpty())
return null;
Expand All @@ -213,7 +217,7 @@ else if (stat == StructureGenStatus.INERT || stat == StructureGenStatus.INERT_GE
closest = loc;
}
}
return closest;
return new StructureSeekData(closest, genned);
}

/** In BLOCK coords */
Expand All @@ -223,6 +227,8 @@ public StructureGenStatus getGenStatus(ChromaStructures s, WorldServer world, in
StructureGenStatus def = gennable ? StructureGenStatus.PLANNED : StructureGenStatus.INERT;
if (def == StructureGenStatus.INERT && genned)
def = StructureGenStatus.INERT_GEN;
if (def == StructureGenStatus.PLANNED && !isValidBiomeNear(world, x, z, s))
def = StructureGenStatus.FAILURE;
Collection<WorldLocation> c = this.getNearbyZones(s, world, x, z, 32);
HashMap<WorldChunk, StructureGenStatus> cache = this.getStatusCache(s);
for (WorldLocation loc : c) {
Expand Down Expand Up @@ -1241,4 +1247,16 @@ public NBTTagCompound writeToNBT() {

}

public static class StructureSeekData {

public final WorldLocation location;
public final boolean isKnownSuccess;

private StructureSeekData(WorldLocation loc, boolean b) {
location = loc;
isKnownSuccess = b;
}

}

}

0 comments on commit a18df6c

Please sign in to comment.