Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.blockdetector.internal;

import com.google.common.collect.Sets;
import org.terasology.audio.AudioManager;
import org.terasology.blockdetector.systems.BlockDetectorSystem;
import org.terasology.blockdetector.utilities.DetectorData;
import org.terasology.blockdetector.utilities.LinearAudioDetectorImpl;
import org.terasology.entitySystem.systems.BaseComponentSystem;
import org.terasology.entitySystem.systems.RegisterSystem;
import org.terasology.math.Region3i;
import org.terasology.engine.audio.AudioManager;
import org.terasology.engine.entitySystem.systems.BaseComponentSystem;
import org.terasology.engine.entitySystem.systems.RegisterSystem;
import org.terasology.engine.math.Region3i;
import org.terasology.engine.registry.In;
import org.terasology.math.geom.Vector3i;
import org.terasology.registry.In;

/**
* A detector for caves, i.e. air located below the player.
Expand All @@ -42,7 +29,8 @@ public class CaveDetectorSystem extends BaseComponentSystem {
@Override
public void initialise() {
Region3i range = Region3i.createFromMinMax(new Vector3i(-1, -55, -1), new Vector3i(1, -5, 1));
data = new LinearAudioDetectorImpl("BlockDetector:caveDetector", Sets.newHashSet("engine:air"), range, audioManager, "BlockDetector:ScannerBeep", 250, 1000);
data = new LinearAudioDetectorImpl("BlockDetector:caveDetector", Sets.newHashSet("engine:air"), range,
audioManager, "BlockDetector:ScannerBeep", 250, 1000);

Region3i nonAerialRange = Region3i.createFromMinMax(new Vector3i(-3, -3, -3), new Vector3i(3, 3, 3));
data.setNonAerialRange(nonAerialRange);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.blockdetector.internal;

import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.audio.AudioManager;
import org.terasology.blockdetector.systems.BlockDetectorSystem;
import org.terasology.blockdetector.utilities.DetectorData;
import org.terasology.blockdetector.utilities.LinearAudioDetectorImpl;
import org.terasology.entitySystem.systems.BaseComponentSystem;
import org.terasology.entitySystem.systems.RegisterSystem;
import org.terasology.math.Region3i;
import org.terasology.engine.audio.AudioManager;
import org.terasology.engine.entitySystem.systems.BaseComponentSystem;
import org.terasology.engine.entitySystem.systems.RegisterSystem;
import org.terasology.engine.math.Region3i;
import org.terasology.engine.registry.In;
import org.terasology.math.geom.Vector3i;
import org.terasology.registry.In;

/**
* A festive implementation example!
Expand Down Expand Up @@ -55,7 +42,8 @@ public class EasterEggDetectorSystem extends BaseComponentSystem {
@Override
public void initialise() {
Region3i range = Region3i.createFromMinMax(new Vector3i(-40, -40, -40), new Vector3i(40, 40, 40));
data = new LinearAudioDetectorImpl("BlockDetector:easterEggDetector", Sets.newHashSet("CoreAssets:Snow"), range, audioManager, "BlockDetector:ScannerBeep", 200, 2000);
data = new LinearAudioDetectorImpl("BlockDetector:easterEggDetector", Sets.newHashSet("CoreAssets:Snow"),
range, audioManager, "BlockDetector:ScannerBeep", 200, 2000);

blockDetectorSystem.addDetector(data);
}
Expand All @@ -65,4 +53,4 @@ public void initialise() {
public void shutdown() {
blockDetectorSystem.removeDetector(data.getDetectorUri());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.blockdetector.systems;

import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.blockdetector.utilities.DetectorData;
import org.terasology.entitySystem.entity.EntityRef;
import org.terasology.entitySystem.systems.BaseComponentSystem;
import org.terasology.entitySystem.systems.RegisterSystem;
import org.terasology.entitySystem.systems.UpdateSubscriberSystem;
import org.terasology.logic.inventory.InventoryManager;
import org.terasology.logic.inventory.SelectedInventorySlotComponent;
import org.terasology.logic.players.LocalPlayer;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.entitySystem.systems.BaseComponentSystem;
import org.terasology.engine.entitySystem.systems.RegisterSystem;
import org.terasology.engine.entitySystem.systems.UpdateSubscriberSystem;
import org.terasology.engine.logic.players.LocalPlayer;
import org.terasology.engine.registry.In;
import org.terasology.engine.registry.Share;
import org.terasology.engine.world.WorldProvider;
import org.terasology.engine.world.block.Block;
import org.terasology.engine.world.block.BlockManager;
import org.terasology.engine.world.block.BlockUri;
import org.terasology.inventory.logic.InventoryManager;
import org.terasology.inventory.logic.SelectedInventorySlotComponent;
import org.terasology.math.geom.Vector3i;
import org.terasology.registry.In;
import org.terasology.registry.Share;
import org.terasology.world.WorldProvider;
import org.terasology.world.block.Block;
import org.terasology.world.block.BlockManager;
import org.terasology.world.block.BlockUri;

import java.math.RoundingMode;
import java.util.HashSet;
Expand All @@ -46,67 +33,58 @@
*/
@RegisterSystem
@Share(value = BlockDetectorSystem.class)
public class BlockDetectorSystemImpl extends BaseComponentSystem implements UpdateSubscriberSystem, BlockDetectorSystem {
public class BlockDetectorSystemImpl extends BaseComponentSystem implements UpdateSubscriberSystem,
BlockDetectorSystem {
private static final Logger logger = LoggerFactory.getLogger(BlockDetectorSystemImpl.class);

private final Set<Vector3i> detectedBlocks = new HashSet<>();
/**
* Used to retrieve the {@code AIR_ID} and {@code UNLOADED_ID} Urns.
*/
@In
private BlockManager blockManager;

/**
* Used to get the block located at the specified position.
*/
@In
private WorldProvider worldProvider;

/**
* Used to get the player's current position.
*/
@In
private LocalPlayer localPlayer;

/**
* Used to get the player's current selected item.
*/
@In
private InventoryManager inventoryManager;

/**
* The map of detector-detectable bindings.
*/
private Map<String, DetectorData> detectors;

private float timeSinceLastUpdate;

/**
* The period at which the detectBlocks() function should be called.
*/
private float updatePeriod;

/**
* The current timer task associated with the timer.
*/
private TimerTask timerTask;

/**
* The timer object calling timerTask periodically.
*/
private Timer timer;

/**
* The current task period, in ms.
*/
private Integer taskPeriod;

private Set<Vector3i> detectedBlocks = new HashSet<>();

/**
* Sets the local player for the test
* The dummy local player will make the system work and does not throw a null exception
* @param set A local player whose location component is used
*/
* Sets the local player for the test The dummy local player will make the system work and does not throw a null
* exception
*
* @param set A local player whose location component is used
*/
public void setLocalPlayer(LocalPlayer set) {
this.localPlayer = set;
}
Expand All @@ -116,16 +94,17 @@ public float getTimeSinceLastUpdate() {
}

/**
* This sets the timeSinceLastUpdate value for the tests
*/
* This sets the timeSinceLastUpdate value for the tests
*/
public void setTimeSinceLastUpdate(float value) {
this.timeSinceLastUpdate = value;
}

/**
* This provides the DetectorData for the tests
* @return a Map of DetectorData
*/
* This provides the DetectorData for the tests
*
* @return a Map of DetectorData
*/
public Map<String, DetectorData> getDetectors() {
return this.detectors;
}
Expand Down Expand Up @@ -337,7 +316,8 @@ public void detectBlocks() {
int newPeriod = data.getPeriod(minDistance);

if (taskPeriod == null || taskPeriod != newPeriod) {
logger.info("Detector {} rescheduling task at taskPeriod {} (minimal block distance: {})", data.getDetectorUri(), newPeriod, minDistance);
logger.info("Detector {} rescheduling task at taskPeriod {} (minimal block distance: {})",
data.getDetectorUri(), newPeriod, minDistance);

// Reset the timer.
shutdownTimer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.blockdetector.utilities;

import org.terasology.math.Region3i;
import org.terasology.engine.math.Region3i;

import java.util.Set;

Expand All @@ -28,21 +15,20 @@ public abstract class DetectorData {
/**
* The Uri of the detector item.
*/
private String detectorUri;
private final String detectorUri;

/**
* A set of detectable item Uris represented as strings.
*/
private Set<String> detectableUris;
private final Set<String> detectableUris;

/**
* The range of the detector.
*/
private Region3i range;
private final Region3i range;

/**
* If this variable is not null, all blocks within the specified range
* must not be AIR or UNLOADED.
* If this variable is not null, all blocks within the specified range must not be AIR or UNLOADED.
*/
private Region3i nonAerialRange;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,41 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.blockdetector.utilities;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.audio.AudioManager;
import org.terasology.math.Region3i;
import org.terasology.utilities.Assets;
import org.terasology.engine.audio.AudioManager;
import org.terasology.engine.math.Region3i;
import org.terasology.engine.utilities.Assets;

import java.util.Set;

/**
* A DetectorData implementation containing information about an audio asset.
* <p>
* Plays the asset with a frequency scaling depending on the distance to the closest block,
* ranging from frequencyLow to frequencyHigh with four possible values.
* Plays the asset with a frequency scaling depending on the distance to the closest block, ranging from frequencyLow to
* frequencyHigh with four possible values.
*/
public class LinearAudioDetectorImpl extends DetectorData {
private static final Logger logger = LoggerFactory.getLogger(LinearAudioDetectorImpl.class);

/**
* The audio manager. Should be injected in the custom system implementation.
*/
private AudioManager audioManager;
private final AudioManager audioManager;

/**
* The audio asset Uri, represented as a string.
*/
private String audioUri;
private final String audioUri;

private int frequencyLow;
private int frequencyHigh;
private final int frequencyLow;
private final int frequencyHigh;

private int scaleCount = 4;
private final int scaleCount = 4;

public LinearAudioDetectorImpl(String detectorUri, Set<String> detectableUris, Region3i range, AudioManager audioManager, String audioUri, int frequencyLow, int frequencyHigh) {
public LinearAudioDetectorImpl(String detectorUri, Set<String> detectableUris, Region3i range,
AudioManager audioManager, String audioUri, int frequencyLow, int frequencyHigh) {
super(detectorUri, detectableUris, range);
this.audioManager = audioManager;
this.audioUri = audioUri;
Expand Down
Loading