use of org.terasology.gestalt.entitysystem.component.Component in project Terasology by MovingBlocks.
the class EntityAwareWorldProvider method setBlocks.
// SetBlocks, not SetBlock, is currently triggered by the engine whenever a player places a block.
// This allows for several useful features, such as quickly synchronizing placement across networks.
// However, this means that even if only one block is placed, this is the method being called.
// It must be overridden here to allow an OnChangedBlock event to be properly sent for placed blocks.
@Override
public Map<Vector3ic, Block> setBlocks(Map<? extends Vector3ic, Block> blocks) {
if (GameThread.isCurrentThread()) {
Map<Vector3ic, Block> oldBlocks = super.setBlocks(blocks);
for (Vector3ic vec : oldBlocks.keySet()) {
if (oldBlocks.get(vec) != null) {
EntityRef blockEntity = getBlockEntityAt(vec);
// check for components to be retained when updating the block entity
final Set<Class<? extends Component>> retainComponents = Optional.ofNullable(blockEntity.getComponent(RetainComponentsComponent.class)).map(retainComponentsComponent -> retainComponentsComponent.components).orElse(Collections.emptySet());
updateBlockEntity(blockEntity, vec, oldBlocks.get(vec), blocks.get(vec), false, retainComponents);
}
}
return oldBlocks;
}
return null;
}
use of org.terasology.gestalt.entitysystem.component.Component in project Terasology by MovingBlocks.
the class EntityAwareWorldProvider method setBlock.
@Override
public Block setBlock(Vector3ic pos, Block type) {
if (GameThread.isCurrentThread()) {
EntityRef blockEntity = getBlockEntityAt(pos);
Block oldType = super.setBlock(pos, type);
final Set<Class<? extends Component>> retainComponents = Optional.ofNullable(blockEntity.getComponent(RetainComponentsComponent.class)).map(retainComponentsComponent -> retainComponentsComponent.components).orElse(Collections.emptySet());
if (oldType != null) {
updateBlockEntity(blockEntity, pos, oldType, type, false, retainComponents);
}
return oldType;
}
return null;
}
Aggregations