use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class StandardBatchPropagator method push.
private void push(Vector3i pos, byte value) {
Block block = world.getBlockAt(pos);
for (Side side : Side.values()) {
byte spreadValue = rules.propagateValue(value, side, block);
Vector3i adjPos = side.getAdjacentPos(pos);
if (rules.canSpreadOutOf(block, side)) {
byte adjValue = world.getValueAt(adjPos);
if (adjValue < spreadValue && adjValue != PropagatorWorldView.UNAVAILABLE) {
Block adjBlock = world.getBlockAt(adjPos);
if (rules.canSpreadInto(adjBlock, side.reverse())) {
increase(adjPos, spreadValue);
}
}
}
}
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class StandardBatchPropagator method purge.
private void purge(Vector3i pos, byte oldValue) {
Block block = world.getBlockAt(pos);
increaseQueues[rules.getMaxValue() - oldValue].remove(pos);
byte fixedValue = rules.getFixedValue(block, pos);
if (fixedValue > 0) {
increase(pos, fixedValue);
} else {
world.setValueAt(pos, NO_VALUE);
}
for (Side side : Side.values()) {
byte expectedValue = rules.propagateValue(oldValue, side, block);
Vector3i adjPos = side.getAdjacentPos(pos);
if (rules.canSpreadOutOf(block, side)) {
byte adjValue = world.getValueAt(adjPos);
if (adjValue == expectedValue) {
Block adjBlock = world.getBlockAt(adjPos);
if (rules.canSpreadInto(adjBlock, side.reverse())) {
reduce(adjPos, expectedValue);
}
} else if (adjValue > 0) {
queueSpreadValue(adjPos, adjValue);
}
}
}
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class InternalLightProcessor method populateSunlightRegen.
private static void populateSunlightRegen(LitChunk chunk) {
int top = ChunkConstants.SIZE_Y - 1;
for (int x = 0; x < ChunkConstants.SIZE_X; x++) {
for (int z = 0; z < ChunkConstants.SIZE_Z; z++) {
int y = top;
byte regen = 0;
Block lastBlock = chunk.getBlock(x, y, z);
for (y -= 1; y >= 0; y--) {
Block block = chunk.getBlock(x, y, z);
if (SUNLIGHT_REGEN_RULES.canSpreadOutOf(lastBlock, Side.BOTTOM) && SUNLIGHT_REGEN_RULES.canSpreadInto(block, Side.TOP)) {
regen = SUNLIGHT_REGEN_RULES.propagateValue(regen, Side.BOTTOM, lastBlock);
chunk.setSunlightRegen(x, y, z, regen);
} else {
regen = 0;
}
lastBlock = block;
}
}
}
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class BlockCommands method replaceBlock.
@Command(shortDescription = "Replaces a block in front of user", helpText = "Replaces a block in front of the user at the specified max distance", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public void replaceBlock(@Sender EntityRef sender, @CommandParam("blockName") String uri, @CommandParam(value = "maxDistance", required = false) Integer maxDistanceParam) {
int maxDistance = maxDistanceParam != null ? maxDistanceParam : 12;
EntityRef playerEntity = sender.getComponent(ClientComponent.class).character;
EntityRef gazeEntity = GazeAuthoritySystem.getGazeEntityForCharacter(playerEntity);
LocationComponent gazeLocation = gazeEntity.getComponent(LocationComponent.class);
Set<ResourceUrn> matchingUris = Assets.resolveAssetUri(uri, BlockFamilyDefinition.class);
targetSystem.updateTarget(gazeLocation.getWorldPosition(), gazeLocation.getWorldDirection(), maxDistance);
EntityRef target = targetSystem.getTarget();
BlockComponent targetLocation = target.getComponent(BlockComponent.class);
if (matchingUris.size() == 1) {
Optional<BlockFamilyDefinition> def = Assets.get(matchingUris.iterator().next(), BlockFamilyDefinition.class);
if (def.isPresent()) {
BlockFamily blockFamily = blockManager.getBlockFamily(uri);
Block block = blockManager.getBlock(blockFamily.getURI());
world.setBlock(targetLocation.getPosition(), block);
} else if (matchingUris.size() > 1) {
StringBuilder builder = new StringBuilder();
builder.append("Non-unique shape name, possible matches: ");
Iterator<ResourceUrn> shapeUris = sortItems(matchingUris).iterator();
while (shapeUris.hasNext()) {
builder.append(shapeUris.next().toString());
if (shapeUris.hasNext()) {
builder.append(", ");
}
}
}
}
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class AttachedToSurfaceFamilyFactory method createBlockFamily.
@Override
public BlockFamily createBlockFamily(BlockFamilyDefinition definition, BlockBuilderHelper blockBuilder) {
Map<Side, Block> blockMap = Maps.newEnumMap(Side.class);
if (definition.getData().hasSection("top")) {
Block block = blockBuilder.constructSimpleBlock(definition, "top");
block.setDirection(Side.TOP);
blockMap.put(Side.TOP, block);
}
if (definition.getData().hasSection("front")) {
for (Rotation rot : Rotation.horizontalRotations()) {
Side side = rot.rotate(Side.FRONT);
blockMap.put(side, blockBuilder.constructTransformedBlock(definition, side.toString().toLowerCase(Locale.ENGLISH), rot));
}
}
if (definition.getData().hasSection("bottom")) {
Block block = blockBuilder.constructSimpleBlock(definition, "bottom");
block.setDirection(Side.BOTTOM);
blockMap.put(Side.BOTTOM, block);
}
return new AttachedToSurfaceFamily(new BlockUri(definition.getUrn()), blockMap, definition.getCategories());
}
Aggregations