use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class HorizontalBlockFamilyFactory method createBlockFamily.
@Override
public BlockFamily createBlockFamily(BlockFamilyDefinition definition, BlockBuilderHelper blockBuilder) {
if (definition.isFreeform()) {
throw new IllegalStateException("A shape must be provided when creating a family for a freeform block family definition");
}
Map<Side, Block> blockMap = Maps.newHashMap();
for (Rotation rot : Rotation.horizontalRotations()) {
Side side = rot.rotate(Side.FRONT);
blockMap.put(side, blockBuilder.constructTransformedBlock(definition, side.toString().toLowerCase(Locale.ENGLISH), rot));
}
return new HorizontalBlockFamily(new BlockUri(definition.getUrn()), getArchetypeSide(), blockMap, definition.getCategories());
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class BlockBuilder method constructSimpleBlock.
@Override
public Block constructSimpleBlock(BlockFamilyDefinition definition) {
BlockShape shape = definition.getData().getBaseSection().getShape();
if (shape == null) {
shape = cubeShape;
}
Block block = constructCustomBlock(definition.getUrn().getResourceName().toString(), shape, Rotation.none(), definition.getData().getBaseSection());
// Lowered mesh for liquids
if (block.isLiquid()) {
applyLoweredShape(block, loweredShape, definition.getData().getBaseSection().getBlockTiles());
}
return block;
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class BlockItemSystem method canPlaceBlock.
private boolean canPlaceBlock(Block block, Vector3i targetBlock, Vector3i blockPos) {
if (block == null) {
return false;
}
Block centerBlock = worldProvider.getBlock(targetBlock.x, targetBlock.y, targetBlock.z);
if (!centerBlock.isAttachmentAllowed()) {
return false;
}
Block adjBlock = worldProvider.getBlock(blockPos.x, blockPos.y, blockPos.z);
if (!adjBlock.isReplacementAllowed() || adjBlock.isTargetable()) {
return false;
}
if (block.getBlockFamily().equals(adjBlock.getBlockFamily())) {
return false;
}
// Prevent players from placing blocks inside their bounding boxes
if (!block.isPenetrable()) {
Physics physics = CoreRegistry.get(Physics.class);
AABB blockBounds = block.getBounds(blockPos);
Vector3f min = new Vector3f(blockBounds.getMin());
Vector3f max = new Vector3f(blockBounds.getMax());
/**
* Characters can enter other solid objects/blocks for certain amount. This is does to detect collsion
* start and end without noise. So if the user walked as close to a block as possible it is only natural
* to let it place a block exactly above it even if that technically would mean a collision start.
*/
min.x += KinematicCharacterMover.HORIZONTAL_PENETRATION;
max.x -= KinematicCharacterMover.HORIZONTAL_PENETRATION;
min.y += KinematicCharacterMover.VERTICAL_PENETRATION;
max.y -= KinematicCharacterMover.VERTICAL_PENETRATION;
min.z += KinematicCharacterMover.HORIZONTAL_PENETRATION;
max.z -= KinematicCharacterMover.HORIZONTAL_PENETRATION;
/*
* Calculations aren't exact and in the corner cases it is better to let the user place the block.
*/
// ignore small rounding mistakes
float additionalAllowedPenetration = 0.04f;
min.add(ADDITIONAL_ALLOWED_PENETRATION, ADDITIONAL_ALLOWED_PENETRATION, ADDITIONAL_ALLOWED_PENETRATION);
max.sub(ADDITIONAL_ALLOWED_PENETRATION, ADDITIONAL_ALLOWED_PENETRATION, ADDITIONAL_ALLOWED_PENETRATION);
AABB newBounds = AABB.createMinMax(min, max);
return physics.scanArea(newBounds, StandardCollisionGroup.DEFAULT, StandardCollisionGroup.CHARACTER).isEmpty();
}
return true;
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class BlockItemSystem method onPlaceBlock.
@ReceiveEvent(components = { BlockItemComponent.class, ItemComponent.class })
public void onPlaceBlock(ActivateEvent event, EntityRef item) {
if (!event.getTarget().exists()) {
event.consume();
return;
}
BlockItemComponent blockItem = item.getComponent(BlockItemComponent.class);
BlockFamily type = blockItem.blockFamily;
Side surfaceSide = Side.inDirection(event.getHitNormal());
Side secondaryDirection = ChunkMath.getSecondaryPlacementDirection(event.getDirection(), event.getHitNormal());
BlockComponent blockComponent = event.getTarget().getComponent(BlockComponent.class);
if (blockComponent == null) {
// If there is no block there (i.e. it's a BlockGroup, we don't allow placing block, try somewhere else)
event.consume();
return;
}
Vector3i targetBlock = blockComponent.getPosition();
Vector3i placementPos = new Vector3i(targetBlock);
placementPos.add(surfaceSide.getVector3i());
Block block = type.getBlockForPlacement(worldProvider, blockEntityRegistry, placementPos, surfaceSide, secondaryDirection);
if (canPlaceBlock(block, targetBlock, placementPos)) {
// TODO: Fix this for changes.
if (networkSystem.getMode().isAuthority()) {
PlaceBlocks placeBlocks = new PlaceBlocks(placementPos, block, event.getInstigator());
worldProvider.getWorldEntity().send(placeBlocks);
if (!placeBlocks.isConsumed()) {
item.send(new OnBlockItemPlaced(placementPos, blockEntityRegistry.getBlockEntityAt(placementPos)));
} else {
event.consume();
}
}
recordBlockPlaced(event, type);
event.getInstigator().send(new PlaySoundEvent(Assets.getSound("engine:PlaceBlock").get(), 0.5f));
} else {
event.consume();
}
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class SideBlockSupportRequired method checkForSupport.
@ReceiveEvent
public void checkForSupport(DelayedActionTriggeredEvent event, EntityRef entity, BlockComponent block, SideBlockSupportRequiredComponent supportRequired) {
if (event.getActionId().equals(SUPPORT_CHECK_ACTION_ID)) {
if (!isSufficientlySupported(block.getPosition(), null, Collections.<Vector3i, Block>emptyMap(), supportRequired)) {
PrefabManager prefabManager = CoreRegistry.get(PrefabManager.class);
entity.send(new DestroyEvent(entity, EntityRef.NULL, prefabManager.getPrefab("engine:supportRemovedDamage")));
}
}
}
Aggregations