use of org.spongepowered.api.data.property.block.ReplaceableProperty in project LanternServer by LanternPowered.
the class ChestInteractionBehavior method validateOpenableChestSpace.
static boolean validateOpenableChestSpace(BehaviorContext context, Location<World> loc, List<Runnable> tasks) {
final Location<World> relLoc = loc.getBlockRelative(Direction.UP);
final AABB relAabb = relLoc.getExtent().getBlockSelectionBox(relLoc.getBlockPosition()).orElse(null);
if (relAabb != null) {
AABB aabb = loc.getExtent().getBlockSelectionBox(loc.getBlockPosition()).get();
aabb = aabb.offset(0, 1, 0);
aabb = new AABB(aabb.getMin(), aabb.getMax().mul(1, 0, 1).add(0, aabb.getMin().getY() + 0.43, 0));
if (aabb.intersects(relAabb)) {
final ReplaceableProperty replaceableProperty = relLoc.getProperty(ReplaceableProperty.class).orElse(null);
// Replaceable blocks will be replaced when opened
if (replaceableProperty != null && replaceableProperty.getValue()) {
tasks.add(() -> context.addBlockChange(BlockSnapshotBuilder.create().location(relLoc).blockState(BlockTypes.AIR.getDefaultState()).build()));
// TODO: Use break block pipeline instead
} else {
return false;
}
}
}
return true;
}
use of org.spongepowered.api.data.property.block.ReplaceableProperty in project LanternServer by LanternPowered.
the class DoorBehavior method tryPlace.
@Override
public BehaviorResult tryPlace(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
final Location<World> location = context.requireContext(ContextKeys.BLOCK_LOCATION);
final Direction face = context.requireContext(ContextKeys.INTERACTION_FACE);
// Door can only be placed by clicking in the floor
if (face != Direction.DOWN) {
return BehaviorResult.PASS;
}
final Location<World> down = location.getBlockRelative(Direction.DOWN);
final SolidCubeProperty solidProp = down.getProperty(SolidCubeProperty.class).get();
// The door must be placed on a solid block
if (!solidProp.getValue()) {
return BehaviorResult.PASS;
}
final Location<World> up = location.getBlockRelative(Direction.UP);
final ReplaceableProperty replaceableProp = up.getProperty(ReplaceableProperty.class).get();
if (!replaceableProp.getValue()) {
return BehaviorResult.PASS;
}
final BlockSnapshot snapshot = context.getContext(ContextKeys.BLOCK_SNAPSHOT).orElseThrow(() -> new IllegalStateException("The BlockSnapshotRetrieveBehavior BlockSnapshot isn't present."));
final BlockSnapshotBuilder builder = BlockSnapshotBuilder.create().from(snapshot);
context.populateBlockSnapshot(builder, BehaviorContext.PopulationFlags.CREATOR_AND_NOTIFIER);
Direction facing = Direction.NORTH;
Vector3i left = Vector3i.UNIT_X;
final Optional<Entity> optSource = context.first(Entity.class);
if (optSource.isPresent()) {
final Entity source = optSource.get();
final Vector3d rotVector;
if (source instanceof Living) {
rotVector = ((Living) source).getHeadRotation();
} else {
rotVector = optSource.get().getRotation();
}
// Calculate the direction the entity is looking
final Vector3d dir = Quaternions.fromAxesAnglesDeg(rotVector.mul(-1)).rotate(Vector3d.FORWARD);
facing = Direction.getClosestHorizontal(dir, Direction.Division.CARDINAL);
left = LEFT_ANGLE.rotate(facing.asOffset()).toInt();
facing = facing.getOpposite();
}
builder.add(Keys.DIRECTION, facing);
// TODO: Hinges
context.addBlockChange(builder.location(location).build());
context.addBlockChange(builder.add(LanternKeys.DOOR_HALF, LanternDoorHalf.UPPER).location(up).build());
return BehaviorResult.SUCCESS;
}
use of org.spongepowered.api.data.property.block.ReplaceableProperty in project LanternServer by LanternPowered.
the class ShulkerBoxInteractionBehavior method validateOpenableSpace.
@Override
protected boolean validateOpenableSpace(BehaviorContext context, Location<World> location, List<Runnable> tasks) {
final Direction facing = location.getBlock().getTraitValue(LanternEnumTraits.FACING).get();
final Location<World> relLocation = location.getBlockRelative(facing);
final AABB aabb = relLocation.getExtent().getBlockSelectionBox(relLocation.getBlockPosition()).orElse(null);
if (aabb != null && getExtendedAABB(facing).offset(relLocation.getBlockPosition()).intersects(aabb)) {
final ReplaceableProperty replaceableProperty = relLocation.getProperty(ReplaceableProperty.class).orElse(null);
// Replaceable blocks will be replaced when opened
if (replaceableProperty != null && replaceableProperty.getValue()) {
tasks.add(() -> context.addBlockChange(BlockSnapshotBuilder.create().location(relLocation).blockState(BlockTypes.AIR.getDefaultState()).build()));
// TODO: Use break block pipeline instead
return true;
}
return false;
}
return true;
}
Aggregations