本文整理汇总了Java中org.spongepowered.api.entity.Item.offer方法的典型用法代码示例。如果您正苦于以下问题:Java Item.offer方法的具体用法?Java Item.offer怎么用?Java Item.offer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.entity.Item
的用法示例。
在下文中一共展示了Item.offer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: give
import org.spongepowered.api.entity.Item; //导入方法依赖的package包/类
public void give(Player player) {
this.checkCache();
for (ItemStackSnapshot iss : itemStacksCache) {
InventoryTransactionResult result = player.getInventory().offer(iss.createStack());
for (ItemStackSnapshot is : result.getRejectedItems()) {
Item item = (Item) player.getLocation().getExtent().createEntity(EntityTypes.ITEM, player.getLocation().getPosition());
item.offer(Keys.REPRESENTED_ITEM, is.copy());
player.getWorld().spawnEntity(item, Cause.of(NamedCause.source(player), NamedCause.owner("BetterKits")));
}
}
for (String command : this.getCommands()) {
try {
Sponge.getCommandManager().process(Sponge.getServer().getConsole(), command.replace("%name", player.getName()).replace("%uuid", player.getUniqueId().toString()));
} catch (Throwable e) {
e.printStackTrace();
}
}
}
示例2: spawnItem
import org.spongepowered.api.entity.Item; //导入方法依赖的package包/类
public void spawnItem(Location<World> location, ItemStackSnapshot snapshot, Object notifier) {
World world = location.getExtent();
Item rejectedItem = (Item) world.createEntity(EntityTypes.ITEM, location.getPosition());
Cause cause = Cause.source(
EntitySpawnCause.builder()
.entity(rejectedItem)
.type(SpawnTypes.PLUGIN)
.build()
)
.owner(CustomItemLibrary.getInstance().getPluginContainer())
.notifier(notifier)
.build();
rejectedItem.offer(Keys.REPRESENTED_ITEM, snapshot);
world.spawnEntity(rejectedItem, cause);
}
示例3: onEntityDrop
import org.spongepowered.api.entity.Item; //导入方法依赖的package包/类
@Listener
public void onEntityDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) EntitySpawnCause spawnCause) {
Entity entity = spawnCause.getEntity();
if (!(entity instanceof Animal)) {
return;
}
Optional<TheButcherShopInstance> optInst = manager.getApplicableZone(entity);
if (!optInst.isPresent()) {
return;
}
event.getEntities().clear();
Item item = (Item) entity.getLocation().createEntity(EntityTypes.ITEM);
item.offer(Keys.REPRESENTED_ITEM, newItemStack("skree:unpackaged_meat").createSnapshot());
event.getEntities().add(item);
}
示例4: sweepFloor
import org.spongepowered.api.entity.Item; //导入方法依赖的package包/类
public void sweepFloor() {
for (Item item : getContained(Item.class)) {
if (!contains(item)) {
continue;
}
ItemType id = item.getItemType();
for (ItemType aItem : ITEMS) {
if (aItem == id) {
ItemStackSnapshot snapshot = item.get(Keys.REPRESENTED_ITEM).get();
int newAmt = (int) (snapshot.getCount() * .8);
if (newAmt < 1) {
item.remove();
} else {
ItemStack newStack = snapshot.createStack();
newStack.setQuantity(newAmt);
item.offer(Keys.REPRESENTED_ITEM, newStack.createSnapshot());
}
break;
}
}
}
}
示例5: dropItem
import org.spongepowered.api.entity.Item; //导入方法依赖的package包/类
/**
* Faire drop un item pied du joueur
* @param itemstack L'itemstack
*/
public void dropItem(final ItemStack itemstack) {
Entity entity = this.getWorld().createEntity(EntityTypes.ITEM, this.getLocation().getPosition());
if (entity instanceof Item) {
Item item = (Item) entity;
item.offer(Keys.REPRESENTED_ITEM, itemstack.createSnapshot());
this.getWorld().spawnEntity(item, Cause.source(this.getPlayer().get()).build());
}
}
示例6: createItem
import org.spongepowered.api.entity.Item; //导入方法依赖的package包/类
private static Item createItem(World world, Vector3d pos, ItemStack stack, boolean noPickup) {
Item itemEntity = (Item) world.createEntity(EntityTypes.ITEM, pos);
itemEntity.offer(Keys.REPRESENTED_ITEM, stack.createSnapshot());
if (noPickup) {
itemEntity.tryOffer(Keys.INFINITE_PICKUP_DELAY, true);
itemEntity.tryOffer(Keys.INFINITE_DESPAWN_DELAY, true);
}
return itemEntity;
}
示例7: dropItem
import org.spongepowered.api.entity.Item; //导入方法依赖的package包/类
public static void dropItem(Player p, ItemStack itemStack) {
Entity optional = p.getLocation().getExtent()
.createEntity(EntityTypes.ITEM, p.getLocation()
.getPosition()
.add(TrigMath.cos((p.getRotation().getX() - 90) % 360) * 0.2, 1,
TrigMath.sin((p.getRotation().getX() - 90) % 360) * 0.2));
Vector3d rotation = p.getRotation();
Vector3d direction = Quaterniond.fromAxesAnglesDeg(rotation.getX(), -rotation.getY(), rotation.getZ()).getDirection();
Item item = (Item) optional;
item.offer(Keys.VELOCITY, direction.mul(0.33));
item.offer(Keys.REPRESENTED_ITEM, itemStack.createSnapshot());
item.offer(Keys.PICKUP_DELAY, 50);
p.getLocation().getExtent().spawnEntity(item);
}
示例8: dropItem
import org.spongepowered.api.entity.Item; //导入方法依赖的package包/类
@Override
public void dropItem(ItemStackSnapshot snapshot, Cause cause) {
Item item = (Item) getExtent().createEntity(EntityTypes.ITEM, getPos());
item.offer(Keys.REPRESENTED_ITEM, snapshot);
item.setVelocity(new Vector3d(0, 0, 0));
getExtent().spawnEntity(item, cause);
}
示例9: dropItem
import org.spongepowered.api.entity.Item; //导入方法依赖的package包/类
public void dropItem(ItemStackSnapshot snapshot, Cause cause) {
Item item = (Item) getExtent().createEntity(EntityTypes.ITEM, getPos());
item.offer(Keys.REPRESENTED_ITEM, snapshot);
getExtent().spawnEntity(item, cause);
}