use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.
the class SpongeRegistryLoaders method valueParameter.
@SuppressWarnings("ConstantConditions")
public static RegistryLoader<ValueParameter<?>> valueParameter() {
return RegistryLoader.of(l -> {
l.add(ResourceKeyedValueParameters.BIG_DECIMAL, SpongeBigDecimalValueParameter::new);
l.add(ResourceKeyedValueParameters.BIG_INTEGER, SpongeBigIntegerValueParameter::new);
l.add(ResourceKeyedValueParameters.BLOCK_STATE, k -> ClientNativeArgumentParser.createConverter(k, BlockStateArgument.block(), (reader, cause, state) -> (BlockState) state.getState()));
l.add(ResourceKeyedValueParameters.BOOLEAN, k -> ClientNativeArgumentParser.createIdentity(k, BoolArgumentType.bool()));
l.add(ResourceKeyedValueParameters.COLOR, SpongeColorValueParameter::new);
l.add(ResourceKeyedValueParameters.DATA_CONTAINER, SpongeDataContainerValueParameter::new);
l.add(ResourceKeyedValueParameters.DATE_TIME, SpongeDateTimeValueParameter::new);
l.add(ResourceKeyedValueParameters.DOUBLE, k -> ClientNativeArgumentParser.createIdentity(k, DoubleArgumentType.doubleArg()));
l.add(ResourceKeyedValueParameters.DURATION, SpongeDurationValueParameter::new);
l.add(ResourceKeyedValueParameters.ENTITY, k -> ClientNativeArgumentParser.createConverter(k, EntityArgument.entity(), (reader, cause, selector) -> (Entity) selector.findSingleEntity((CommandSourceStack) cause)));
l.add(ResourceKeyedValueParameters.GAME_PROFILE, SpongeGameProfileValueParameter::new);
l.add(ResourceKeyedValueParameters.INTEGER, k -> ClientNativeArgumentParser.createIdentity(k, IntegerArgumentType.integer()));
l.add(ResourceKeyedValueParameters.IP, SpongeIPAddressValueParameter::new);
l.add(ResourceKeyedValueParameters.ITEM_STACK_SNAPSHOT, k -> ClientNativeArgumentParser.createConverter(k, ItemArgument.item(), (reader, cause, converter) -> new SpongeItemStackSnapshot((ItemStack) (Object) converter.createItemStack(1, true))));
l.add(ResourceKeyedValueParameters.LOCATION, SpongeServerLocationValueParameter::new);
l.add(ResourceKeyedValueParameters.LONG, k -> ClientNativeArgumentParser.createIdentity(k, LongArgumentType.longArg()));
l.add(ResourceKeyedValueParameters.MANY_ENTITIES, k -> ClientNativeArgumentParser.createConverter(k, EntityArgument.entities(), (reader, cause, selector) -> selector.findEntities((CommandSourceStack) cause).stream().map(x -> (Entity) x).collect(Collectors.toList())));
l.add(ResourceKeyedValueParameters.MANY_GAME_PROFILES, k -> ClientNativeArgumentParser.createConverter(k, GameProfileArgument.gameProfile(), (reader, cause, converter) -> converter.getNames((CommandSourceStack) cause)));
l.add(ResourceKeyedValueParameters.MANY_PLAYERS, k -> ClientNativeArgumentParser.createConverter(k, EntityArgument.players(), (reader, cause, selector) -> selector.findPlayers((CommandSourceStack) cause)));
l.add(ResourceKeyedValueParameters.NONE, SpongeNoneValueParameter::new);
l.add(ResourceKeyedValueParameters.OPERATOR, SpongeOperatorValueParameter::new);
l.add(ResourceKeyedValueParameters.PLAYER, k -> ClientNativeArgumentParser.createConverter(k, EntityArgument.player(), (reader, cause, selector) -> (Player) selector.findSinglePlayer((CommandSourceStack) cause)));
l.add(ResourceKeyedValueParameters.PLUGIN, SpongePluginContainerValueParameter::new);
l.add(ResourceKeyedValueParameters.REMAINING_JOINED_STRINGS, k -> ClientNativeArgumentParser.createIdentity(k, StringArgumentType.greedyString()));
l.add(ResourceKeyedValueParameters.RESOURCE_KEY, k -> ClientNativeArgumentParser.createConverter(k, ResourceLocationArgument.id(), (reader, cause, resourceLocation) -> (ResourceKey) (Object) resourceLocation));
l.add(ResourceKeyedValueParameters.ROTATION, k -> ClientNativeArgumentParser.createConverter(k, RotationArgument.rotation(), (reader, cause, coords) -> {
final Vec2 rotation = coords.getRotation((CommandSourceStack) cause);
return new Vector3d(rotation.x, rotation.y, 0);
}));
l.add(ResourceKeyedValueParameters.STRING, k -> ClientNativeArgumentParser.createIdentity(k, StringArgumentType.string()));
l.add(ResourceKeyedValueParameters.TARGET_BLOCK, SpongeTargetBlockValueParameter::new);
l.add(ResourceKeyedValueParameters.TARGET_ENTITY, k -> new SpongeTargetEntityValueParameter(k, false));
l.add(ResourceKeyedValueParameters.TARGET_PLAYER, k -> new SpongeTargetEntityValueParameter(k, true));
l.add(ResourceKeyedValueParameters.TEXT_FORMATTING_CODE, k -> ClientNativeArgumentParser.createConverter(k, StringArgumentType.string(), (reader, cause, result) -> LegacyComponentSerializer.legacyAmpersand().deserialize(result)));
l.add(ResourceKeyedValueParameters.TEXT_FORMATTING_CODE_ALL, k -> ClientNativeArgumentParser.createConverter(k, StringArgumentType.greedyString(), (reader, cause, result) -> LegacyComponentSerializer.legacyAmpersand().deserialize(result)));
l.add(ResourceKeyedValueParameters.TEXT_JSON, k -> ClientNativeArgumentParser.createConverter(k, ComponentArgument.textComponent(), (reader, cause, result) -> SpongeAdventure.asAdventure(result)));
l.add(ResourceKeyedValueParameters.TEXT_JSON_ALL, k -> ClientNativeArgumentParser.createConverter(k, StringArgumentType.greedyString(), (reader, cause, result) -> GsonComponentSerializer.gson().deserialize(result)));
l.add(ResourceKeyedValueParameters.URL, k -> ClientNativeArgumentParser.createConverter(k, StringArgumentType.string(), (reader, cause, input) -> {
try {
return new URL(input);
} catch (final MalformedURLException ex) {
throw new SimpleCommandExceptionType(new TextComponent("Could not parse " + input + " as a URL")).createWithContext(reader);
}
}));
l.add(ResourceKeyedValueParameters.USER, SpongeUserValueParameter::new);
l.add(ResourceKeyedValueParameters.UUID, k -> ClientNativeArgumentParser.createIdentity(k, UuidArgument.uuid()));
l.add(ResourceKeyedValueParameters.VECTOR2D, k -> ClientNativeArgumentParser.createConverter(k, Vec2Argument.vec2(), (reader, cause, result) -> {
final net.minecraft.world.phys.Vec3 r = result.getPosition((CommandSourceStack) cause);
return new Vector2d(r.x, r.z);
}));
l.add(ResourceKeyedValueParameters.VECTOR3D, k -> ClientNativeArgumentParser.createConverter(k, Vec3Argument.vec3(false), (reader, cause, result) -> VecHelper.toVector3d(result.getPosition((CommandSourceStack) cause))));
l.add(ResourceKeyedValueParameters.WORLD, k -> ClientNativeArgumentParser.createConverter(k, DimensionArgument.dimension(), (reader, cause, result) -> Sponge.server().worldManager().world((ResourceKey) (Object) result).orElseThrow(() -> DimensionArgumentAccessor.accessor$ERROR_INVALID_VALUE().createWithContext(reader, result))));
});
}
use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.
the class AbstractReferentArchetypeVolume method addEntity.
@Override
public void addEntity(final EntityArchetypeEntry entry) {
final Vector3d position = entry.position();
final Vector3i transformed = this.inverseTransform(position.x(), position.y(), position.z());
this.consumeReference(a -> a.addEntity(entry.archetype(), transformed.toDouble()));
}
use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.
the class SpongeArchetypeVolume method blockStateStream.
@Override
public VolumeStream<ArchetypeVolume, BlockState> blockStateStream(final Vector3i min, final Vector3i max, final StreamOptions options) {
final Vector3i blockMin = this.min();
final Vector3i blockMax = this.max();
VolumeStreamUtils.validateStreamArgs(min, max, blockMin, blockMax, options);
final ArrayMutableBlockBuffer buffer;
if (options.carbonCopy()) {
buffer = this.blocks.copy();
} else {
buffer = this.blocks;
}
final Stream<VolumeElement<ArchetypeVolume, BlockState>> stateStream = IntStream.range(min.x(), max.x() + 1).mapToObj(x -> IntStream.range(min.z(), max.z() + 1).mapToObj(z -> IntStream.range(min.y(), max.y() + 1).mapToObj(y -> VolumeElement.of((ArchetypeVolume) this, () -> buffer.block(x, y, z), new Vector3d(x, y, z)))).flatMap(Function.identity())).flatMap(Function.identity());
return new SpongeVolumeStream<>(stateStream, () -> this);
}
use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.
the class NetherPortalType method portalObjectFromRectangle.
public static Portal portalObjectFromRectangle(final ServerWorld world, final BlockUtil.FoundRectangle x) {
final Vector3d minCornerVec = VecHelper.toVector3d(x.minCorner);
final ServerLocation minCorner = world.location(minCornerVec);
@Nullable final Axis axis = minCorner.block().getOrNull(Keys.AXIS);
if (axis == null) {
return new VanillaPortal(PortalTypes.NETHER.get(), minCorner, null);
}
final ServerLocation maxCorner;
if (axis == Axis.X) {
maxCorner = minCorner.withPosition(minCornerVec.add(x.axis1Size, x.axis2Size, 0));
} else {
// it's z
maxCorner = minCorner.withPosition(minCornerVec.add(0, x.axis2Size, x.axis1Size));
}
return new VanillaTwoDimensionalPortal(PortalTypes.NETHER.get(), minCorner, maxCorner, null);
}
use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.
the class BlockMixin method impl$throwConstructPreEvent.
@Inject(method = "popResource", at = @At(value = "NEW", target = "Lnet/minecraft/world/entity/item/ItemEntity;<init>(Lnet/minecraft/world/level/Level;DDDLnet/minecraft/world/item/ItemStack;)V"), cancellable = true, locals = LocalCapture.CAPTURE_FAILSOFT, require = 0, expect = 0)
private static void impl$throwConstructPreEvent(final Level level, final BlockPos pos, final ItemStack stack, final CallbackInfo ci, final float unused, final double xOffset, final double yOffset, final double zOffset) {
if (!ShouldFire.CONSTRUCT_ENTITY_EVENT_PRE) {
return;
}
final double xPos = (double) pos.getX() + xOffset;
final double yPos = (double) pos.getY() + yOffset;
final double zPos = (double) pos.getZ() + zOffset;
// Go ahead and throw the construction event
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(level.getBlockState(pos));
final ConstructEntityEvent.Pre eventPre = SpongeEventFactory.createConstructEntityEventPre(frame.currentCause(), ServerLocation.of((ServerWorld) level, xPos, yPos, zPos), new Vector3d(0, 0, 0), EntityTypes.ITEM.get());
SpongeCommon.post(eventPre);
if (eventPre.isCancelled()) {
ci.cancel();
}
}
}
Aggregations