use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class WorldProviderCoreStub method setBlocks.
@Override
public Map<Vector3i, Block> setBlocks(Map<Vector3i, Block> blocksToPlace) {
Map<Vector3i, Block> result = new HashMap<>(blocks.size());
for (Map.Entry<Vector3i, Block> entry : blocksToPlace.entrySet()) {
Block b = setBlock(entry.getKey(), entry.getValue());
result.put(entry.getKey(), b);
}
return result;
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class BlockPlacementBenchmark method runStep.
@Override
public void runStep() {
if (useSetBlocksInsteadOfSetBlock) {
Map<Vector3i, Block> blocksToPlace = new HashMap<>();
for (Vector3i v : region3i) {
blocksToPlace.put(v, blockToPlace);
}
worldProvider.setBlocks(blocksToPlace);
} else {
for (Vector3i v : region3i) {
worldProvider.setBlock(v, blockToPlace);
}
}
if (blockToPlace == stone) {
blockToPlace = air;
} else {
blockToPlace = stone;
}
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class DoorSystem method canAttachTo.
private boolean canAttachTo(Vector3i doorPos, Side side) {
Vector3i adjacentBlockPos = new Vector3i(doorPos);
adjacentBlockPos.add(side.getVector3i());
Block adjacentBlock = worldProvider.getBlock(adjacentBlockPos);
return adjacentBlock.isAttachmentAllowed();
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class DoorSystem method openDoor.
@ReceiveEvent
public void openDoor(OpenDoorEvent event, EntityRef player) {
EntityRef entity = event.getDoorEntity();
DoorComponent door = entity.getComponent(DoorComponent.class);
Side newSide = door.openSide;
BlockRegionComponent regionComp = entity.getComponent(BlockRegionComponent.class);
Block bottomBlock = door.bottomBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, regionComp.region.min(), newSide, Side.TOP);
worldProvider.setBlock(regionComp.region.min(), bottomBlock);
Block topBlock = door.topBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, regionComp.region.max(), newSide, Side.TOP);
worldProvider.setBlock(regionComp.region.max(), topBlock);
if (door.openSound != null) {
entity.send(new PlaySoundEvent(door.openSound, 1f));
}
door.isOpen = true;
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class ArrowAction method onActivate.
@ReceiveEvent
public void onActivate(ActivateEvent event, EntityRef entity, ArrowActionComponent arrowActionComponent) {
if (time.getGameTime() > lastTime + 1.0f / arrowActionComponent.arrowsPerSecond) {
Vector3f target = event.getHitNormal();
Vector3i blockPos = new Vector3i(target);
Vector3f position = new Vector3f(event.getOrigin());
Vector3f dir = new Vector3f(event.getDirection());
HitResult result;
result = physicsRenderer.rayTrace(position, dir, arrowActionComponent.maxDistance, filter);
Block currentBlock = worldProvider.getBlock(blockPos);
if (currentBlock.isDestructible()) {
EntityBuilder builder = entityManager.newBuilder("Core:defaultBlockParticles");
builder.getComponent(LocationComponent.class).setWorldPosition(target);
builder.build();
}
EntityRef blockEntity = result.getEntity();
blockEntity.send(new DoDamageEvent(arrowActionComponent.damageAmount, arrowActionComponent.damageType));
lastTime = time.getGameTime();
}
}
Aggregations