use of org.spongepowered.api.data.DataTransactionResult in project SpongeCommon by SpongePowered.
the class MixinDataHolder method offer.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public DataTransactionResult offer(DataManipulator<?, ?> valueContainer, MergeFunction function) {
TimingsManager.DATA_GROUP_HANDLER.startTimingIfSync();
SpongeTimings.dataOfferManipulator.startTimingIfSync();
final Optional<DataProcessor> optional = DataUtil.getWildDataProcessor(valueContainer.getClass());
if (optional.isPresent()) {
final DataTransactionResult result = optional.get().set(this, valueContainer, checkNotNull(function));
SpongeTimings.dataOfferManipulator.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return result;
} else if (this instanceof IMixinCustomDataHolder) {
final DataTransactionResult result = ((IMixinCustomDataHolder) this).offerCustom(valueContainer, function);
SpongeTimings.dataOfferManipulator.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return result;
}
SpongeTimings.dataOfferManipulator.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return DataTransactionResult.failResult(valueContainer.getValues());
}
use of org.spongepowered.api.data.DataTransactionResult in project SpongeCommon by SpongePowered.
the class SpongeItemStackBuilder method itemData.
@Override
public ItemStack.Builder itemData(final DataManipulator<?, ?> itemData) throws IllegalArgumentException {
checkNotNull(itemData, "Must have a non-null item data!");
checkNotNull(this.type, "Cannot set item data without having set a type first!");
// Validation is required, we can't let devs set block data on a non-block item!
DataTransactionResult result = validateData(this.type, itemData);
if (result.getType() != DataTransactionResult.Type.SUCCESS) {
throw new IllegalArgumentException("The item data is not compatible with the current item type!");
}
if (this.itemDataSet == null) {
this.itemDataSet = new HashSet<>();
}
this.itemDataSet.add(itemData);
return this;
}
use of org.spongepowered.api.data.DataTransactionResult in project SpongeCommon by SpongePowered.
the class SpongeItemStackSnapshot method with.
@Override
public <E> Optional<ItemStackSnapshot> with(Key<? extends BaseValue<E>> key, E value) {
final ItemStack copy = this.privateStack.copy();
final DataTransactionResult result = copy.offer(key, value);
if (result.getType() != DataTransactionResult.Type.SUCCESS) {
return Optional.empty();
}
return Optional.of(copy.createSnapshot());
}
use of org.spongepowered.api.data.DataTransactionResult in project SpongeCommon by SpongePowered.
the class SpongeItemStackSnapshot method with.
@Override
public Optional<ItemStackSnapshot> with(ImmutableDataManipulator<?, ?> valueContainer) {
final DataManipulator<?, ?> manipulator = valueContainer.asMutable();
final ItemStack copyStack = this.privateStack.copy();
final DataTransactionResult result = copyStack.offer(manipulator);
if (result.getType() != DataTransactionResult.Type.FAILURE) {
return Optional.of(copyStack.createSnapshot());
}
return Optional.empty();
}
use of org.spongepowered.api.data.DataTransactionResult in project SpongeCommon by SpongePowered.
the class RecipeTest method onInit.
@Listener
public void onInit(GamePreInitializationEvent event) {
final Ingredient s = Ingredient.of(STONE);
final Ingredient b = Ingredient.of(BED, WOOL);
final ItemStack item = ItemStack.of(BEDROCK, 1);
final DataTransactionResult trans = item.offer(Keys.ITEM_ENCHANTMENTS, Collections.singletonList(Enchantment.of(EnchantmentTypes.UNBREAKING, 1)));
if (trans.getType() != DataTransactionResult.Type.SUCCESS) {
this.plugin.getLogger().error("Could not build recipe output!");
}
final ShapedCraftingRecipe recipe = CraftingRecipe.shapedBuilder().rows().row(s, s, s).row(s, b, s).row(s, s, s).result(item).build("bedrock", this.plugin);
Sponge.getRegistry().getCraftingRecipeRegistry().register(recipe);
}
Aggregations