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 ClamberComponent and ClimbablesPlacingSystem #5

Merged
merged 1 commit into from
Jan 16, 2021
Merged
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
13 changes: 7 additions & 6 deletions src/main/java/org/terasology/climbables/ClamberComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@
*/
package org.terasology.climbables;

import org.joml.Vector3i;
import org.joml.Vector3ic;
import org.terasology.entitySystem.Component;
import org.terasology.math.Side;
import org.terasology.math.geom.Vector3i;

public class ClamberComponent implements Component {

public PlacingMode placingMode = PlacingMode.NORMAL;
public boolean support = false;
public int maxPlacementDistance = 3;

public Vector3i getPlacingModeDirection() {
public Vector3ic getPlacingModeDirection() {
switch (this.placingMode) {
case ROPING:
return Side.BOTTOM.getVector3i();
return Side.BOTTOM.direction();
case STACKING:
return Side.TOP.getVector3i();
return Side.TOP.direction();
case NORMAL:
return Vector3i.zero();
default:
return new Vector3i(0, 0, 0);
}
return Vector3i.zero();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.terasology.climbables;

import org.joml.Vector3f;
import org.joml.Vector3i;
import org.terasology.audio.AudioManager;
import org.terasology.audio.events.PlaySoundEvent;
import org.terasology.entitySystem.entity.EntityRef;
Expand All @@ -31,9 +33,7 @@
import org.terasology.logic.inventory.InventoryUtils;
import org.terasology.logic.inventory.ItemComponent;
import org.terasology.math.ChunkMath;
import org.terasology.math.JomlUtil;
import org.terasology.math.Side;
import org.terasology.math.geom.Vector3i;
import org.terasology.registry.In;
import org.terasology.utilities.Assets;
import org.terasology.world.BlockEntityRegistry;
Expand All @@ -42,6 +42,7 @@
import org.terasology.world.block.BlockComponent;
import org.terasology.world.block.entity.placement.PlaceBlocks;
import org.terasology.world.block.family.BlockFamily;
import org.terasology.world.block.family.BlockPlacementData;
import org.terasology.world.block.items.BlockItemComponent;
import org.terasology.world.block.items.OnBlockItemPlaced;

Expand All @@ -61,7 +62,7 @@ public class ClimbablesPlacingSystem extends BaseComponentSystem {

@ReceiveEvent(priority = EventPriority.PRIORITY_HIGH)
public void onDestroyed(DoDestroyEvent event, EntityRef entity, ClamberComponent clamberComponent, BlockComponent blockComponent) {
Vector3i nextBlockPos = new Vector3i(blockComponent.getPosition());
Vector3i nextBlockPos = blockComponent.getPosition(new Vector3i());
nextBlockPos.add(clamberComponent.getPlacingModeDirection());

EntityRef nextBlockEntity = blockEntityRegistry.getBlockEntityAt(nextBlockPos);
Expand Down Expand Up @@ -93,11 +94,11 @@ public void onPlaceBlock(ActivateEvent event, EntityRef item) {
return;
}

Vector3i placementDirection = Vector3i.zero();
Vector3i placementDirection = new Vector3i();
ClamberComponent targetClamberComponent = targetEntity.getComponent(ClamberComponent.class);

Vector3i climbablePlacementPos = new Vector3i(blockComponent.getPosition());
Block blockToPlace = type.getBlockForPlacement(climbablePlacementPos, Side.LEFT, secondaryDirection);
Vector3i climbablePlacementPos = blockComponent.getPosition(new Vector3i());
Block blockToPlace = type.getBlockForPlacement(new BlockPlacementData(climbablePlacementPos, Side.LEFT, new Vector3f(secondaryDirection.direction())));
if (blockToPlace == null) {
event.consume();
return;
Expand All @@ -109,7 +110,7 @@ public void onPlaceBlock(ActivateEvent event, EntityRef item) {
event.consume();
return;
} else {
placementDirection = placingClamberComponent.getPlacingModeDirection();
placementDirection.set(placingClamberComponent.getPlacingModeDirection());
}
} else {
return;
Expand All @@ -135,11 +136,11 @@ public void onPlaceBlock(ActivateEvent event, EntityRef item) {
while (targetClamberComponent.placingMode == newBlockClamberComponent.placingMode && placementDistance < targetClamberComponent.maxPlacementDistance);

if (newBlock.isReplacementAllowed()) {
PlaceBlocks placeBlocks = new PlaceBlocks(JomlUtil.from(climbablePlacementPos), blockToPlace, event.getInstigator());
PlaceBlocks placeBlocks = new PlaceBlocks(climbablePlacementPos, blockToPlace, event.getInstigator());
worldProvider.getWorldEntity().send(placeBlocks);

if (!placeBlocks.isConsumed()) {
item.send(new OnBlockItemPlaced(climbablePlacementPos, blockEntityRegistry.getBlockEntityAt(climbablePlacementPos)));
item.send(new OnBlockItemPlaced(climbablePlacementPos, blockEntityRegistry.getBlockEntityAt(climbablePlacementPos), EntityRef.NULL));
}

event.getInstigator().send(new PlaySoundEvent(Assets.getSound("engine:PlaceBlock").get(), 0.5f));
Expand Down