Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: apply workaround for @In malfunction in actions #102

Merged
merged 3 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions assets/prefabs/behaviorNodes/jump.prefab
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"BehaviorNode" : {
"action" : "jump",
"name" : "jump",
"displayName" : "Jump",
"category" : "moving",
"shape" : "rect",
"color" : [0.7, 0.7, 0.7, 255],
"description": "Trigger a single jump into the air.\nSUCCESS: when the actor is grounded after the jump again.",
"textColor" : [ 0, 0, 0, 255]
}
"BehaviorNode": {
"action": "jump",
"name": "jump",
"displayName": "Jump",
"category": "moving",
"shape": "rect",
"color": [0.7, 0.7, 0.7, 255],
"description": "Trigger a single jump into the air.\nSUCCESS: when the actor is grounded after the jump again.",
"textColor": [0, 0, 0, 255]
}
}
20 changes: 10 additions & 10 deletions assets/prefabs/behaviorNodes/setTargetLocalPlayer.prefab
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"BehaviorNode" : {
"action" : "set_target_local_player",
"name" : "set_target_local_player",
"displayName" : "Set Target To Local Player",
"category" : "moving",
"shape" : "rect",
"description": "Set MinionMoveComponent.target to the block below local player.\nAlways returns SUCCESS.",
"color" : [0.7, 0.7, 0.7, 255],
"textColor" : [ 0, 0, 0, 255]
}
"BehaviorNode": {
"action": "set_target_local_player",
"name": "set_target_local_player",
"displayName": "Set Target To Local Player",
"category": "moving",
"shape": "rect",
"description": "Set MinionMoveComponent.target to the block below local player.\nAlways returns SUCCESS.",
"color": [0.7, 0.7, 0.7, 255],
"textColor": [0, 0, 0, 255]
}
}
20 changes: 10 additions & 10 deletions assets/prefabs/behaviorNodes/setTargetToNearbyBlock.prefab
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"BehaviorNode" : {
"action" : "set_target_nearby_block",
"name" : "set_target_nearby_block",
"displayName" : "Set target to a random nearby block",
"category" : "moving",
"shape" : "rect",
"description": "Set MinionMoveComponent's target to a nearby block.\nReturns always SUCCESS",
"color" : [0.7, 0.7, 0.7, 255],
"textColor" : [ 0, 0, 0, 255]
}
"BehaviorNode": {
"action": "set_target_nearby_block",
"name": "set_target_nearby_block",
"displayName": "Set target to a random nearby block",
"category": "moving",
"shape": "rect",
"description": "Set MinionMoveComponent's target to a nearby block.\nReturns always SUCCESS",
"color": [0.7, 0.7, 0.7, 255],
"textColor": [0, 0, 0, 255]
}
}
30 changes: 15 additions & 15 deletions assets/prefabs/jobRemoveBlock.prefab
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"parent" : "engine:iconItem",
"parent": "engine:iconItem",
"DisplayName": {
"name": "Remove Block"
},
"Item" : {
"icon" : "engine:items#removeBlockJob",
"usage" : "ON_BLOCK"
},
"PlaySoundAction" : {
"sounds" : "engine:click"
},
"Work" : {
"workType" : "Behaviors:removeBlock"
},
"BlockSelection" : {
"shouldRender" : true
},
"OnItemActivateSelection" : {}
"Item": {
"icon": "engine:items#removeBlockJob",
"usage": "ON_BLOCK"
},
"PlaySoundAction": {
"sounds": "engine:click"
},
"Work": {
"workType": "Behaviors:removeBlock"
},
"BlockSelection": {
"shouldRender": true
},
"OnItemActivateSelection": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ private boolean isTargetEntityOutOfFollowDistance(Actor actor) {
if (locationComponent == null) {
return true;
}
if (locationComponent.getWorldPosition(new Vector3f()).distanceSquared(actorPosition) <= maxDistanceSquared) {
return false;
}
return true;
return !(locationComponent.getWorldPosition(new Vector3f()).distanceSquared(actorPosition) <= maxDistanceSquared);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ public class CheckNightAction extends BaseAction {

@Override
public void construct(Actor actor) {
// TODO: Temporary fix for injection malfunction in actions, ideally remove this in the future.
nightTrackerSystem = CoreRegistry.get(NightTrackerSystem.class);
// TODO: Temporary fix for injection malfunction in actions, remove as soon as injection malfunction in actions is fixed.
if (nightTrackerSystem == null) {
nightTrackerSystem = CoreRegistry.get(NightTrackerSystem.class);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class FindPathToNode extends BaseAction {

@Override
public void construct(Actor actor) {
// TODO: Temporary fix for injection malfunction in actions, remove as soon as injection malfunction in actions is fixed.
if (pathfinderSystem == null) {
pathfinderSystem = CoreRegistry.get(PathfinderSystem.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.google.common.collect.Lists;
import org.joml.Vector3f;
import org.terasology.engine.registry.CoreRegistry;
import org.terasology.module.behaviors.components.FollowComponent;
import org.terasology.engine.entitySystem.entity.EntityManager;
import org.terasology.engine.entitySystem.entity.EntityRef;
Expand All @@ -15,6 +16,7 @@
import org.terasology.engine.logic.location.LocationComponent;
import org.terasology.engine.network.ClientComponent;
import org.terasology.engine.registry.In;
import org.terasology.module.behaviors.systems.PluginSystem;
import org.terasology.nui.properties.Range;

import java.util.List;
Expand All @@ -28,6 +30,14 @@ public class FollowPlayerWithinRangeAction extends BaseAction {
@In
private EntityManager entityManager;

@Override
public void construct(Actor actor) {
// TODO: Temporary fix for injection malfunction in actions, remove as soon as injection malfunction in actions is fixed.
if (entityManager == null) {
entityManager = CoreRegistry.get(EntityManager.class);
}
}

@Override
public BehaviorState modify(Actor actor, BehaviorState result) {
LocationComponent actorLocationComponent = actor.getComponent(LocationComponent.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ public class MoveToAction extends BaseAction {

@Override
public void construct(Actor actor) {
// TODO: Temporary fix for injection malfunction in actions, remove as soon as injection malfunction in actions is fixed.
if (time == null) {
time = CoreRegistry.get(Time.class);
}
if (world == null) {
world = CoreRegistry.get(WorldProvider.class);
}
if (pluginSystem == null) {
pluginSystem = CoreRegistry.get(PluginSystem.class);
}

MinionMoveComponent minionMoveComponent = actor.getComponent(MinionMoveComponent.class);
minionMoveComponent.sequenceNumber = 0;
actor.save(minionMoveComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.terasology.engine.logic.behavior.core.BaseAction;
import org.terasology.engine.logic.behavior.core.BehaviorState;
import org.terasology.engine.logic.location.LocationComponent;
import org.terasology.engine.registry.CoreRegistry;
import org.terasology.engine.registry.In;
import org.terasology.engine.world.block.BlockArea;
import org.terasology.engine.world.block.BlockRegion;
Expand Down Expand Up @@ -52,6 +53,11 @@ public class NearbyBlockRestricted extends BaseAction {

@Override
public void construct(Actor actor) {
// TODO: Temporary fix for injection malfunction in actions, remove as soon as injection malfunction in actions is fixed.
if (movementPluginSystem == null) {
movementPluginSystem = CoreRegistry.get(PluginSystem.class);
}

if (!actor.hasComponent(StrayRestrictionComponent.class)) {
logger.warn("Actor used behavior node set_target_nearby_block_restricted, but doesn't have a StrayRestrictionComponent!");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
package org.terasology.module.behaviors.actions;

import org.terasology.engine.registry.CoreRegistry;
import org.terasology.gestalt.assets.ResourceUrn;
import org.terasology.gestalt.assets.management.AssetManager;
import org.terasology.engine.audio.AudioEndListener;
Expand All @@ -13,6 +14,7 @@
import org.terasology.engine.logic.behavior.core.BehaviorState;
import org.terasology.engine.registry.In;
import org.terasology.gestalt.module.sandbox.API;
import org.terasology.module.behaviors.systems.PluginSystem;
import org.terasology.nui.properties.OneOf;
import org.terasology.nui.properties.Range;

Expand All @@ -33,8 +35,15 @@ public class PlayMusicAction extends BaseAction {

@Override
public void construct(Actor actor) {
if (musicUrn != null) {
// TODO: Temporary fix for injection malfunction in actions, remove as soon as injection malfunction in actions is fixed.
if (audioManager == null) {
audioManager = CoreRegistry.get(AudioManager.class);
}
if (assetManager == null) {
assetManager = CoreRegistry.get(AssetManager.class);
}

if (musicUrn != null) {
StreamingSound snd = assetManager.getAsset(musicUrn, StreamingSound.class).orElse(null);

if (snd != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package org.terasology.module.behaviors.actions;

import org.joml.Vector3f;
import org.terasology.engine.registry.CoreRegistry;
import org.terasology.gestalt.assets.ResourceUrn;
import org.terasology.gestalt.assets.management.AssetManager;
import org.terasology.engine.audio.AudioEndListener;
Expand Down Expand Up @@ -36,11 +37,17 @@ public class PlaySoundAction extends BaseAction {

@Override
public void construct(Actor actor) {
if (soundUrn != null) {
// TODO: Temporary fix for injection malfunction in actions, remove as soon as injection malfunction in actions is fixed.
if (audioManager == null) {
audioManager = CoreRegistry.get(AudioManager.class);
}
if (assetManager == null) {
assetManager = CoreRegistry.get(AssetManager.class);
}

if (soundUrn != null) {
StaticSound snd = assetManager.getAsset(soundUrn, StaticSound.class).orElse(null);


if (snd != null) {
if (actor.hasComponent(LocationComponent.class)) {
Vector3f worldPosition = actor.getComponent(LocationComponent.class).getWorldPosition(new Vector3f());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class SetTargetToNearbyBlockAwayFromInstigatorAction extends BaseAction {

@Override
public void construct(Actor actor) {
// TODO: Temporary fix for injection malfunction in actions, remove as soon as injection malfunction in actions is fixed.
if (movementPluginSystem == null) {
movementPluginSystem = CoreRegistry.get(PluginSystem.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class SetTargetToNearbyBlockNode extends BaseAction {

@Override
public void construct(Actor actor) {
// TODO: Temporary fix for injection malfunction in actions, remove as soon as injection malfunction in actions is fixed.
if (movementPluginSystem == null) {
movementPluginSystem = CoreRegistry.get(PluginSystem.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
package org.terasology.module.behaviors.actions;

import org.terasology.engine.registry.CoreRegistry;
import org.terasology.module.behaviors.components.AttackOnHitComponent;
import org.terasology.module.behaviors.components.FindNearbyPlayersComponent;
import org.terasology.module.behaviors.components.FollowComponent;
Expand All @@ -11,12 +12,21 @@
import org.terasology.engine.logic.behavior.core.BaseAction;
import org.terasology.engine.logic.behavior.core.BehaviorState;
import org.terasology.engine.registry.In;
import org.terasology.module.behaviors.systems.PluginSystem;

@BehaviorAction(name = "set_target_nearby_player")
public class SetTargetToNearbyPlayer extends BaseAction {
@In
private Time time;

@Override
public void construct(Actor actor) {
// TODO: Temporary fix for injection malfunction in actions, remove as soon as injection malfunction in actions is fixed.
if (time == null) {
time = CoreRegistry.get(Time.class);
}
}

@Override
public BehaviorState modify(Actor actor, BehaviorState result) {
if (!actor.hasComponent(AttackOnHitComponent.class) || !actor.hasComponent(FindNearbyPlayersComponent.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.terasology.engine.logic.behavior.core.Actor;
import org.terasology.engine.logic.behavior.core.BaseAction;
import org.terasology.engine.logic.behavior.core.BehaviorState;
import org.terasology.engine.registry.CoreRegistry;
import org.terasology.engine.registry.In;
import org.terasology.flexiblepathfinding.PathfinderSystem;
import org.terasology.flexiblepathfinding.plugins.JPSPlugin;
Expand All @@ -17,7 +18,7 @@
import java.util.List;

/**
* Validates the entity's current path for walkability (according to the pathfinding plugin its using)
* Validates the entity's current path for walkability (according to the pathfinding plugin it's using)
* <p>
* SUCCESS: when there are no unwalkable waypoints
* <p>
Expand All @@ -35,6 +36,14 @@ public class ValidatePath extends BaseAction {
@In
private MinionMoveSystem minionMoveSystem;

@Override
public void construct(Actor actor) {
// TODO: Temporary fix for injection malfunction in actions, remove as soon as injection malfunction in actions is fixed.
if (pluginSystem == null) {
pluginSystem = CoreRegistry.get(PluginSystem.class);
}
}

@Override
public BehaviorState modify(Actor actor, BehaviorState result) {

Expand Down