Skip to content

Commit

Permalink
fix dummy move through walls during respawn
Browse files Browse the repository at this point in the history
  • Loading branch information
JaylyDev committed Jun 2, 2024
1 parent c924246 commit c32dc90
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 91 deletions.
20 changes: 0 additions & 20 deletions assets/behavior_pack/entities/dummy.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,6 @@
"add": {
"component_groups": ["dummy:force_spawn_entity"]
}
},
"dummy:request_spawning_steve": {
"set_property": {
"dummy:task_type": 1
}
},
"dummy:request_pathfind": {
"set_property": {
"dummy:task_type": 2
}
},
"dummy:request_spawning_alex": {
"set_property": {
"dummy:task_type": 3
}
},
"dummy:request_spawning_custom": {
"set_property": {
"dummy:task_type": 4
}
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/debug/statsDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ export function onHealthDebug(enabled: boolean) {
objective: healthObjective,
});
runId = system.runInterval(() => {
const terminators = overworld.getEntities({
for (const terminator of overworld.getEntities({
type: "entity:terminator",
});
for (const terminator of terminators) {
})) {
const health = terminator.getComponent(
EntityHealthComponent.componentId
) as EntityHealthComponent;
Expand Down
26 changes: 26 additions & 0 deletions src/dummyEntity/dummyEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { world, system, Vector3 } from "@minecraft/server";
import { MinecraftDimensionTypes } from "@minecraft/vanilla-data";

export enum TaskType {
SpawnSteve = 1,
PathFind,
SpawnAlex,
SpawnCustom,
}

const overworld = world.getDimension("overworld");

system.runInterval(() => {
for (const dummyEntity of overworld.getEntities({ type: "entity:dummy" })) {
const spawnLocation = dummyEntity.getDynamicProperty(
"dummy:spawn_location"
) as Vector3 | undefined;
const spawnDimension = dummyEntity.getDynamicProperty(
"dummy:spawn_dimension"
) as MinecraftDimensionTypes | undefined;
if (!spawnLocation || !spawnDimension) continue;
dummyEntity.teleport(spawnLocation, {
dimension: world.getDimension(spawnDimension),
});
}
});
10 changes: 10 additions & 0 deletions src/dummyEntity/navigationDetect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Entity, system, world } from "@minecraft/server";
import { terminatorDie } from "../terminator-events/onTerminatorDie";
import { debugEnabled } from "../config";
import { Vector3Utils } from "@minecraft/math";

const overworld = world.getDimension("overworld");

Expand All @@ -20,6 +22,12 @@ system.runInterval(() => {
maxDistance: 8,
})
) {
if (debugEnabled)
console.warn(
`Terminator navigated to location (${Vector3Utils.toString(
dummyEntity.location
)})`
);
dummyEntity.remove();
terminator.triggerEvent("terminator:remove_escape");
}
Expand All @@ -35,4 +43,6 @@ terminatorDie.subscribe(({ deadEntity }) => {
entity.getDynamicProperty("terminator:navigator") === deadEntity.id
);
dummyEntity?.remove();
if (debugEnabled)
console.warn(`Terminator (id: ${deadEntity.id}) died during navigation.`);
});
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import "./terminator/ridingTransport";
import "./terminator-death/index";
import "./terminator/suffocation";
import "./terminator/rangedAttack";
import "./terminator/escapeFromDanger";
import "./commands/index";
import "./guide/index";
import "./dummyEntity/navigationDetect";
import "./dummyEntity/dummyEntity";

// Debug Features
if (debugEnabled) {
Expand Down
12 changes: 9 additions & 3 deletions src/terminator-death/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { terminatorDie } from "../terminator-events/onTerminatorDie";
import { sendDeathMessageCallback } from "./deathMessage";
import { MinecraftColor } from "../minecraft-color";
import { dropEntityInventory } from "./dropInventory";
import { TaskType } from "../dummyEntity/dummyEntity";

enum TerminatorVariant {
SteveDefault = 0,
Expand Down Expand Up @@ -44,12 +45,17 @@ terminatorDie.subscribe((event) => {
deadEntity.location
);
dummyEntity.runCommand("fog @a remove respawn_lore");
dummyEntity.setDynamicProperty("dummy:spawn_location", deadEntity.location);
dummyEntity.setDynamicProperty(
"dummy:spawn_dimension",
deadEntity.dimension.id
);
if (isSteveVariant)
dummyEntity.triggerEvent("dummy:request_spawning_steve");
dummyEntity.setProperty("dummy:task_type", TaskType.SpawnSteve);
else if (isAlexVariant)
dummyEntity.triggerEvent("dummy:request_spawning_alex");
dummyEntity.setProperty("dummy:task_type", TaskType.SpawnAlex);
else if (isCustomVariant)
dummyEntity.triggerEvent("dummy:request_spawning_custom");
dummyEntity.setProperty("dummy:task_type", TaskType.SpawnCustom);
}
// Second Death
else if (
Expand Down
67 changes: 67 additions & 0 deletions src/terminator/escapeFromDanger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {
EntityHealthComponent,
TicksPerSecond,
system,
world,
} from "@minecraft/server";
import { MinecraftEffectTypes } from "@minecraft/vanilla-data";
import { debugEnabled } from "../config";
import { getSpreadLocation } from "../dummyEntity/spreadDummies";
import { TerminatorEntity } from "./terminator";

const overworld = world.getDimension("overworld");

// detect when terminator's health is below 20hp (max 60hp)
system.runInterval(() => {
for (const entity of overworld.getEntities({ type: "entity:terminator" })) {
const health = entity.getComponent("health") as EntityHealthComponent;
const dangerEscapeTriggered =
(entity.getDynamicProperty("terminator:escape_triggered") as
| boolean
| undefined) ?? false;

if (!health.isValid() || dangerEscapeTriggered) continue;
if (
health.currentValue < 20 &&
!entity.hasTag("terminatorNoRegeneration")
) {
entity.addEffect(MinecraftEffectTypes.Regeneration, 6 * TicksPerSecond, {
amplifier: 4,
showParticles: false,
});
entity.addEffect(MinecraftEffectTypes.Absorption, 24 * TicksPerSecond, {
amplifier: 3,
showParticles: false,
});
entity.addEffect(MinecraftEffectTypes.Resistance, 60 * TicksPerSecond, {
amplifier: 0,
showParticles: false,
});
entity.addEffect(
MinecraftEffectTypes.FireResistance,
60 * TicksPerSecond,
{
amplifier: 0,
showParticles: false,
}
);

// Trigger terminator to pathfind to a random location within 32-48 block radius
const terminator = new TerminatorEntity(entity);
const locationOffsetXZ = {
x: Math.floor(Math.random() * 32 - 17 + terminator.location.x),
z: Math.floor(Math.random() * 32 - 17 + terminator.location.z),
};
const locationOffset = getSpreadLocation(
locationOffsetXZ,
entity.dimension
);
if (debugEnabled)
terminator.chat(
`I'm going to ${locationOffset.x}, ${locationOffset.y}, ${locationOffset.z}!`
);
terminator.navigateToLocation(locationOffset);
terminator.setDynamicProperty("terminator:escape_triggered", true);
}
}
});
65 changes: 1 addition & 64 deletions src/terminator/initialization.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import {
EntityHealthComponent,
RawText,
TicksPerSecond,
system,
world,
} from "@minecraft/server";
import { RawText, system, world } from "@minecraft/server";
import { terminatorSpawn } from "../terminator-events/onTerminatorSpawn";
import { MinecraftEffectTypes } from "@minecraft/vanilla-data";
import { MinecraftColor } from "../minecraft-color";
import { TerminatorEntity } from "./terminator";
import { getSpreadLocation } from "../dummyEntity/spreadDummies";
import { debugEnabled } from "../config";

// naming tag
terminatorSpawn.subscribe(({ entity }) => {
Expand Down Expand Up @@ -44,56 +34,3 @@ terminatorSpawn.subscribe(({ entity }) => {
world.playSound("mob.terminator.spawn", entity.location);
}, 2);
});

// detect when terminator's health is below 20hp (max 60hp)
terminatorSpawn.subscribe(({ entity }) => {
const health = entity.getComponent("health") as EntityHealthComponent;
let triggered = false;

const id = system.runInterval(() => {
if (!health.isValid() || triggered) {
system.clearRun(id);
return;
}
if (
health.currentValue < 20 &&
!entity.hasTag("terminatorNoRegeneration")
) {
entity.addEffect(MinecraftEffectTypes.Regeneration, 6 * TicksPerSecond, {
amplifier: 4,
showParticles: false,
});
entity.addEffect(MinecraftEffectTypes.Absorption, 24 * TicksPerSecond, {
amplifier: 3,
showParticles: false,
});
entity.addEffect(MinecraftEffectTypes.Resistance, 60 * TicksPerSecond, {
amplifier: 0,
showParticles: false,
});
entity.addEffect(
MinecraftEffectTypes.FireResistance,
60 * TicksPerSecond,
{
amplifier: 0,
showParticles: false,
}
);

// Trigger terminator to pathfind to a random location within 32-48 block radius
const terminator = new TerminatorEntity(entity);
const locationOffsetXZ = {
x: Math.floor(Math.random() * 32 - 17 + terminator.location.x),
z: Math.floor(Math.random() * 32 - 17 + terminator.location.z),
};
const locationOffset = getSpreadLocation(
locationOffsetXZ,
entity.dimension
);
if (debugEnabled) terminator.chat(`I'm going to ${locationOffset.x}, ${locationOffset.y}, ${locationOffset.z}!`);
terminator.navigateToLocation(locationOffset);

triggered = true;
}
});
});
3 changes: 2 additions & 1 deletion src/terminator/terminator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
UnbreakableBlocks,
} from "../config";
import { MinecraftColor } from "../minecraft-color";
import { TaskType } from "../dummyEntity/dummyEntity";

/**
* Represents the state of a terminator entity in the world.
Expand Down Expand Up @@ -377,7 +378,7 @@ export class TerminatorEntity implements Entity {
*/
navigateToLocation(location: Vector3): void {
const dummyEntity = this.dimension.spawnEntity("entity:dummy", location);
dummyEntity.triggerEvent("dummy:request_pathfind");
dummyEntity.setProperty("dummy:task_type", TaskType.PathFind);
dummyEntity.setDynamicProperty("terminator:navigator", this.id);
this.triggerEvent("terminator:escape");
}
Expand Down

0 comments on commit c32dc90

Please sign in to comment.