use of org.spongepowered.api.item.ItemType in project LanternServer by LanternPowered.
the class LanternIngredientBuilder method with.
@Override
public IIngredient.Builder with(ItemType... types) {
checkNotNull(types, "types");
for (ItemType type : types) {
checkNotNull(type, "type");
this.matchers.add(type::matches);
}
return withDisplay(types);
}
use of org.spongepowered.api.item.ItemType in project LanternServer by LanternPowered.
the class EquipmentItemFilter method of.
/**
* Constructs a {@link ItemFilter} for the provided
* {@link EquipmentSlotType} property.
*
* @param equipmentSlotType The equipment slot type property
* @return The equipment item filter
*/
static EquipmentItemFilter of(EquipmentSlotType equipmentSlotType) {
checkNotNull(equipmentSlotType, "equipmentSlotType");
final EquipmentType slotEquipmentType = equipmentSlotType.getValue();
checkNotNull(slotEquipmentType, "value");
final Property.Operator operator = equipmentSlotType.getOperator();
checkArgument(operator == Property.Operator.EQUAL || operator == Property.Operator.NOTEQUAL, "Only the operators EQUAL and NOTEQUAL are supported, %s is not.", operator);
return new EquipmentItemFilter() {
@Override
public boolean isValid(EquipmentType equipmentType) {
final boolean result = ((LanternEquipmentType) slotEquipmentType).isChild(equipmentType);
return (operator == Property.Operator.EQUAL) == result;
}
private boolean isValid(Optional<EquipmentProperty> optEquipmentProperty) {
return optEquipmentProperty.map(property -> {
final EquipmentType equipmentType = property.getValue();
final boolean result = ((LanternEquipmentType) slotEquipmentType).isChild(equipmentType);
return (operator == Property.Operator.EQUAL) == result;
}).orElse(false);
}
@Override
public boolean isValid(ItemStack stack) {
return isValid(stack.getProperty(EquipmentProperty.class));
}
@Override
public boolean isValid(ItemStackSnapshot stack) {
return isValid(stack.getProperty(EquipmentProperty.class));
}
@Override
public boolean isValid(ItemType type) {
return isValid(type.getDefaultProperty(EquipmentProperty.class));
}
};
}
use of org.spongepowered.api.item.ItemType in project LanternServer by LanternPowered.
the class ItemStackStore method deserialize.
@Override
public LanternItemStack deserialize(DataView dataView) throws InvalidDataException {
final String identifier = dataView.getString(IDENTIFIER).get();
final ItemType itemType = ItemRegistryModule.get().getById(identifier).orElseThrow(() -> new InvalidDataException("There is no item type with the id: " + identifier));
final LanternItemStack itemStack = new LanternItemStack(itemType);
deserialize(itemStack, dataView);
return itemStack;
}
use of org.spongepowered.api.item.ItemType 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();
});
}
use of org.spongepowered.api.item.ItemType in project LanternServer by LanternPowered.
the class BlockTypeBuilderImpl method build.
@Override
public LanternBlockType build(String pluginId, String id) {
MutableBehaviorPipeline<Behavior> behaviorPipeline = this.behaviorPipeline;
if (behaviorPipeline == null) {
behaviorPipeline = new MutableBehaviorPipelineImpl<>(Behavior.class, new ArrayList<>());
} else {
behaviorPipeline = new MutableBehaviorPipelineImpl<>(Behavior.class, new ArrayList<>(behaviorPipeline.getBehaviors()));
}
TranslationProvider translationProvider = this.translationProvider;
if (translationProvider == null) {
String path = "tile." + id + ".name";
if (!pluginId.equals("minecraft")) {
path = pluginId + '.' + path;
}
translationProvider = TranslationProvider.of(tr(path));
}
PropertyProviderCollection.Builder properties;
if (this.propertiesBuilder != null) {
properties = this.propertiesBuilder;
} else {
properties = PropertyProviderCollections.DEFAULT.toBuilder();
}
ExtendedBlockStateProvider extendedBlockStateProvider = this.extendedBlockStateProvider;
if (extendedBlockStateProvider == null) {
extendedBlockStateProvider = new ExtendedBlockStateProvider() {
@Override
public BlockState get(BlockState blockState, @Nullable Location<World> location, @Nullable Direction face) {
return blockState;
}
@Override
public BlockState remove(BlockState blockState) {
return blockState;
}
};
}
final LanternBlockType blockType = new LanternBlockType(pluginId, id, this.traits, translationProvider, behaviorPipeline, this.tileEntityProvider, extendedBlockStateProvider);
// Override the default solid cube property provider if necessary
final PropertyProvider<SolidCubeProperty> provider = properties.build().get(SolidCubeProperty.class).orElse(null);
ObjectProvider<AABB> boundingBoxProvider = this.boundingBoxProvider;
if (boundingBoxProvider instanceof SimpleObjectProvider) {
// noinspection unchecked
boundingBoxProvider = new CachedSimpleObjectProvider(blockType, ((SimpleObjectProvider) boundingBoxProvider).getProvider());
}
// noinspection ConstantConditions
if (provider instanceof ConstantObjectProvider && provider.get(null, null, null).getValue()) {
if (boundingBoxProvider instanceof ConstantObjectProvider) {
// noinspection ConstantConditions
final AABB aabb = boundingBoxProvider.get(null, null, null);
final boolean isSolid = isSolid(aabb);
if (isSolid) {
properties.add(solidCube(true));
properties.add(solidSide(true));
} else {
properties.add(solidCube(false));
final BitSet solidSides = compileSidePropertyBitSet(aabb);
// Check if all the direction bits are set
final byte[] bytes = solidSides.toByteArray();
if (bytes.length == 0 || bytes[0] != (1 << DIRECTION_INDEXES) - 1) {
properties.add(solidSide((blockState, location, face) -> {
final int index = getDirectionIndex(face);
return index != -1 && solidSides.get(index);
}));
} else {
properties.add(solidSide(false));
}
}
} else if (boundingBoxProvider instanceof CachedSimpleObjectProvider) {
final List<AABB> values = ((CachedSimpleObjectProvider<AABB>) boundingBoxProvider).getValues();
final BitSet bitSet = new BitSet();
int count = 0;
for (int i = 0; i < values.size(); i++) {
if (isSolid(values.get(i))) {
bitSet.set(i);
count++;
}
}
final boolean flag1 = count == values.size();
final boolean flag2 = count == 0;
// Use the best possible solid cube property
if (flag1) {
properties.add(solidCube(true));
properties.add(solidSide(false));
} else if (flag2) {
properties.add(solidCube(false));
} else {
properties.add(solidCube(((blockState, location, face) -> bitSet.get(((LanternBlockState) blockState).getInternalId()))));
}
if (!flag1) {
final BitSet[] solidSides = new BitSet[values.size()];
int solidCount = 0;
for (int i = 0; i < values.size(); i++) {
solidSides[i] = compileSidePropertyBitSet(values.get(i));
// Check if all the direction bits are set
final byte[] bytes = solidSides[i].toByteArray();
if (bytes.length != 0 && bytes[0] == (1 << DIRECTION_INDEXES) - 1) {
solidCount++;
}
}
if (solidCount == 0) {
properties.add(solidSide(false));
} else {
properties.add(solidSide((blockState, location, face) -> {
final int index = getDirectionIndex(face);
if (index == -1) {
return false;
}
final int state = ((LanternBlockState) blockState).getInternalId();
return solidSides[state].get(index);
}));
}
}
} else {
final ObjectProvider<AABB> boundingBoxProvider1 = boundingBoxProvider;
properties.add(solidCube(((blockState, location, face) -> isSolid(boundingBoxProvider1.get(blockState, location, face)))));
properties.add(solidSide(((blockState, location, face) -> isSideSolid(boundingBoxProvider1.get(blockState, location, face), face))));
}
}
blockType.setBoundingBoxProvider(boundingBoxProvider);
blockType.setPropertyProviderCollection(properties.build());
if (this.defaultStateProvider != null) {
blockType.setDefaultBlockState(this.defaultStateProvider.apply(blockType.getDefaultState()));
}
if (this.itemTypeBuilder != null) {
final ItemType itemType = this.itemTypeBuilder.blockType(blockType).behaviors(pipeline -> {
// Only add the default behavior if there isn't any interaction behavior present
if (pipeline.pipeline(InteractWithItemBehavior.class).getBehaviors().isEmpty()) {
pipeline.add(new InteractWithBlockItemBehavior());
}
}).build(blockType.getPluginId(), blockType.getName());
blockType.setItemType(itemType);
}
return blockType;
}
Aggregations