Skip to content

Commit

Permalink
add visualize projectile logger
Browse files Browse the repository at this point in the history
  • Loading branch information
kafuuchino-desu committed Aug 26, 2019
1 parent b1a77ab commit 450d4d1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
4 changes: 2 additions & 2 deletions patches/net/minecraft/entity/item/EntityEnderPearl.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
+ if (LoggerRegistry.__projectiles && this.logHelper != null)
+ {
+ if (result.type == RayTraceResult.Type.BLOCK) {
+ this.logHelper.onCollide(result.hitVec.x, result.hitVec.y, result.hitVec.z, "Block");
+ this.logHelper.onCollide(result.hitVec.x, result.hitVec.y, result.hitVec.z, "Block", this.world);
+ }
+ else {
+ this.logHelper.onCollide(result.hitVec.x, result.hitVec.y, result.hitVec.z, "Entity");
+ this.logHelper.onCollide(result.hitVec.x, result.hitVec.y, result.hitVec.z, "Entity", this.world);
+ }
+ }
+ //END TISCM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
+ if (LoggerRegistry.__projectiles && this.logHelper != null)
+ {
+ if (result.type == RayTraceResult.Type.BLOCK) {
+ this.logHelper.onCollide(result.hitVec.x, result.hitVec.y, result.hitVec.z, "Block");
+ this.logHelper.onCollide(result.hitVec.x, result.hitVec.y, result.hitVec.z, "Block", this.world);
+ }
+ else {
+ this.logHelper.onCollide(result.hitVec.x, result.hitVec.y, result.hitVec.z, "Entity");
+ this.logHelper.onCollide(result.hitVec.x, result.hitVec.y, result.hitVec.z, "Entity", this.world);
+ }
+ }
+ //END TISCM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
+ if (LoggerRegistry.__projectiles && this.logHelper != null)
+ {
+ if (result.type == RayTraceResult.Type.BLOCK) {
+ this.logHelper.onCollide(result.hitVec.x, result.hitVec.y, result.hitVec.z, "Block");
+ this.logHelper.onCollide(result.hitVec.x, result.hitVec.y, result.hitVec.z, "Block", this.world);
+ }
+ else {
+ this.logHelper.onCollide(result.hitVec.x, result.hitVec.y, result.hitVec.z, "Entity");
+ this.logHelper.onCollide(result.hitVec.x, result.hitVec.y, result.hitVec.z, "Entity", this.world);
+ }
+ }
+ //END TISCM
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/carpet/logging/LoggerRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class LoggerRegistry
public static void initLoggers()
{
registerLogger("tnt", new Logger("tnt", "brief", new String[]{"brief", "full"}));
registerLogger("projectiles", new Logger("projectiles", "brief", new String[]{"brief", "full"}));
registerLogger("projectiles", new Logger("projectiles", "brief", new String[]{"brief", "full", "visualize"}));
registerLogger("fallingBlocks",new Logger("fallingBlocks", "brief", new String[]{"brief", "full"}));
registerLogger("kills", new Logger("kills", null, null));
registerLogger("damage", new Logger("damage", "all", new String[]{"all","players","me"}));
Expand Down
38 changes: 35 additions & 3 deletions src/main/java/carpet/logging/logHelpers/TrajectoryLogHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import carpet.logging.Logger;
import carpet.logging.LoggerRegistry;
import carpet.utils.Messenger;
import net.minecraft.entity.Entity;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -22,7 +26,8 @@ public class TrajectoryLogHelper
private ArrayList<Vec3d> positions = new ArrayList<>();
private ArrayList<Vec3d> motions = new ArrayList<>();
private ArrayList<String> collide = new ArrayList<>();
private String hitType = new String();
private String hitType;
private World world;

public TrajectoryLogHelper(String logName)
{
Expand All @@ -38,13 +43,21 @@ public void onTick(double x, double y, double z, double motionX, double motionY,
collide.add("f");
}

public void onCollide(double x, double y, double z, String type)
public void onCollide(double x, double y, double z, String type, World worldIn)
{
if (!doLog) return;
positions.add(new Vec3d(x, y, z));
motions.add(new Vec3d(0,0,0));
collide.add("t");
this.hitType = type;
hitType = type;
world = worldIn;

for (int i = 0; i < worldIn.loadedEntityList.size(); ++i){
Entity checkentity = worldIn.loadedEntityList.get(i);
if (checkentity.getTags().contains("TISCM_VISPROJ_LOGGER")){
worldIn.removeEntity(checkentity);
}
}
}

public void onFinish()
Expand Down Expand Up @@ -90,6 +103,25 @@ public void onFinish()
"w mot",Messenger.dblt("w",mot.x, mot.y, mot.z)));
}
break;
case "visualize":
comp.add(Messenger.c("w visualize logger: visualized " + (positions.size()-1) + " tick(s)"));
for (int i = 0; i < positions.size(); i++)
{
Vec3d pos = positions.get(i);
EntitySnowball visEntity = new EntitySnowball(world, pos.x, pos.y, pos.z);
visEntity.setNoGravity(true);
if (i < positions.size() - 1) {
visEntity.setCustomName(new TextComponentString(i + ""));
}
else {
visEntity.setCustomName(new TextComponentString("Hit"));
}
visEntity.setCustomNameVisible(true);
visEntity.addTag("TISCM_VISPROJ_LOGGER");
visEntity.logHelper = null;
world.spawnEntity(visEntity);
}
break;
}
return comp.toArray(new ITextComponent[0]);
});
Expand Down

0 comments on commit 450d4d1

Please sign in to comment.