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

feat(JOML): migrate DefenceWorldManager #51

Merged
merged 1 commit into from
Jan 4, 2021
Merged
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
23 changes: 11 additions & 12 deletions src/main/java/org/terasology/gooeyDefence/DefenceWorldManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package org.terasology.gooeyDefence;

import org.joml.Vector2i;
import org.joml.Vector3f;
import org.joml.Vector3i;
import org.terasology.assets.management.AssetManager;
import org.terasology.entitySystem.entity.EntityManager;
import org.terasology.entitySystem.entity.EntityRef;
Expand All @@ -33,9 +36,6 @@
import org.terasology.logic.health.EngineDamageTypes;
import org.terasology.logic.inventory.events.DropItemEvent;
import org.terasology.logic.location.LocationComponent;
import org.terasology.math.JomlUtil;
import org.terasology.math.geom.Vector2i;
import org.terasology.math.geom.Vector3i;
import org.terasology.registry.In;
import org.terasology.registry.Share;
import org.terasology.utilities.procedural.Noise;
Expand Down Expand Up @@ -124,7 +124,7 @@ public void onAttackEntity(AttackEvent event, EntityRef targetEntity) {
public void onCreateBlockDrops(CreateBlockDropsEvent event, EntityRef entity, LocationComponent component) {
if (entity.getParentPrefab().getName().equals(DefenceUris.PLAIN_WORLD_BLOCK)) {
event.consume();
factory.newInstance(blockManager.getBlockFamily(DefenceUris.PLAIN_BLOCK)).send(new DropItemEvent(component.getWorldPosition()));
factory.newInstance(blockManager.getBlockFamily(DefenceUris.PLAIN_BLOCK)).send(new DropItemEvent(component.getWorldPosition(new Vector3f())));
}
}

Expand All @@ -147,7 +147,7 @@ public void onFieldReset(OnFieldReset event, EntityRef entity) {
* @param size The size of the field to clear.
*/
private void clearField(int size) {
Vector3i pos = Vector3i.zero();
Vector3i pos = new Vector3i();
Block block;
for (int x = -size; x <= size; x++) {
/* We use circle eq "x^2 + y^2 = r^2" to work out where we need to start */
Expand All @@ -174,17 +174,16 @@ private void clearField(int size) {
*/
private void createRandomFill(int size) {
Noise noise = new WhiteNoise(System.currentTimeMillis());
Vector2i pos2i = Vector2i.zero();
Vector3i pos3i = Vector3i.zero();
Vector2i pos2i = new Vector2i();
Vector3i pos3i = new Vector3i();

for (int x = -size; x <= size; x++) {
int width = (int) Math.floor(Math.sqrt(size * size - x * x));
for (int y = -width; y <= width; y++) {
pos2i.setX(x);
pos2i.setY(y);
if (RandomFillingProvider.shouldSpawnBlock(JomlUtil.from(pos2i), noise)) {
pos3i.setX(pos2i.x);
pos3i.setZ(pos2i.y);
pos2i.set(x,y);
if (RandomFillingProvider.shouldSpawnBlock(pos2i, noise)) {
pos3i.x = pos2i.x;
pos3i.z = pos2i.y;
worldProvider.setBlock(pos3i, fieldBlock);
}
}
Expand Down