use of org.spongepowered.api.data.type.NotePitch in project SpongeCommon by SpongePowered.
the class SpongeParticleHelper method toCachedPacket.
private static ICachedParticleEffect toCachedPacket(SpongeParticleEffect effect) {
SpongeParticleType type = effect.getType();
EnumParticleTypes internal = type.getInternalType();
// Special cases
if (internal == null) {
if (type == ParticleTypes.FIREWORKS) {
final List<FireworkEffect> effects = type.getDefaultOption(ParticleOptions.FIREWORK_EFFECTS).get();
if (effects.isEmpty()) {
return EmptyCachedPacket.INSTANCE;
}
final net.minecraft.item.ItemStack itemStack = new net.minecraft.item.ItemStack(Items.FIREWORKS);
FireworkUtils.setFireworkEffects(itemStack, effects);
final SPacketEntityMetadata packetEntityMetadata = new SPacketEntityMetadata();
packetEntityMetadata.entityId = CachedFireworkPacket.FIREWORK_ROCKET_ID;
packetEntityMetadata.dataManagerEntries = new ArrayList<>();
packetEntityMetadata.dataManagerEntries.add(new EntityDataManager.DataEntry<>(EntityFireworkRocket.FIREWORK_ITEM, itemStack));
return new CachedFireworkPacket(packetEntityMetadata);
}
if (type == ParticleTypes.FERTILIZER) {
int quantity = effect.getOptionOrDefault(ParticleOptions.QUANTITY).get();
return new CachedEffectPacket(2005, quantity, false);
} else if (type == ParticleTypes.SPLASH_POTION) {
Potion potion = (Potion) effect.getOptionOrDefault(ParticleOptions.POTION_EFFECT_TYPE).get();
for (PotionType potionType : PotionType.REGISTRY) {
for (net.minecraft.potion.PotionEffect potionEffect : potionType.getEffects()) {
if (potionEffect.getPotion() == potion) {
return new CachedEffectPacket(2002, PotionType.REGISTRY.getIDForObject(potionType), false);
}
}
}
return EmptyCachedPacket.INSTANCE;
} else if (type == ParticleTypes.BREAK_BLOCK) {
int state = getBlockState(effect, type.getDefaultOption(ParticleOptions.BLOCK_STATE));
if (state == 0) {
return EmptyCachedPacket.INSTANCE;
}
return new CachedEffectPacket(2001, state, false);
} else if (type == ParticleTypes.MOBSPAWNER_FLAMES) {
return new CachedEffectPacket(2004, 0, false);
} else if (type == ParticleTypes.ENDER_TELEPORT) {
return new CachedEffectPacket(2003, 0, false);
} else if (type == ParticleTypes.DRAGON_BREATH_ATTACK) {
return new CachedEffectPacket(2006, 0, false);
} else if (type == ParticleTypes.FIRE_SMOKE) {
final Direction direction = effect.getOptionOrDefault(ParticleOptions.DIRECTION).get();
return new CachedEffectPacket(2000, getDirectionData(direction), false);
}
return EmptyCachedPacket.INSTANCE;
}
Vector3f offset = effect.getOption(ParticleOptions.OFFSET).map(Vector3d::toFloat).orElse(Vector3f.ZERO);
int quantity = effect.getOption(ParticleOptions.QUANTITY).orElse(1);
int[] extra = null;
// The extra values, normal behavior offsetX, offsetY, offsetZ
double f0 = 0f;
double f1 = 0f;
double f2 = 0f;
// Depends on behavior
// Note: If the count > 0 -> speed = 0f else if count = 0 -> speed = 1f
Optional<BlockState> defaultBlockState;
if (internal != EnumParticleTypes.ITEM_CRACK && (defaultBlockState = type.getDefaultOption(ParticleOptions.BLOCK_STATE)).isPresent()) {
int state = getBlockState(effect, defaultBlockState);
if (state == 0) {
return EmptyCachedPacket.INSTANCE;
}
extra = new int[] { state };
}
Optional<ItemStackSnapshot> defaultSnapshot;
if (extra == null && (defaultSnapshot = type.getDefaultOption(ParticleOptions.ITEM_STACK_SNAPSHOT)).isPresent()) {
Optional<ItemStackSnapshot> optSnapshot = effect.getOption(ParticleOptions.ITEM_STACK_SNAPSHOT);
if (optSnapshot.isPresent()) {
ItemStackSnapshot snapshot = optSnapshot.get();
extra = new int[] { Item.getIdFromItem((Item) snapshot.getType()), ((SpongeItemStackSnapshot) snapshot).getDamageValue() };
} else {
Optional<BlockState> optBlockState = effect.getOption(ParticleOptions.BLOCK_STATE);
if (optBlockState.isPresent()) {
BlockState blockState = optBlockState.get();
Optional<ItemType> optItemType = blockState.getType().getItem();
if (optItemType.isPresent()) {
extra = new int[] { Item.getIdFromItem((Item) optItemType.get()), ((Block) blockState.getType()).getMetaFromState((IBlockState) blockState) };
} else {
return EmptyCachedPacket.INSTANCE;
}
} else {
ItemStackSnapshot snapshot = defaultSnapshot.get();
extra = new int[] { Item.getIdFromItem((Item) snapshot.getType()), ((SpongeItemStackSnapshot) snapshot).getDamageValue() };
}
}
}
if (extra == null) {
extra = new int[0];
}
Optional<Double> defaultScale = type.getDefaultOption(ParticleOptions.SCALE);
Optional<Color> defaultColor;
Optional<NotePitch> defaultNote;
Optional<Vector3d> defaultVelocity;
if (defaultScale.isPresent()) {
double scale = effect.getOption(ParticleOptions.SCALE).orElse(defaultScale.get());
// Server formula: sizeServer = (-sizeClient * 2) + 2
if (internal == EnumParticleTypes.EXPLOSION_LARGE || internal == EnumParticleTypes.SWEEP_ATTACK) {
scale = (-scale * 2f) + 2f;
}
if (scale == 0f) {
return new CachedParticlePacket(internal, offset, quantity, extra);
}
f0 = scale;
} else if ((defaultColor = type.getDefaultOption(ParticleOptions.COLOR)).isPresent()) {
Color color = effect.getOption(ParticleOptions.COLOR).orElse(null);
boolean isSpell = internal == EnumParticleTypes.SPELL_MOB || internal == EnumParticleTypes.SPELL_MOB_AMBIENT;
if (!isSpell && (color == null || color.equals(defaultColor.get()))) {
return new CachedParticlePacket(internal, offset, quantity, extra);
} else if (isSpell && color == null) {
color = defaultColor.get();
}
f0 = color.getRed() / 255f;
f1 = color.getGreen() / 255f;
f2 = color.getBlue() / 255f;
// but we already chose for the color, can't have both
if (isSpell) {
f0 = Math.max(f0, 0.001f);
f2 = Math.max(f0, 0.001f);
}
// If the f0 value 0 is, the redstone will set it automatically to red 255
if (f0 == 0f && internal == EnumParticleTypes.REDSTONE) {
f0 = 0.00001f;
}
} else if ((defaultNote = type.getDefaultOption(ParticleOptions.NOTE)).isPresent()) {
NotePitch notePitch = effect.getOption(ParticleOptions.NOTE).orElse(defaultNote.get());
float note = ((SpongeNotePitch) notePitch).getByteId();
if (note == 0f) {
return new CachedParticlePacket(internal, offset, quantity, extra);
}
f0 = note / 24f;
} else if ((defaultVelocity = type.getDefaultOption(ParticleOptions.VELOCITY)).isPresent()) {
Vector3d velocity = effect.getOption(ParticleOptions.VELOCITY).orElse(defaultVelocity.get());
f0 = velocity.getX();
f1 = velocity.getY();
f2 = velocity.getZ();
Optional<Boolean> slowHorizontalVelocity = type.getDefaultOption(ParticleOptions.SLOW_HORIZONTAL_VELOCITY);
if (slowHorizontalVelocity.isPresent() && effect.getOption(ParticleOptions.SLOW_HORIZONTAL_VELOCITY).orElse(slowHorizontalVelocity.get())) {
f0 = 0f;
f2 = 0f;
}
// The y value won't work for this effect, if the value isn't 0 the velocity won't work
if (internal == EnumParticleTypes.WATER_SPLASH) {
f1 = 0f;
}
if (f0 == 0f && f1 == 0f && f2 == 0f) {
return new CachedParticlePacket(internal, offset, quantity, extra);
}
}
// Is this check necessary?
if (f0 == 0f && f1 == 0f && f2 == 0f) {
return new CachedParticlePacket(internal, offset, quantity, extra);
}
return new CachedOffsetParticlePacket(internal, new Vector3f(f0, f1, f2), offset, quantity, extra);
}
use of org.spongepowered.api.data.type.NotePitch in project SpongeCommon by SpongePowered.
the class NotePitchRegistryModule method registerDefaults.
@Override
public void registerDefaults() {
RegistryHelper.mapFields(NotePitches.class, input -> {
NotePitch pitch = new SpongeNotePitch((byte) this.notePitchMap.size(), input);
this.notePitchMap.put(input.toLowerCase(Locale.ENGLISH), pitch);
return pitch;
});
}
use of org.spongepowered.api.data.type.NotePitch in project LanternServer by LanternPowered.
the class KeyRegistryModule method registerDefaults.
@Override
public void registerDefaults() {
final CauseStack causeStack = CauseStack.current();
causeStack.pushCause(Lantern.getSpongePlugin());
register(makeMutableBoundedValueKey(Double.class, DataQuery.of("Absorption"), "absorption"));
register(makeValueKey(Boolean.class, of("AffectsSpawning"), "affects_spawning"));
register(makeMutableBoundedValueKey(Integer.class, of("Age"), "age"));
register(makeValueKey(Boolean.class, of("AIEnabled"), "ai_enabled"));
register(makeMutableBoundedValueKey(Integer.class, of("Anger"), "anger"));
register(makeMutableBoundedValueKey(Integer.class, DataQuery.of("AreaEffectCloudAge"), "area_effect_cloud_age"));
register(makeValueKey(Color.class, DataQuery.of("AreaEffectCloudColor"), "area_effect_cloud_color"));
register(makeMutableBoundedValueKey(Integer.class, DataQuery.of("AreaEffectCloudDuration"), "area_effect_cloud_duration"));
register(makeMutableBoundedValueKey(Integer.class, DataQuery.of("AreaEffectCloudDurationOnUse"), "area_effect_cloud_duration_on_use"));
register(makeValueKey(Color.class, DataQuery.of("AreaEffectCloudParticleType"), "area_effect_cloud_particle_type"));
register(makeMutableBoundedValueKey(Double.class, DataQuery.of("AreaEffectCloudRadius"), "area_effect_cloud_radius"));
register(makeMutableBoundedValueKey(Double.class, DataQuery.of("AreaEffectCloudRadiusOnUse"), "area_effect_cloud_radius_on_use"));
register(makeMutableBoundedValueKey(Double.class, DataQuery.of("AreaEffectCloudRadiusPerTick"), "area_effect_cloud_radius_per_tick"));
register(makeMutableBoundedValueKey(Integer.class, DataQuery.of("AreaEffectCloudRadiusReapplicationDelay"), "area_effect_cloud_reapplication_delay"));
register(makeMutableBoundedValueKey(Integer.class, DataQuery.of("AreaEffectCloudWaitTime"), "area_effect_cloud_wait_time"));
register(makeValueKey(Boolean.class, of("ArmorStandHasArms"), "armor_stand_has_arms"));
register(makeValueKey(Boolean.class, of("ArmorStandHasBasePlate"), "armor_stand_has_base_plate"));
register(makeValueKey(Boolean.class, of("ArmorStandIsSmall"), "armor_stand_is_small"));
register(makeValueKey(Boolean.class, of("ArmorStandMarker"), "armor_stand_marker"));
register(makeValueKey(Boolean.class, of("Angry"), "angry"));
register(makeValueKey(Art.class, of("Art"), "art"));
register(makeValueKey(Boolean.class, of("Attached"), "attached"));
register(makeMutableBoundedValueKey(Double.class, of("AttackDamage"), "attack_damage"));
register(makeValueKey(Axis.class, of("Axis"), "axis"));
register(makeValueKey(DyeColor.class, of("BannerBaseColor"), "banner_base_color"));
register(makePatternListKey(of("BannerPatterns"), "banner_patterns"));
register(makeMutableBoundedValueKey(Float.class, of("BaseSize"), "base_size"));
register(makeValueKey(EntitySnapshot.class, of("BaseVehicle"), "base_vehicle"));
register(makeOptionalKey(PotionEffectType.class, of("BeaconPrimaryEffect"), "beacon_primary_effect"));
register(makeOptionalKey(PotionEffectType.class, of("BeaconSecondaryEffect"), "beacon_secondary_effect"));
register(makeValueKey(BigMushroomType.class, of("BigMushroomType"), "big_mushroom_type"));
register(makeMapKeyWithKeyAndValue(BodyPart.class, Vector3d.class, of("BodyRotations"), "body_rotations"));
register(makeValueKey(Text.class, of("BookAuthor"), "book_author"));
register(makeListKey(Text.class, of("BookPages"), "book_pages"));
register(makeSetKey(BlockType.class, of("BreakableBlockTypes"), "breakable_block_types"));
register(makeValueKey(BrickType.class, of("BrickType"), "brick_type"));
register(makeValueKey(Boolean.class, of("CanBreed"), "can_breed"));
register(makeValueKey(Boolean.class, of("CanDropAsItem"), "can_drop_as_item"));
register(makeValueKey(Boolean.class, of("CanFly"), "can_fly"));
register(makeValueKey(Boolean.class, of("CanGrief"), "can_grief"));
register(makeValueKey(Boolean.class, of("CanPlaceAsBlock"), "can_place_as_block"));
register(makeValueKey(Career.class, of("Career"), "career"));
register(makeValueKey(Vector3d.class, of("ChestRotation"), "chest_rotation"));
register(makeValueKey(CoalType.class, of("CoalType"), "coal_type"));
register(makeValueKey(Color.class, of("Color"), "color"));
register(makeValueKey(String.class, of("Command"), "command"));
register(makeValueKey(ComparatorType.class, of("ComparatorType"), "comparator_type"));
register(makeSetKey(Direction.class, of("ConnectedDirections"), "connected_directions"));
register(makeValueKey(Boolean.class, of("ConnectedEast"), "connected_east"));
register(makeValueKey(Boolean.class, of("ConnectedNorth"), "connected_north"));
register(makeValueKey(Boolean.class, of("ConnectedSouth"), "connected_south"));
register(makeValueKey(Boolean.class, of("ConnectedWest"), "connected_west"));
register(makeMutableBoundedValueKey(Integer.class, of("ContainedExperience"), "contained_experience"));
register(makeValueKey(CookedFish.class, of("CookedFish"), "cooked_fish"));
register(makeMutableBoundedValueKey(Integer.class, of("Cooldown"), "cooldown"));
register(makeValueKey(Boolean.class, of("CreeperCharged"), "creeper_charged"));
register(makeValueKey(Boolean.class, of("CriticalHit"), "critical_hit"));
register(makeValueKey(Boolean.class, of("CustomNameVisible"), "custom_name_visible"));
register(makeMapKeyWithKeyAndValue(EntityType.class, Double.class, of("EntityDamageMap"), "damage_entity_map"));
register(makeValueKey(Boolean.class, of("Decayable"), "decayable"));
register(makeMutableBoundedValueKey(Integer.class, of("Delay"), "delay"));
register(makeMutableBoundedValueKey(Integer.class, of("DespawnDelay"), "despawn_delay"));
register(makeValueKey(Direction.class, of("Direction"), "direction"));
register(makeValueKey(DirtType.class, of("DirtType"), "dirt_type"));
register(makeValueKey(Boolean.class, of("Disarmed"), "disarmed"));
register(makeValueKey(DisguisedBlockType.class, of("DisguisedBlockType"), "disguised_block_type"));
register(makeValueKey(Text.class, of("DisplayName"), "display_name"));
register(makeValueKey(HandPreference.class, of("DominantHand"), "dominant_hand"));
register(makeValueKey(DoublePlantType.class, of("DoublePlantType"), "double_plant_type"));
register(makeValueKey(DyeColor.class, of("DyeColor"), "dye_color"));
register(makeValueKey(Boolean.class, of("ElderGuardian"), "elder_guardian"));
register(makeValueKey(Boolean.class, of("EndGatewayAge"), "end_gateway_age"));
register(makeValueKey(Boolean.class, of("EndGatewayTeleportCooldown"), "end_gateway_teleport_cooldown"));
register(makeMutableBoundedValueKey(Double.class, of("Exhaustion"), "exhaustion"));
register(makeValueKey(Boolean.class, of("ExactTeleport"), "exact_teleport"));
register(makeValueKey(Vector3i.class, of("ExitPosition"), "exit_position"));
register(makeImmutableBoundedValueKey(Integer.class, of("ExperienceFromStartOfLevel"), "experience_from_start_of_level"));
register(makeMutableBoundedValueKey(Integer.class, of("ExperienceLevel"), "experience_level"));
register(makeMutableBoundedValueKey(Integer.class, of("ExperienceSinceLevel"), "experience_since_level"));
register(makeMutableBoundedValueKey(Integer.class, of("ExpirationTicks"), "expiration_ticks"));
register(makeOptionalKey(Integer.class, of("ExplosionRadius"), "explosion_radius"));
register(makeValueKey(Boolean.class, of("Extended"), "extended"));
register(makeValueKey(Boolean.class, of("FallingBlockCanHurtEntities"), "falling_block_can_hurt_entities"));
register(makeValueKey(BlockState.class, of("FallingBlockState"), "falling_block_state"));
register(makeMutableBoundedValueKey(Double.class, of("FallDamagePerBlock"), "fall_damage_per_block"));
register(makeMutableBoundedValueKey(Float.class, of("FallDistance"), "fall_distance"));
register(makeValueKey(Integer.class, of("FallTime"), "fall_time"));
register(makeValueKey(Boolean.class, of("Filled"), "filled"));
register(makeListKey(FireworkEffect.class, of("FireworkEffects"), "firework_effects"));
register(makeMutableBoundedValueKey(Integer.class, of("FireworkFlightModifier"), "firework_flight_modifier"));
register(makeMutableBoundedValueKey(Integer.class, of("FireDamageDelay"), "fire_damage_delay"));
register(makeMutableBoundedValueKey(Integer.class, of("FireTicks"), "fire_ticks"));
register(makeValueKey(Instant.class, of("FirstDatePlayed"), "first_date_played"));
register(makeValueKey(Fish.class, of("FishType"), "fish_type"));
register(makeValueKey(FluidStackSnapshot.class, of("FluidItemStack"), "fluid_item_stack"));
register(makeMutableBoundedValueKey(Integer.class, of("FluidLevel"), "fluid_level"));
register(makeMapKeyWithKeyAndValue(Direction.class, List.class, of("FluidTankContents"), "fluid_tank_contents"));
register(makeValueKey(Double.class, of("FlyingSpeed"), "flying_speed"));
register(makeMutableBoundedValueKey(Integer.class, of("FoodLevel"), "food_level"));
register(makeValueKey(Integer.class, of("FuseDuration"), "fuse_duration"));
register(makeValueKey(GameMode.class, of("GameMode"), "game_mode"));
register(makeMutableBoundedValueKey(Integer.class, of("Generation"), "generation"));
register(makeValueKey(Boolean.class, of("Glowing"), "glowing"));
register(makeValueKey(GoldenApple.class, of("GoldenAppleType"), "golden_apple_type"));
register(makeMutableBoundedValueKey(Integer.class, of("GrowthStage"), "growth_stage"));
register(makeValueKey(Boolean.class, of("HasGravity"), "has_gravity"));
register(makeValueKey(Vector3d.class, of("HeadRotation"), "head_rotation"));
register(makeMutableBoundedValueKey(Double.class, of("Health"), "health"));
register(makeMutableBoundedValueKey(Double.class, of("HealthScale"), "health_scale"));
register(makeMutableBoundedValueKey(Float.class, of("Height"), "height"));
register(makeValueKey(Boolean.class, of("HideAttributes"), "hide_attributes"));
register(makeValueKey(Boolean.class, of("HideCanDestroy"), "hide_can_destroy"));
register(makeValueKey(Boolean.class, of("HideCanPlace"), "hide_can_place"));
register(makeValueKey(Boolean.class, of("HideEnchantments"), "hide_enchantments"));
register(makeValueKey(Boolean.class, of("HideMiscellaneous"), "hide_miscellaneous"));
register(makeValueKey(Boolean.class, of("HideUnbreakable"), "hide_unbreakable"));
register(makeValueKey(Hinge.class, of("HingePosition"), "hinge_position"));
register(makeValueKey(HorseColor.class, of("HorseColor"), "horse_color"));
register(makeValueKey(HorseStyle.class, of("HorseStyle"), "horse_style"));
register(makeValueKey(Boolean.class, of("InfiniteDespawnDelay"), "infinite_despawn_delay"));
register(makeValueKey(Boolean.class, of("InfinitePickupDelay"), "infinite_pickup_delay"));
register(makeValueKey(Boolean.class, of("InvisibilityIgnoresCollision"), "invisibility_ignores_collision"));
register(makeValueKey(Boolean.class, of("InvisibilityPreventsTargeting"), "invisibility_prevents_targeting"));
register(makeValueKey(Boolean.class, of("Invisible"), "invisible"));
register(makeMutableBoundedValueKey(Integer.class, of("InvulnerabilityTicks"), "invulnerability_ticks"));
register(makeValueKey(Boolean.class, of("Invulnerable"), "invulnerable"));
register(makeValueKey(Boolean.class, of("InWall"), "in_wall"));
register(makeValueKey(Boolean.class, of("IsAdult"), "is_adult"));
register(makeValueKey(Boolean.class, of("IsAflame"), "is_aflame"));
register(makeValueKey(Boolean.class, of("IsFlying"), "is_flying"));
register(makeValueKey(Boolean.class, of("IsJohnny"), "is_johnny"));
register(makeValueKey(Boolean.class, of("IsPlaying"), "is_playing"));
register(makeValueKey(Boolean.class, of("IsScreaming"), "is_screaming"));
register(makeValueKey(Boolean.class, of("IsSheared"), "is_sheared"));
register(makeValueKey(Boolean.class, of("IsSilent"), "is_silent"));
register(makeValueKey(Boolean.class, of("IsSitting"), "is_sitting"));
register(makeValueKey(Boolean.class, of("IsSleeping"), "is_sleeping"));
register(makeValueKey(Boolean.class, of("IsSneaking"), "is_sneaking"));
register(makeValueKey(Boolean.class, of("IsSprinting"), "is_sprinting"));
register(makeValueKey(Boolean.class, of("IsWet"), "is_wet"));
register(makeValueKey(BlockState.class, of("ItemBlockState"), "item_blockstate"));
register(makeMutableBoundedValueKey(Integer.class, of("ItemDurability"), "item_durability"));
register(makeListKey(Enchantment.class, of("ItemEnchantments"), "item_enchantments"));
register(makeListKey(Text.class, of("ItemLore"), "item_lore"));
register(makeValueKey(Boolean.class, of("JohnnyVindicator"), "johnny_vindicator"));
register(makeMutableBoundedValueKey(Integer.class, of("KnockbackStrength"), "knockback_strength"));
register(makeOptionalKey(EntitySnapshot.class, of("LastAttacker"), "last_attacker"));
register(makeOptionalKey(Text.class, of("LastCommandOutput"), "last_command_output"));
register(makeOptionalKey(Double.class, of("LastDamage"), "last_damage"));
register(makeValueKey(Instant.class, of("LastDatePlayed"), "last_date_played"));
register(makeValueKey(Integer.class, of("Layer"), "layer"));
register(makeValueKey(EntitySnapshot.class, of("LeashHolder"), "leash_holder"));
register(makeValueKey(Vector3d.class, of("LeftArmRotation"), "left_arm_rotation"));
register(makeValueKey(Vector3d.class, of("LeftLegRotation"), "left_leg_rotation"));
register(makeMutableBoundedValueKey(Integer.class, of("LlamaStrength"), "llama_strength"));
register(makeValueKey(LlamaVariant.class, of("LlamaVariant"), "llama_variant"));
register(makeValueKey(String.class, of("LockToken"), "lock_token"));
register(makeValueKey(LogAxis.class, of("LogAxis"), "log_axis"));
register(makeMutableBoundedValueKey(Integer.class, of("MaxAir"), "max_air"));
register(makeMutableBoundedValueKey(Integer.class, of("MaxBurnTime"), "max_burn_time"));
register(makeMutableBoundedValueKey(Integer.class, of("MaxCookTime"), "max_cook_time"));
register(makeMutableBoundedValueKey(Double.class, of("MaxFallDamage"), "max_fall_damage"));
register(makeMutableBoundedValueKey(Double.class, of("MaxHealth"), "max_health"));
register(makeMutableBoundedValueKey(Integer.class, of("Moisture"), "moisture"));
register(makeValueKey(NotePitch.class, of("NotePitch"), "note_pitch"));
register(makeValueKey(Boolean.class, of("Occupied"), "occupied"));
register(makeValueKey(OcelotType.class, of("OcelotType"), "ocelot_type"));
register(makeValueKey(Integer.class, of("Offset"), "offset"));
register(makeValueKey(Boolean.class, of("Open"), "open"));
register(makeMutableBoundedValueKey(Integer.class, of("PassedBurnTime"), "passed_burn_time"));
register(makeMutableBoundedValueKey(Integer.class, of("PassedCookTime"), "passed_cook_time"));
register(makeListKey(UUID.class, of("Passengers"), "passengers"));
register(makeValueKey(Boolean.class, of("Persists"), "persists"));
register(makeMutableBoundedValueKey(Integer.class, of("PickupDelay"), "pickup_delay"));
register(makeValueKey(PickupRule.class, of("PickupRule"), "pickup_rule"));
register(makeValueKey(Boolean.class, of("PigSaddle"), "pig_saddle"));
register(makeValueKey(PistonType.class, of("PistonType"), "piston_type"));
register(makeSetKey(BlockType.class, of("PlaceableBlocks"), "placeable_blocks"));
register(makeValueKey(PlantType.class, of("PlantType"), "plant_type"));
register(makeValueKey(Boolean.class, of("PlayerCreated"), "player_created"));
register(makeValueKey(PortionType.class, of("PortionType"), "portion_type"));
register(makeListKey(PotionEffect.class, of("PotionEffects"), "potion_effects"));
register(makeValueKey(Integer.class, of("Power"), "power"));
register(makeValueKey(Boolean.class, of("Powered"), "powered"));
register(makeValueKey(PrismarineType.class, of("PrismarineType"), "prismarine_type"));
register(makeValueKey(QuartzType.class, of("QuartzType"), "quartz_type"));
register(makeValueKey(RabbitType.class, of("RabbitType"), "rabbit_type"));
register(makeValueKey(RailDirection.class, of("RailDirection"), "rail_direction"));
register(makeMutableBoundedValueKey(Integer.class, of("RemainingAir"), "remaining_air"));
register(makeMutableBoundedValueKey(Integer.class, of("RemainingBrewTime"), "remaining_brew_time"));
register(makeValueKey(BlockState.class, of("RepresentedBlock"), "represented_block"));
register(makeValueKey(ItemStackSnapshot.class, of("RepresentedItem"), "represented_item"));
register(makeValueKey(GameProfile.class, of("RepresentedPlayer"), "represented_player"));
register(makeMapKeyWithKeyAndValue(UUID.class, RespawnLocation.class, of("RespawnLocations"), "respawn_locations"));
register(makeValueKey(Vector3d.class, of("RightArmRotation"), "right_arm_rotation"));
register(makeValueKey(Vector3d.class, of("RightLegRotation"), "right_leg_rotation"));
register(makeValueKey(Rotation.class, of("Rotation"), "rotation"));
register(makeValueKey(SandstoneType.class, of("SandstoneType"), "sandstone_type"));
register(makeValueKey(SandType.class, of("SandType"), "sand_type"));
register(makeMutableBoundedValueKey(Double.class, of("Saturation"), "saturation"));
register(makeMutableBoundedValueKey(Float.class, of("Scale"), "scale"));
register(makeValueKey(Boolean.class, of("Seamless"), "seamless"));
register(makeValueKey(Boolean.class, of("ShouldDrop"), "should_drop"));
register(makeValueKey(ShrubType.class, of("ShrubType"), "shrub_type"));
register(makeListKey(Text.class, of("SignLines"), "sign_lines"));
register(makeValueKey(UUID.class, of("SkinUniqueId"), "skin_unique_id"));
register(makeValueKey(SkullType.class, of("SkullType"), "skull_type"));
register(makeValueKey(SlabType.class, of("SlabType"), "slab_type"));
register(makeMutableBoundedValueKey(Integer.class, of("SlimeSize"), "slime_size"));
register(makeValueKey(Boolean.class, of("Snowed"), "snowed"));
register(makeValueKey(EntityType.class, of("SpawnableEntityType"), "spawnable_entity_type"));
register(makeWeightedCollectionKey(EntityArchetype.class, of("SpawnerEntities"), "spawner_entities"));
register(makeMutableBoundedValueKey(Short.class, of("SpawnerMaximumDelay"), "spawner_maximum_delay"));
register(makeMutableBoundedValueKey(Short.class, of("SpawnerMaximumNearbyEntities"), "spawner_maximum_nearby_entities"));
register(makeMutableBoundedValueKey(Short.class, of("SpawnerMinimumDelay"), "spawner_minimum_delay"));
register(makeValueKey(new TypeToken<WeightedSerializableObject<EntityArchetype>>() {
}, of("SpawnerNextEntityToSpawn"), "spawner_next_entity_to_spawn"));
register(makeMutableBoundedValueKey(Short.class, of("SpawnerRemainingDelay"), "spawner_remaining_delay"));
register(makeMutableBoundedValueKey(Short.class, of("SpawnerRequiredPlayerRange"), "spawner_required_player_range"));
register(makeMutableBoundedValueKey(Short.class, of("SpawnerSpawnCount"), "spawner_spawn_count"));
register(makeMutableBoundedValueKey(Short.class, of("SpawnerSpawnRange"), "spawner_spawn_range"));
register(makeValueKey(StairShape.class, of("StairShape"), "stair_shape"));
register(makeMapKeyWithKeyAndValue(Statistic.class, Long.class, of("Statistics"), "statistics"));
register(makeValueKey(StoneType.class, of("StoneType"), "stone_type"));
register(makeListKey(Enchantment.class, of("StoredEnchantments"), "stored_enchantments"));
register(makeValueKey(String.class, of("StructureAuthor"), "structure_author"));
register(makeValueKey(Boolean.class, of("StructureIgnoreEntities"), "structure_ignore_entities"));
register(makeValueKey(Float.class, of("StructureIntegrity"), "structure_integrity"));
register(makeValueKey(StructureMode.class, of("StructureMode"), "structure_mode"));
register(makeValueKey(Vector3i.class, of("StructurePosition"), "structure_position"));
register(makeValueKey(Boolean.class, of("StructurePowered"), "structure_powered"));
register(makeValueKey(Long.class, of("StructureSeed"), "structure_seed"));
register(makeValueKey(Boolean.class, of("StructureShowAir"), "structure_show_air"));
register(makeValueKey(Boolean.class, of("StructureShowBoundingBox"), "structure_show_bounding_box"));
register(makeValueKey(Vector3i.class, of("StructureSize"), "structure_size"));
register(makeMutableBoundedValueKey(Integer.class, of("StuckArrows"), "stuck_arrows"));
register(makeMutableBoundedValueKey(Integer.class, of("SuccessCount"), "success_count"));
register(makeValueKey(Boolean.class, of("Suspended"), "suspended"));
register(makeOptionalKey(UUID.class, of("TamedOwner"), "tamed_owner"));
register(makeValueKey(Vector3d.class, of("TargetedLocation"), "targeted_location"));
register(makeValueKey(Integer.class, of("TicksRemaining"), "ticks_remaining"));
register(makeMutableBoundedValueKey(Integer.class, of("TotalExperience"), "total_experience"));
register(makeValueKey(Boolean.class, of("TracksOutput"), "tracks_output"));
register(makeListKey(TradeOffer.class, of("TradeOffers"), "trade_offers"));
register(makeValueKey(TreeType.class, of("TreeType"), "tree_type"));
register(makeValueKey(Boolean.class, of("Unbreakable"), "unbreakable"));
register(makeValueKey(Boolean.class, of("Vanish"), "vanish"));
register(makeValueKey(Boolean.class, of("VanishIgnoresCollision"), "vanish_ignores_collision"));
register(makeValueKey(Boolean.class, of("VanishPreventsTargeting"), "vanish_prevents_targeting"));
register(makeValueKey(EntitySnapshot.class, of("Vehicle"), "vehicle"));
register(makeValueKey(Vector3d.class, of("Velocity"), "velocity"));
register(makeOptionalKey(Profession.class, of("VillagerZombieProfession"), "villager_zombie_profession"));
register(makeValueKey(Double.class, of("WalkingSpeed"), "walking_speed"));
register(makeValueKey(WallType.class, of("WallType"), "wall_type"));
register(makeValueKey(Boolean.class, of("WillShatter"), "will_shatter"));
register(makeMapKeyWithKeyAndValue(Direction.class, WireAttachmentType.class, of("WireAttachments"), "wire_attachments"));
register(makeValueKey(WireAttachmentType.class, of("WireAttachmentEast"), "wire_attachment_east"));
register(makeValueKey(WireAttachmentType.class, of("WireAttachmentNorth"), "wire_attachment_north"));
register(makeValueKey(WireAttachmentType.class, of("WireAttachmentSouth"), "wire_attachment_south"));
register(makeValueKey(WireAttachmentType.class, of("WireAttachmentWest"), "wire_attachment_west"));
causeStack.popCause();
causeStack.pushCause(Lantern.getImplementationPlugin());
// Register the lantern keys
for (Field field : LanternKeys.class.getFields()) {
if (Modifier.isStatic(field.getModifiers())) {
final Object object;
try {
object = field.get(null);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
if (object instanceof Key) {
register((Key) object);
}
}
}
causeStack.popCause();
}
use of org.spongepowered.api.data.type.NotePitch in project LanternServer by LanternPowered.
the class ProcessorPlayOutParticleEffect method preProcess.
private ICachedMessage preProcess(ParticleEffect effect0) {
final LanternParticleEffect effect = (LanternParticleEffect) effect0;
final LanternParticleType type = effect.getType();
final OptionalInt internalType = type.getInternalType();
// Special cases
if (!internalType.isPresent()) {
if (type == ParticleTypes.FIREWORKS) {
// Create the fireworks data item
final LanternItemStack itemStack = new LanternItemStack(ItemTypes.FIREWORKS);
itemStack.tryOffer(Keys.FIREWORK_EFFECTS, effect.getOptionOrDefault(ParticleOptions.FIREWORK_EFFECTS).get());
// Write the item to a parameter list
final ByteBufParameterList parameterList = new ByteBufParameterList(ByteBufferAllocator.unpooled());
parameterList.add(EntityParameters.Fireworks.ITEM, itemStack);
return new CachedFireworksMessage(new MessagePlayOutEntityMetadata(CachedFireworksMessage.ENTITY_ID, parameterList));
} else if (type == ParticleTypes.FERTILIZER) {
final int quantity = effect.getOptionOrDefault(ParticleOptions.QUANTITY).get();
return new CachedEffectMessage(2005, quantity, false);
} else if (type == ParticleTypes.SPLASH_POTION) {
final int potionId = this.potionEffectTypeToId.getInt(effect.getOptionOrDefault(ParticleOptions.POTION_EFFECT_TYPE).get());
return new CachedEffectMessage(2002, potionId, false);
} else if (type == ParticleTypes.BREAK_BLOCK) {
final int state = getBlockState(effect, type.getDefaultOption(ParticleOptions.BLOCK_STATE));
if (state == 0) {
return EmptyCachedMessage.INSTANCE;
}
return new CachedEffectMessage(2001, state, false);
} else if (type == ParticleTypes.MOBSPAWNER_FLAMES) {
return new CachedEffectMessage(2004, 0, false);
} else if (type == ParticleTypes.ENDER_TELEPORT) {
return new CachedEffectMessage(2003, 0, false);
} else if (type == ParticleTypes.DRAGON_BREATH_ATTACK) {
return new CachedEffectMessage(2006, 0, false);
} else if (type == ParticleTypes.FIRE_SMOKE) {
final Direction direction = effect.getOptionOrDefault(ParticleOptions.DIRECTION).get();
return new CachedEffectMessage(2000, getDirectionData(direction), false);
}
return EmptyCachedMessage.INSTANCE;
}
final int internalId = internalType.getAsInt();
final Vector3f offset = effect.getOption(ParticleOptions.OFFSET).map(Vector3d::toFloat).orElse(Vector3f.ZERO);
final int quantity = effect.getOption(ParticleOptions.QUANTITY).orElse(1);
int[] extra = null;
// The extra values, normal behavior offsetX, offsetY, offsetZ
double f0 = 0f;
double f1 = 0f;
double f2 = 0f;
// Depends on behavior
// Note: If the count > 0 -> speed = 0f else if count = 0 -> speed = 1f
final Optional<BlockState> defaultBlockState;
if (type != ParticleTypes.ITEM_CRACK && (defaultBlockState = type.getDefaultOption(ParticleOptions.BLOCK_STATE)).isPresent()) {
final int state = getBlockState(effect, defaultBlockState);
if (state == 0) {
return EmptyCachedMessage.INSTANCE;
}
extra = new int[] { state };
}
final Optional<ItemStackSnapshot> defaultItemStackSnapshot;
if (extra == null && (defaultItemStackSnapshot = type.getDefaultOption(ParticleOptions.ITEM_STACK_SNAPSHOT)).isPresent()) {
final Optional<ItemStackSnapshot> optItemStackSnapshot = effect.getOption(ParticleOptions.ITEM_STACK_SNAPSHOT);
if (optItemStackSnapshot.isPresent()) {
extra = toExtraItemData(optItemStackSnapshot.get().createStack());
} else {
final Optional<BlockState> optBlockState = effect.getOption(ParticleOptions.BLOCK_STATE);
if (optBlockState.isPresent()) {
final BlockState blockState = optBlockState.get();
final Optional<ItemType> optItemType = blockState.getType().getItem();
if (optItemType.isPresent()) {
// TODO: Item damage value
extra = new int[] { ItemRegistryModule.get().getInternalId(optItemType.get()), 0 };
} else {
return EmptyCachedMessage.INSTANCE;
}
} else {
extra = toExtraItemData(defaultItemStackSnapshot.get().createStack());
}
}
}
if (extra == null) {
extra = new int[0];
}
final Optional<Double> defaultScale = type.getDefaultOption(ParticleOptions.SCALE);
final Optional<Color> defaultColor;
final Optional<NotePitch> defaultNote;
final Optional<Vector3d> defaultVelocity;
if (defaultScale.isPresent()) {
double scale = effect.getOption(ParticleOptions.SCALE).orElse(defaultScale.get());
// Server formula: sizeServer = (-sizeClient * 2) + 2
if (type == ParticleTypes.LARGE_EXPLOSION || type == ParticleTypes.SWEEP_ATTACK) {
scale = (-scale * 2f) + 2f;
}
if (scale == 0f) {
return new CachedParticleMessage(internalId, offset, quantity, extra);
}
f0 = scale;
} else if ((defaultColor = type.getDefaultOption(ParticleOptions.COLOR)).isPresent()) {
final boolean isSpell = type == ParticleTypes.MOB_SPELL || type == ParticleTypes.AMBIENT_MOB_SPELL;
Color color = effect.getOption(ParticleOptions.COLOR).orElse(null);
if (!isSpell && (color == null || color.equals(defaultColor.get()))) {
return new CachedParticleMessage(internalId, offset, quantity, extra);
} else if (isSpell && color == null) {
color = defaultColor.get();
}
f0 = color.getRed() / 255f;
f1 = color.getGreen() / 255f;
f2 = color.getBlue() / 255f;
// but we already chose for the color, can't have both
if (isSpell) {
f0 = Math.max(f0, 0.001f);
f2 = Math.max(f0, 0.001f);
}
// If the f0 value 0 is, the redstone will set it automatically to red 255
if (f0 == 0f && type == ParticleTypes.REDSTONE_DUST) {
f0 = 0.00001f;
}
} else if ((defaultNote = type.getDefaultOption(ParticleOptions.NOTE)).isPresent()) {
final NotePitch notePitch = effect.getOption(ParticleOptions.NOTE).orElse(defaultNote.get());
final float note = ((LanternNotePitch) notePitch).getInternalId();
if (note == 0f) {
return new CachedParticleMessage(internalId, offset, quantity, extra);
}
f0 = note / 24f;
} else if ((defaultVelocity = type.getDefaultOption(ParticleOptions.VELOCITY)).isPresent()) {
final Vector3d velocity = effect.getOption(ParticleOptions.VELOCITY).orElse(defaultVelocity.get());
f0 = velocity.getX();
f1 = velocity.getY();
f2 = velocity.getZ();
final Optional<Boolean> slowHorizontalVelocity = type.getDefaultOption(ParticleOptions.SLOW_HORIZONTAL_VELOCITY);
if (slowHorizontalVelocity.isPresent() && effect.getOption(ParticleOptions.SLOW_HORIZONTAL_VELOCITY).orElse(slowHorizontalVelocity.get())) {
f0 = 0f;
f2 = 0f;
}
// The y value won't work for this effect, if the value isn't 0 the velocity won't work
if (type == ParticleTypes.WATER_SPLASH) {
f1 = 0f;
}
if (f0 == 0f && f1 == 0f && f2 == 0f) {
return new CachedParticleMessage(internalId, offset, quantity, extra);
}
}
// Is this check necessary?
if (f0 == 0f && f1 == 0f && f2 == 0f) {
return new CachedParticleMessage(internalId, offset, quantity, extra);
}
return new CachedOffsetParticleMessage(internalId, new Vector3f(f0, f1, f2), offset, quantity, extra);
}
use of org.spongepowered.api.data.type.NotePitch in project LanternServer by LanternPowered.
the class CommandParticleEffect method completeSpec.
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
specBuilder.arguments(GenericArguments.catalogedElement(Text.of("type"), ParticleType.class), GenericArguments.vector3d(Text.of("position")), GenericArguments.optional(GenericArguments.world(Text.of("world"))), // TODO: Tab complaining is currently throwing errors, but it's a small bug in SpongeAPI
GenericArguments.flags().valueFlag(GenericArguments.integer(Text.of("quantity")), "-quantity", "q").valueFlag(GenericArguments.vector3d(Text.of("offset")), "-offset", "o").valueFlag(GenericArguments.vector3d(Text.of("velocity")), "-velocity", "v").valueFlag(GenericArguments.vector3d(Text.of("color")), "-color", "c").valueFlag(GenericArguments.doubleNum(Text.of("scale")), "-scale", "s").valueFlag(GenericArguments.catalogedElement(Text.of("note"), NotePitch.class), "-note", "n").valueFlag(GenericArguments.catalogedElement(Text.of("block"), BlockState.class), "-block", "b").valueFlag(GenericArguments.catalogedElement(Text.of("item"), ItemType.class), "-item", "i").valueFlag(GenericArguments.catalogedElement(Text.of("potion"), PotionEffectType.class), "-potion", "p").buildWith(GenericArguments.none())).executor((src, args) -> {
final ParticleType particleType = args.<ParticleType>getOne("type").get();
final Vector3d position = args.<Vector3d>getOne("position").get();
final World world = args.<WorldProperties>getOne("world").map(props -> Sponge.getServer().getWorld(props.getUniqueId()).get()).orElseGet(((Locatable) src)::getWorld);
final ParticleEffect.Builder builder = ParticleEffect.builder().type(particleType);
args.<Integer>getOne("quantity").ifPresent(builder::quantity);
args.<Vector3d>getOne("offset").ifPresent(builder::offset);
args.<Vector3d>getOne("velocity").ifPresent(builder::velocity);
args.<Vector3d>getOne("color").ifPresent(color -> builder.option(ParticleOptions.COLOR, Color.of(color.toInt())));
args.<NotePitch>getOne("note").ifPresent(note -> builder.option(ParticleOptions.NOTE, note));
args.<Double>getOne("scale").ifPresent(scale -> builder.option(ParticleOptions.SCALE, scale));
args.<BlockState>getOne("block").ifPresent(blockState -> builder.option(ParticleOptions.BLOCK_STATE, blockState));
args.<ItemType>getOne("item").ifPresent(item -> builder.option(ParticleOptions.ITEM_STACK_SNAPSHOT, new LanternItemStack(item).createSnapshot()));
args.<PotionEffectType>getOne("potion").ifPresent(type -> builder.option(ParticleOptions.POTION_EFFECT_TYPE, type));
world.spawnParticles(builder.build(), position);
src.sendMessage(t("Successfully spawned the particle %s", particleType.getName()));
return CommandResult.success();
});
}
Aggregations