use of org.spongepowered.api.data.property.item.RecordProperty in project LanternServer by LanternPowered.
the class LanternJukebox method playRecord.
@Override
public void playRecord() {
final ItemStack recordItem = this.inventory.getRawItemStack();
if (recordItem == null) {
return;
}
this.playing = true;
final Location<World> location = getLocation();
final RecordProperty property = recordItem.getProperty(RecordProperty.class).orElse(null);
final RecordType recordType = property == null ? null : property.getValue();
if (recordType != null) {
location.getExtent().playRecord(location.getBlockPosition(), recordType);
}
}
use of org.spongepowered.api.data.property.item.RecordProperty in project LanternServer by LanternPowered.
the class JukeboxInteractionBehavior method tryInteract.
@Override
public BehaviorResult tryInteract(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
final Location<World> location = context.requireContext(ContextKeys.INTERACTION_LOCATION);
final Optional<TileEntity> optTile = location.getTileEntity();
if (optTile.isPresent()) {
final TileEntity tile = optTile.get();
if (tile instanceof Jukebox) {
final LanternJukebox jukebox = (LanternJukebox) tile;
final Optional<Entity> optEjectedItem = jukebox.ejectRecordItem();
boolean success = false;
if (optEjectedItem.isPresent()) {
final Entity entity = optEjectedItem.get();
entity.getWorld().spawnEntity(optEjectedItem.get());
// TODO: Include the entity in the behavior context
success = true;
}
final Optional<ItemStack> optItemStack = context.getContext(ContextKeys.USED_ITEM_STACK);
if (optItemStack.isPresent()) {
final ItemStack itemStack = optItemStack.get();
final RecordProperty property = itemStack.getProperty(RecordProperty.class).orElse(null);
final RecordType recordType = property == null ? null : property.getValue();
if (recordType != null) {
final ItemStackSnapshot oldSnapshot = itemStack.createSnapshot();
itemStack.setQuantity(itemStack.getQuantity() - 1);
final ItemStackSnapshot newSnapshot = itemStack.createSnapshot();
context.getContext(ContextKeys.PLAYER).ifPresent(player -> {
if (!player.get(Keys.GAME_MODE).orElse(GameModes.NOT_SET).equals(GameModes.CREATIVE)) {
context.getContext(ContextKeys.USED_SLOT).ifPresent(slot -> context.addSlotChange(new SlotTransaction(slot, oldSnapshot, newSnapshot)));
}
});
itemStack.setQuantity(1);
jukebox.insertRecord(itemStack);
jukebox.playRecord();
success = true;
}
}
if (success) {
return BehaviorResult.SUCCESS;
}
}
}
return BehaviorResult.PASS;
}
Aggregations