Skip to content

Commit

Permalink
Bugfix: use target position offset when placing blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
skaldarnar committed Mar 11, 2016
1 parent 2e48a04 commit eac658c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.terasology.grammar.world.block;

import com.google.common.collect.Maps;
import org.terasology.math.geom.Vector3f;
import org.terasology.math.geom.Vector3i;
import org.terasology.world.block.Block;

Expand All @@ -37,6 +38,13 @@ public Map<Vector3i, Block> getBlocks() {
return Collections.unmodifiableMap(blocks);
}

public Map<Vector3i, Block> getBlocks(Vector3f offset) {
HashMap<Vector3i, Block> res = Maps.newHashMapWithExpectedSize(blocks.size());
blocks.entrySet().forEach(entry -> res.put(entry.getKey().add(new Vector3i(offset)), entry.getValue()));
return Collections.unmodifiableMap(res);
}


/**
* Sets the block at the given position to the specfic block type.
* May override an existing entry without any further notice.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class BuildingCommands extends BaseComponentSystem {
@In
private WorldProvider worldProvider;

@Command(shortDescription = "Building generation test")
@Command(shortDescription = "Building generation test", runOnServer = true)
public void build() {
console.addMessage("Starting building a default structure ...");

Expand All @@ -68,7 +68,7 @@ public void build() {
Vector3f targetPos = cameraTargetSystem.getHitPosition();

if (worldProvider != null) {
worldProvider.getWorldEntity().send(new PlaceBlocks(collection.getBlocks()));
worldProvider.getWorldEntity().send(new PlaceBlocks(collection.getBlocks(targetPos)));
}

console.addMessage("Finished ...");
Expand All @@ -89,16 +89,7 @@ public void buildWithDimension(@CommandParam(value = "width") int width, @Comman
console.addMessage(builder.toString());

Vector3f targetPos = cameraTargetSystem.getHitPosition();
//Camera camera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();
//Vector3f attachPos = camera.getPosition();
//Vector3f offset = camera.getViewingDirection();

//offset.scale(3);
//attachPos.add(offset);

//BuildingGenerator generator = setUp();
BuildingGenerator generator = complexBuildingGenerator();
//BuildingGenerator generator = testGenerator();

console.addMessage("Created Building Generator. Starting building process ...");
long time = System.currentTimeMillis();
Expand All @@ -111,13 +102,7 @@ public void buildWithDimension(@CommandParam(value = "width") int width, @Comman
console.addMessage(builder.toString());

if (worldProvider != null) {
// TODO
worldProvider.getWorldEntity().send(new PlaceBlocks(collection.getBlocks()));
// collection.getBlocks().forEach(
// (position, block) -> {
// worldProvider.setBlock(position.add(new Vector3i(targetPos)), block);
// }
// );
worldProvider.getWorldEntity().send(new PlaceBlocks(collection.getBlocks(targetPos)));
}

console.addMessage("Finished ...");
Expand All @@ -130,7 +115,7 @@ public BuildingGenerator setUp() {
ShapeSymbol floor = new ShapeSymbol("floor");
ShapeSymbol roof = new ShapeSymbol("roof");
// used Set rules
SetRule setStone = new SetRule(new BlockUri("core:CobbleStone"));
SetRule setStone = new SetRule(new BlockUri("core:cobblestone"));
SetRule setPlank = new SetRule(new BlockUri("core:plank"));
// used split rule (split walls)
SplitArg walls = new SplitArg(SplitArg.SplitType.WALLS, setStone);
Expand Down Expand Up @@ -170,7 +155,7 @@ public static BuildingGenerator complexBuildingGenerator() {
ShapeSymbol middlePartWalls = new ShapeSymbol("middle_part_walls");
//================================================
SetRule setStone = new SetRule(new BlockUri("core:stone"));
SetRule setCobblestone = new SetRule(new BlockUri("core:CobbleStone"));
SetRule setCobblestone = new SetRule(new BlockUri("core:cobblestone"));
SetRule setOaktrunk = new SetRule(new BlockUri("core:OakTrunk"));
SetRule setGlass = new SetRule(new BlockUri("core:glass"));
SetRule setPlank = new SetRule(new BlockUri("core:plank"));
Expand Down

0 comments on commit eac658c

Please sign in to comment.