use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class BlockBuilder method createRawBlock.
private Block createRawBlock(String defaultName, SectionDefinitionData def) {
Block block = new Block();
block.setLiquid(def.isLiquid());
block.setWater(def.isWater());
block.setGrass(def.isGrass());
block.setIce(def.isIce());
block.setHardness(def.getHardness());
block.setAttachmentAllowed(def.isAttachmentAllowed());
block.setReplacementAllowed(def.isReplacementAllowed());
block.setSupportRequired(def.isSupportRequired());
block.setPenetrable(def.isPenetrable());
block.setTargetable(def.isTargetable());
block.setClimbable(def.isClimbable());
block.setTranslucent(def.isTranslucent());
block.setDoubleSided(def.isDoubleSided());
block.setShadowCasting(def.isShadowCasting());
block.setWaving(def.isWaving());
block.setLuminance(def.getLuminance());
block.setTint(def.getTint());
if (Strings.isNullOrEmpty(def.getDisplayName())) {
block.setDisplayName(properCase(defaultName));
} else {
block.setDisplayName(def.getDisplayName());
}
block.setSounds(def.getSounds());
block.setMass(def.getMass());
block.setDebrisOnDestroy(def.isDebrisOnDestroy());
block.setFriction(def.getFriction());
block.setRestitution(def.getRestitution());
if (def.getEntity() != null) {
block.setPrefab(def.getEntity().getPrefab());
block.setKeepActive(def.getEntity().isKeepActive());
}
if (def.getInventory() != null) {
block.setStackable(def.getInventory().isStackable());
block.setDirectPickup(def.getInventory().isDirectPickup());
}
return block;
}
use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class BlockBuilder method constructCustomBlock.
@Override
public Block constructCustomBlock(String defaultName, BlockShape shape, Rotation rotation, SectionDefinitionData section, BlockUri uri, BlockFamily blockFamily) {
Block block = createRawBlock(defaultName, section);
block.setRotation(rotation);
block.setPrimaryAppearance(createAppearance(shape, section.getBlockTiles(), rotation));
setBlockFullSides(block, shape, rotation);
block.setCollision(shape.getCollisionOffset(rotation), shape.getCollisionShape(rotation));
for (BlockPart part : BlockPart.values()) {
block.setColorSource(part, section.getColorSources().get(part));
block.setColorOffset(part, new Color().set(section.getColorOffsets().get(part)));
}
block.setUri(uri);
block.setBlockFamily(blockFamily);
// Lowered mesh for liquids
if (block.isLiquid()) {
applyLiquidShapes(block, section.getBlockTiles());
}
return block;
}
use of org.terasology.engine.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);
AABBf blockBounds = block.getBounds(blockPos);
/**
* 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.
*/
blockBounds.minX += KinematicCharacterMover.HORIZONTAL_PENETRATION;
blockBounds.maxX -= KinematicCharacterMover.HORIZONTAL_PENETRATION;
blockBounds.minY += KinematicCharacterMover.VERTICAL_PENETRATION;
blockBounds.maxY -= KinematicCharacterMover.VERTICAL_PENETRATION;
blockBounds.minZ += KinematicCharacterMover.HORIZONTAL_PENETRATION;
blockBounds.maxZ -= KinematicCharacterMover.HORIZONTAL_PENETRATION;
/*
* Calculations aren't exact and in the corner cases it is better to let the user place the block.
*/
blockBounds.minX += ADDITIONAL_ALLOWED_PENETRATION;
blockBounds.minY += ADDITIONAL_ALLOWED_PENETRATION;
blockBounds.minZ += ADDITIONAL_ALLOWED_PENETRATION;
blockBounds.maxX -= ADDITIONAL_ALLOWED_PENETRATION;
blockBounds.maxY -= ADDITIONAL_ALLOWED_PENETRATION;
blockBounds.maxZ -= ADDITIONAL_ALLOWED_PENETRATION;
return physics.scanArea(blockBounds, StandardCollisionGroup.DEFAULT, StandardCollisionGroup.CHARACTER).isEmpty();
}
return true;
}
use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class MultiConnectFamily method registerBlock.
/**
* @param root The root block URI of the family
* @param definition The definition of the block family as passed down from the engine
* @param blockBuilder The block builder to make the blocks in the family
* @param name The name of the section of the block to be registered, ex: "no_connections"
* @param sides A byte representing the sides which should be connected for this block
* @param rotations All of the ways the block should be rotated
* @return All of the rotations possible for the block with the given sides
*/
public Set<Block> registerBlock(BlockUri root, BlockFamilyDefinition definition, BlockBuilderHelper blockBuilder, String name, byte sides, Iterable<Rotation> rotations) {
Set<Block> result = Sets.newLinkedHashSet();
for (Rotation rotation : rotations) {
byte sideBits = 0;
for (Side side : SideBitFlag.getSides(sides)) {
sideBits |= SideBitFlag.getSide(rotation.rotate(side));
}
Block block = blockBuilder.constructTransformedBlock(definition, name, rotation, new BlockUri(root, new Name(String.valueOf(sideBits))), this);
blocks.put(sideBits, block);
result.add(block);
}
return result;
}
use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class BlockManagerImpl method receiveFamilyRegistration.
public void receiveFamilyRegistration(BlockUri familyUri, Map<String, Integer> registration) {
Optional<BlockFamily> family = loadFamily(familyUri);
if (family.isPresent()) {
lock.lock();
try {
for (Block block : family.get().getBlocks()) {
Integer id = registration.get(block.getURI().toString());
if (id != null) {
block.setId((short) id.intValue());
} else {
logger.error("Missing id for block {} in registered family {}", block.getURI(), familyUri);
block.setId(UNKNOWN_ID);
}
}
registerFamily(family.get());
} finally {
lock.unlock();
}
}
}
Aggregations