use of org.spongepowered.api.data.type.BodyPart in project SpongeCommon by SpongePowered.
the class ArmorStandBodyPartRotationalDataProcessor method set.
@Override
protected boolean set(EntityArmorStand dataHolder, Map<Key<?>, Object> keyValues) {
@SuppressWarnings("unchecked") Map<BodyPart, Vector3d> bodyRotations = (Map<BodyPart, Vector3d>) keyValues.get(Keys.BODY_ROTATIONS);
Vector3d headRotation = getValueFromTwoMapsOrUseFallback(keyValues, Keys.HEAD_ROTATION, bodyRotations, BodyParts.HEAD, DataConstants.DEFAULT_HEAD_ROTATION);
Vector3d chestRotation = getValueFromTwoMapsOrUseFallback(keyValues, Keys.CHEST_ROTATION, bodyRotations, BodyParts.CHEST, DataConstants.DEFAULT_CHEST_ROTATION);
Vector3d leftArmRotation = getValueFromTwoMapsOrUseFallback(keyValues, Keys.LEFT_ARM_ROTATION, bodyRotations, BodyParts.LEFT_ARM, DataConstants.DEFAULT_LEFT_ARM_ROTATION);
Vector3d rightArmRotation = getValueFromTwoMapsOrUseFallback(keyValues, Keys.RIGHT_ARM_ROTATION, bodyRotations, BodyParts.RIGHT_ARM, DataConstants.DEFAULT_RIGHT_ARM_ROTATION);
Vector3d leftLegRotation = getValueFromTwoMapsOrUseFallback(keyValues, Keys.LEFT_LEG_ROTATION, bodyRotations, BodyParts.LEFT_LEG, DataConstants.DEFAULT_LEFT_LEG_ROTATION);
Vector3d rightLegRotation = getValueFromTwoMapsOrUseFallback(keyValues, Keys.RIGHT_LEG_ROTATION, bodyRotations, BodyParts.RIGHT_LEG, DataConstants.DEFAULT_RIGHT_LEG_ROTATION);
dataHolder.setHeadRotation(VecHelper.toRotation(headRotation));
dataHolder.setBodyRotation(VecHelper.toRotation(chestRotation));
dataHolder.setLeftArmRotation(VecHelper.toRotation(leftArmRotation));
dataHolder.setRightArmRotation(VecHelper.toRotation(rightArmRotation));
dataHolder.setLeftLegRotation(VecHelper.toRotation(leftLegRotation));
dataHolder.setRightLegRotation(VecHelper.toRotation(rightLegRotation));
return true;
}
use of org.spongepowered.api.data.type.BodyPart in project SpongeCommon by SpongePowered.
the class ArmorStandBodyPartRotationalDataProcessor method fill.
@Override
public Optional<BodyPartRotationalData> fill(DataContainer container, BodyPartRotationalData data) {
if (!container.contains(Keys.BODY_ROTATIONS.getQuery(), Keys.HEAD_ROTATION.getQuery(), Keys.CHEST_ROTATION.getQuery(), Keys.LEFT_ARM_ROTATION.getQuery(), Keys.RIGHT_ARM_ROTATION.getQuery(), Keys.LEFT_LEG_ROTATION.getQuery(), Keys.RIGHT_LEG_ROTATION.getQuery())) {
return Optional.empty();
}
@SuppressWarnings("unchecked") Map<BodyPart, Vector3d> bodyRotations = (Map<BodyPart, Vector3d>) container.getMap(Keys.BODY_ROTATIONS.getQuery()).get();
Vector3d headRotation = DataUtil.getPosition3d(container, Keys.HEAD_ROTATION.getQuery());
Vector3d chestRotation = DataUtil.getPosition3d(container, Keys.CHEST_ROTATION.getQuery());
Vector3d leftArmRotation = DataUtil.getPosition3d(container, Keys.LEFT_ARM_ROTATION.getQuery());
Vector3d rightArmRotation = DataUtil.getPosition3d(container, Keys.RIGHT_ARM_ROTATION.getQuery());
Vector3d leftLegRotation = DataUtil.getPosition3d(container, Keys.LEFT_LEG_ROTATION.getQuery());
Vector3d rightLegRotation = DataUtil.getPosition3d(container, Keys.RIGHT_LEG_ROTATION.getQuery());
data.set(Keys.BODY_ROTATIONS, bodyRotations);
data.set(Keys.HEAD_ROTATION, headRotation);
data.set(Keys.CHEST_ROTATION, chestRotation);
data.set(Keys.LEFT_ARM_ROTATION, leftArmRotation);
data.set(Keys.RIGHT_ARM_ROTATION, rightArmRotation);
data.set(Keys.LEFT_LEG_ROTATION, leftLegRotation);
data.set(Keys.RIGHT_LEG_ROTATION, rightLegRotation);
return Optional.of(data);
}
use of org.spongepowered.api.data.type.BodyPart in project LanternServer by LanternPowered.
the class DataRegistrar method setupRegistrations.
public static void setupRegistrations(LanternGame game) {
Copyable.register(ImmutableMap.class, map -> map);
Copyable.register(ImmutableList.class, list -> list);
Copyable.register(ImmutableSet.class, set -> set);
Copyable.register(List.class, ArrayList::new);
Copyable.register(Set.class, HashSet::new);
Copyable.register(Map.class, HashMap::new);
final PropertyRegistry propertyRegistry = game.getPropertyRegistry();
// Block property stores
propertyRegistry.register(SkyLuminanceProperty.class, new SkyLuminancePropertyStore());
propertyRegistry.register(GroundLuminanceProperty.class, new GroundLuminancePropertyStore());
// Entity property stores
propertyRegistry.register(DominantHandProperty.class, new DominantHandPropertyStore());
// Item property stores
propertyRegistry.register(SmeltableProperty.class, new SmeltablePropertyStore());
propertyRegistry.register(BurningFuelProperty.class, new BurningFuelPropertyStore());
final LanternDataManager dataManager = game.getDataManager();
// Register the data type serializers
DataTypeSerializers.registerSerializers(dataManager);
// Register the data serializers
DataTranslators.registerSerializers(dataManager);
// Register the data builders
dataManager.registerBuilder(PatternLayer.class, new LanternPatternLayer.Builder(game));
dataManager.registerBuilder(Text.class, new TextConfigSerializer());
dataManager.registerBuilder(BookView.class, new BookViewDataBuilder());
dataManager.registerBuilder(PotionEffect.class, new LanternPotionEffectBuilder());
dataManager.registerBuilder(RespawnLocation.class, new RespawnLocation.Builder());
dataManager.registerBuilder(Enchantment.class, new LanternEnchantmentBuilder());
final LanternValueFactory valueFactory = LanternValueFactory.get();
valueFactory.registerKey(Keys.CONNECTED_DIRECTIONS).add(builder -> builder.applicableTester(valueContainer -> valueContainer.supports(Keys.CONNECTED_WEST) || valueContainer.supports(Keys.CONNECTED_EAST) || valueContainer.supports(Keys.CONNECTED_NORTH) || valueContainer.supports(Keys.CONNECTED_SOUTH)).retrieveHandler((valueContainer, key) -> {
final Set<Direction> directions = new HashSet<>();
if (valueContainer.get(Keys.CONNECTED_WEST).orElse(false)) {
directions.add(Direction.WEST);
}
if (valueContainer.get(Keys.CONNECTED_EAST).orElse(false)) {
directions.add(Direction.EAST);
}
if (valueContainer.get(Keys.CONNECTED_SOUTH).orElse(false)) {
directions.add(Direction.SOUTH);
}
if (valueContainer.get(Keys.CONNECTED_NORTH).orElse(false)) {
directions.add(Direction.NORTH);
}
return Optional.of(directions);
}).offerHandler((valueContainer, key, directions) -> {
if (valueContainer instanceof ICompositeValueStore) {
final ICompositeValueStore store = (ICompositeValueStore) valueContainer;
final DataTransactionResult.Builder resultBuilder = DataTransactionResult.builder();
resultBuilder.absorbResult(store.offerNoEvents(Keys.CONNECTED_WEST, directions.contains(Direction.WEST)));
resultBuilder.absorbResult(store.offerNoEvents(Keys.CONNECTED_EAST, directions.contains(Direction.EAST)));
resultBuilder.absorbResult(store.offerNoEvents(Keys.CONNECTED_SOUTH, directions.contains(Direction.SOUTH)));
resultBuilder.absorbResult(store.offerNoEvents(Keys.CONNECTED_NORTH, directions.contains(Direction.NORTH)));
return resultBuilder.result(DataTransactionResult.Type.SUCCESS).build();
}
return DataTransactionResult.successNoData();
}).failAlwaysRemoveHandler());
valueFactory.registerKey(Keys.WIRE_ATTACHMENTS).add(builder -> builder.applicableTester(valueContainer -> valueContainer.supports(Keys.WIRE_ATTACHMENT_WEST) || valueContainer.supports(Keys.WIRE_ATTACHMENT_EAST) || valueContainer.supports(Keys.WIRE_ATTACHMENT_NORTH) || valueContainer.supports(Keys.WIRE_ATTACHMENT_SOUTH)).retrieveHandler((valueContainer, key) -> {
final Map<Direction, WireAttachmentType> attachments = new HashMap<>();
valueContainer.get(Keys.WIRE_ATTACHMENT_WEST).ifPresent(type -> attachments.put(Direction.WEST, type));
valueContainer.get(Keys.WIRE_ATTACHMENT_EAST).ifPresent(type -> attachments.put(Direction.EAST, type));
valueContainer.get(Keys.WIRE_ATTACHMENT_SOUTH).ifPresent(type -> attachments.put(Direction.SOUTH, type));
valueContainer.get(Keys.WIRE_ATTACHMENT_NORTH).ifPresent(type -> attachments.put(Direction.NORTH, type));
return Optional.of(attachments);
}).offerHandler((key, valueContainer, attachments) -> {
if (valueContainer instanceof ICompositeValueStore) {
final ICompositeValueStore store = (ICompositeValueStore) valueContainer;
final DataTransactionResult.Builder resultBuilder = DataTransactionResult.builder();
WireAttachmentType type = attachments.get(Direction.WEST);
resultBuilder.absorbResult(store.offerNoEvents(Keys.CONNECTED_WEST, type == null ? WireAttachmentTypes.NONE : type));
type = attachments.get(Direction.EAST);
resultBuilder.absorbResult(store.offerNoEvents(Keys.CONNECTED_EAST, type == null ? WireAttachmentTypes.NONE : type));
type = attachments.get(Direction.SOUTH);
resultBuilder.absorbResult(store.offerNoEvents(Keys.CONNECTED_SOUTH, type == null ? WireAttachmentTypes.NONE : type));
type = attachments.get(Direction.NORTH);
resultBuilder.absorbResult(store.offerNoEvents(Keys.CONNECTED_NORTH, type == null ? WireAttachmentTypes.NONE : type));
return resultBuilder.result(DataTransactionResult.Type.SUCCESS).build();
}
return DataTransactionResult.successNoData();
}).failAlwaysRemoveHandler());
valueFactory.registerKey(Keys.BODY_ROTATIONS).add(builder -> builder.applicableTester(valueContainer -> valueContainer.supports(Keys.RIGHT_ARM_ROTATION) || valueContainer.supports(Keys.LEFT_ARM_ROTATION) || valueContainer.supports(Keys.RIGHT_LEG_ROTATION) || valueContainer.supports(Keys.LEFT_LEG_ROTATION) || valueContainer.supports(Keys.HEAD_ROTATION) || valueContainer.supports(Keys.CHEST_ROTATION)).retrieveHandler((valueContainer, key) -> {
final Map<BodyPart, Vector3d> rotations = new HashMap<>();
valueContainer.get(Keys.RIGHT_ARM_ROTATION).ifPresent(type -> rotations.put(BodyParts.RIGHT_ARM, type));
valueContainer.get(Keys.RIGHT_LEG_ROTATION).ifPresent(type -> rotations.put(BodyParts.RIGHT_LEG, type));
valueContainer.get(Keys.LEFT_ARM_ROTATION).ifPresent(type -> rotations.put(BodyParts.LEFT_ARM, type));
valueContainer.get(Keys.LEFT_LEG_ROTATION).ifPresent(type -> rotations.put(BodyParts.LEFT_LEG, type));
valueContainer.get(Keys.HEAD_ROTATION).ifPresent(type -> rotations.put(BodyParts.HEAD, type));
valueContainer.get(Keys.CHEST_ROTATION).ifPresent(type -> rotations.put(BodyParts.CHEST, type));
return Optional.of(rotations);
}).offerHandler((key, valueContainer, rotations) -> {
if (valueContainer instanceof CompositeValueStore) {
final ICompositeValueStore store = (ICompositeValueStore) valueContainer;
final DataTransactionResult.Builder resultBuilder = DataTransactionResult.builder();
Vector3d rot;
if ((rot = rotations.get(BodyParts.RIGHT_ARM)) != null) {
resultBuilder.absorbResult(store.offerNoEvents(Keys.RIGHT_ARM_ROTATION, rot));
}
if ((rot = rotations.get(BodyParts.RIGHT_LEG)) != null) {
resultBuilder.absorbResult(store.offerNoEvents(Keys.RIGHT_LEG_ROTATION, rot));
}
if ((rot = rotations.get(BodyParts.LEFT_ARM)) != null) {
resultBuilder.absorbResult(store.offerNoEvents(Keys.LEFT_ARM_ROTATION, rot));
}
if ((rot = rotations.get(BodyParts.LEFT_LEG)) != null) {
resultBuilder.absorbResult(store.offerNoEvents(Keys.LEFT_LEG_ROTATION, rot));
}
if ((rot = rotations.get(BodyParts.HEAD)) != null) {
resultBuilder.absorbResult(store.offerNoEvents(Keys.HEAD_ROTATION, rot));
}
if ((rot = rotations.get(BodyParts.CHEST)) != null) {
resultBuilder.absorbResult(store.offerNoEvents(Keys.CHEST_ROTATION, rot));
}
return resultBuilder.result(DataTransactionResult.Type.SUCCESS).build();
}
return DataTransactionResult.successNoData();
}).failAlwaysRemoveHandler());
DataManipulatorRegistry.get();
}
Aggregations