本文整理汇总了Java中org.spongepowered.api.entity.EntityTypes类的典型用法代码示例。如果您正苦于以下问题:Java EntityTypes类的具体用法?Java EntityTypes怎么用?Java EntityTypes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityTypes类属于org.spongepowered.api.entity包,在下文中一共展示了EntityTypes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: triggerExplosion
import org.spongepowered.api.entity.EntityTypes; //导入依赖的package包/类
private static boolean triggerExplosion(World world, int x, int baseY,
int z, Cause cause) {
int y = baseY + EXPLOSION_Y_OFFSET;
Optional<Entity> opt = world.createEntity(EntityTypes.PRIMED_TNT,
new Vector3i(x, y, z));
if (!opt.isPresent()) {
APlugin.getInstance().getLogger().info("Couldn't spawn PTNT at "
+ String.format("(%s, %s, %s)", x, y, z));
return false;
}
Entity e = opt.get();
((EntityTNTPrimed) e).fuse = EXPLOSION_TIMER;
// if (!e.offer(Keys.FUSE_DURATION, EXPLOSION_TIMER).isSuccessful()) {
// APlugin.getInstance().getLogger().info("Couldn't set data on " + e);
// return false;
// }
return world.spawnEntity(e, cause);
}
示例2: execute
import org.spongepowered.api.entity.EntityTypes; //导入依赖的package包/类
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
ItemTag item = ItemTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
LocationTag locationTag = LocationTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
UtilLocation location = locationTag.getInternal();
if (location.world == null) {
queue.handleError(entry, "Invalid location with no world in Spawn command!");
return;
}
Entity entity = location.world.createEntity(EntityTypes.ITEM, location.toVector3d());
entity.offer(Keys.REPRESENTED_ITEM, item.getInternal().createSnapshot());
location.world.spawnEntity(entity);
if (queue.shouldShowGood()) {
queue.outGood("Dropped item " + ColorSet.emphasis + item.debug() + ColorSet.good
+ " at location " + ColorSet.emphasis + locationTag.debug() + ColorSet.good + "!");
}
}
示例3: onEntityDamagedByPlayer
import org.spongepowered.api.entity.EntityTypes; //导入依赖的package包/类
@Listener(order=Order.FIRST, beforeModifications = true)
public void onEntityDamagedByPlayer(DamageEntityEvent event, @All(ignoreEmpty=false) EntityDamageSource[] sources)
{
if (!ConfigHandler.getNode("worlds").getNode(event.getTargetEntity().getWorld().getName()).getNode("enabled").getBoolean())
{
return;
}
Entity attacker = null;
for (int i = 0; i < sources.length; i++)
{
if (sources[i].getSource().getType() == EntityTypes.PLAYER
|| (sources[i] instanceof IndirectEntityDamageSource && ((IndirectEntityDamageSource) sources[i]).getIndirectSource().getType() == EntityTypes.PLAYER))
{
attacker = sources[i].getSource();
}
}
if (attacker != null && event.getTargetEntity().getType() == EntityTypes.PLAYER)
{
if (!DataHandler.getFlag("pvp", attacker.getLocation()) || !DataHandler.getFlag("pvp", event.getTargetEntity().getLocation()))
{
event.setCancelled(true);
return;
}
}
}
示例4: onEntityTeleport
import org.spongepowered.api.entity.EntityTypes; //导入依赖的package包/类
@Listener(order = Order.LAST)
public void onEntityTeleport(MoveEntityEvent.Teleport event) {
if (event.getTargetEntity().getType() != EntityTypes.PLAYER) {
return; // not a player
}
if (event.getFromTransform().getPosition().equals(event.getToTransform().getPosition())) {
return; // player hasn't moved
}
Optional<Challenger> chal = CommonCore.getChallenger(event.getTargetEntity().getUniqueId());
if (chal.isPresent() && !((CommonChallenger) chal.get()).isLeaving()) {
Boundary bound = chal.get().getRound().getArena().getBoundary();
if (!bound.contains(LocationConverter.of(event.getToTransform().getPosition()))) {
if (chal.get().getRound().getConfigValue(ConfigNode.ALLOW_EXIT_BOUNDARY)) {
chal.get().removeFromRound();;
} else {
event.setCancelled(true);
}
}
}
}
示例5: give
import org.spongepowered.api.entity.EntityTypes; //导入依赖的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();
}
}
}
示例6: tabCompleter
import org.spongepowered.api.entity.EntityTypes; //导入依赖的package包/类
@Override
public Collection<String> tabCompleter(final CommandSource source, final List<String> args) throws CommandException {
if (args.size() == 1) {
List<String> suggests = new ArrayList<String>();
this.plugin.getGame().getRegistry().getAllForMinecraft(EntityType.class).stream()
.filter(entity -> !entity.equals(EntityTypes.UNKNOWN) &&
(Creature.class.isAssignableFrom(entity.getEntityClass()) || Hostile.class.isAssignableFrom(entity.getEntityClass())))
.forEach(entity -> suggests.add(entity.getId().replaceAll("minecraft:", "")));
this.plugin.getGame().getRegistry().getAllOf(EntityType.class).stream()
.filter(entity -> !entity.equals(EntityTypes.UNKNOWN) &&
(Creature.class.isAssignableFrom(entity.getEntityClass()) || Hostile.class.isAssignableFrom(entity.getEntityClass())))
.forEach(entity -> suggests.add(entity.getId()));
this.plugin.getEverAPI().getManagerService().getEntity().getAll()
.forEach(entity -> suggests.add(entity.getId()));
return suggests;
} else if (args.size() == 2){
Arrays.asList("1", String.valueOf(this.limit));
}
return Arrays.asList();
}
示例7: onItemDrop
import org.spongepowered.api.entity.EntityTypes; //导入依赖的package包/类
@Listener
public void onItemDrop(DropItemEvent.Dispense event, @Root Player player) {
PermHandler ph = PermHandler.getInstance();
event.filterEntities(entity -> {
if (entity.getType().equals(EntityTypes.ITEM)) {
Item item = (Item) entity;
ItemType itemType = item.getItemType();
String itemId = itemType.getId();
if (!ph.checkPerm(player, "protectionperms.item.drop." + itemId + ".dispense")) {
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to drop " + itemType.getName() + '!'));
return false;
}
}
return true;
});
}
示例8: deserialize
import org.spongepowered.api.entity.EntityTypes; //导入依赖的package包/类
@Override
public NPCguard deserialize(TypeToken<?> arg0, ConfigurationNode cfg) throws ObjectMappingException {
NPCguard npc = new NPCguard(UUID.fromString(cfg.getNode("uuid").getString()));
InvPrep ip = new InvPrep();
ip.items = cfg.getNode("items").getValue(tokenListStockItem);
if (ip.items==null) ip.items = new LinkedList<>();
npc.setPreparator(ip);
npc.setLoc(cfg.getNode("location").getValue(tokenLocationWorld));
npc.setRot(new Vector3d(0.0, cfg.getNode("rotation").getDouble(0.0), 0.0 ));
npc.setNpcType((EntityType)FieldResolver.getFinalStaticByName(EntityTypes.class, cfg.getNode("entitytype").getString("VILLAGER")));
npc.setVariant(cfg.getNode("variant").getString("NONE"));
npc.setDisplayName(TextSerializers.FORMATTING_CODE.deserialize(cfg.getNode("displayName").getString("VillagerShop")));
String tmp = cfg.getNode("playershop").getString(null);
if (tmp != null && !tmp.isEmpty())
npc.playershopholder=UUID.fromString(tmp);
npc.playershopcontainer=cfg.getNode("stocklocation").getValue(tokenLocationWorld);
return npc;
}
示例9: createDummyArmorStand
import org.spongepowered.api.entity.EntityTypes; //导入依赖的package包/类
static ArmorStand createDummyArmorStand(Block block) {
World world = block.getWorld()
.orElseThrow(() -> new IllegalStateException("Could not access the world this block resides in."));
Vector3d armorStandPosition = block.getPosition().toDouble().add(Vector3d.ONE.mul(0.5));
ArmorStand armorStand = (ArmorStand) world.createEntity(EntityTypes.ARMOR_STAND, armorStandPosition);
armorStand.offer(Keys.IS_SILENT, true);
armorStand.offer(Keys.INVISIBLE, true);
armorStand.offer(Keys.ARMOR_STAND_MARKER, true);
armorStand.offer(Keys.HAS_GRAVITY, false);
armorStand.offer(Keys.PERSISTS, true);
armorStand.offer(Keys.IS_SILENT, true);
armorStand.setHeadRotation(Vector3d.ZERO);
armorStand.setRotation(Vector3d.ZERO);
return armorStand;
}
示例10: spawnItem
import org.spongepowered.api.entity.EntityTypes; //导入依赖的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);
}
示例11: create
import org.spongepowered.api.entity.EntityTypes; //导入依赖的package包/类
private boolean create() {
if (this.entity == null) {
return false;
}
if (this.stand != null) {
// For some reason setPassenger behaves differently
return this.entity.setVehicle(this.stand);
}
this.stand = (ArmorStand) this.entity.getWorld().createEntity(EntityTypes.ARMOR_STAND,
this.entity.getLocation().getPosition());
if (!this.stand.offer(Keys.HAS_GRAVITY, false).isSuccessful()) {
return false;
}
ArmorStandData data = this.stand.getOrCreate(ArmorStandData.class).get();
data.set(data.basePlate().set(false));
data.set(data.small().set(true));
data.set(data.marker().set(true));
if (!this.stand.offer(data).isSuccessful()) {
return false;
}
this.stand.tryOffer(Keys.INVISIBLE, true);
if (!this.stand.addPassenger(this.entity)) {
return false;
}
return true;
}
示例12: PipeBlock
import org.spongepowered.api.entity.EntityTypes; //导入依赖的package包/类
public PipeBlock() {
this.pane = ItemStack.of(ItemTypes.STAINED_GLASS_PANE, 1);
Vector3d rotX = new Vector3d(90, 0, 0);
Vector3d rotY = new Vector3d(0, 90, 0);
this.entityStruct = new MultiEntityStructure.Builder()
.define(Direction.DOWN.name(), EntityTypes.ARMOR_STAND,
armorStandOffset(true, Axis.Z, new Vector3f(0.5, 0.2, 0.5)),
ArmorStand.class, stand -> setupArmorStand(stand, rotX))
.define(Direction.UP.name(), EntityTypes.ARMOR_STAND,
armorStandOffset(true, Axis.Z, new Vector3f(0.5, 0.7375, 0.5)),
ArmorStand.class, stand -> setupArmorStand(stand, rotX))
.define(Direction.NORTH.name(), EntityTypes.ARMOR_STAND,
armorStandOffset(false, Axis.Z, new Vector3f(0.5, 0.2, 0.2)),
ArmorStand.class, stand -> setupArmorStand(stand, null))
.define(Direction.SOUTH.name(), EntityTypes.ARMOR_STAND,
armorStandOffset(false, Axis.Z, new Vector3f(0.5, 0.2, 0.8)),
ArmorStand.class, stand -> setupArmorStand(stand, null))
.define(Direction.EAST.name(), EntityTypes.ARMOR_STAND,
armorStandOffset(false, Axis.X, new Vector3f(0.8, 0.2, 0.5)),
ArmorStand.class, stand -> setupArmorStand(stand, rotY))
.define(Direction.WEST.name(), EntityTypes.ARMOR_STAND,
armorStandOffset(false, Axis.X, new Vector3f(0.2, 0.2, 0.5)),
ArmorStand.class, stand -> setupArmorStand(stand, rotY))
.build();
}
示例13: accept
import org.spongepowered.api.entity.EntityTypes; //导入依赖的package包/类
@Override
public void accept(Task task) {
List<Color> colors = Lists.newArrayList(Color.BLACK, Color.BLUE, Color.CYAN, Color.DARK_CYAN, Color.DARK_GREEN, Color.DARK_MAGENTA,
Color.GRAY, Color.GREEN, Color.LIME, Color.MAGENTA, Color.NAVY, Color.PINK, Color.PURPLE, Color.RED, Color.WHITE, Color.YELLOW);
Collections.shuffle(colors);
FireworkEffect fireworkEffect = FireworkEffect.builder()
.colors(colors.get(0), colors.get(1), colors.get(2))
.shape(FireworkShapes.STAR)
.build();
Entity firework = this.player.getWorld().createEntity(EntityTypes.FIREWORK, this.player.getLocation().getPosition());
firework.offer(Keys.FIREWORK_EFFECTS, Lists.newArrayList(fireworkEffect));
firework.offer(Keys.FIREWORK_FLIGHT_MODIFIER, 2);
this.player.getWorld().spawnEntity(firework);
this.counter++;
if (this.counter >= this.ITERATIONS) {
task.cancel();
}
}
示例14: run
import org.spongepowered.api.entity.EntityTypes; //导入依赖的package包/类
@Override
public void run(ScriptContext scriptContext) {
final LanternWorld world = (LanternWorld) scriptContext.get(Parameters.WORLD).get();
final Random random = RANDOM.get();
final Iterable<Chunk> chunks = world.getLoadedChunks();
final int chance = (int) (1f / Math.max(this.chance, 0.000000000001f));
for (Chunk chunk : chunks) {
for (int i = 0; i < this.attemptsPerChunk; i++) {
final LanternChunk chunk1 = (LanternChunk) chunk;
if (random.nextInt(chance) != 0) {
continue;
}
final int value = random.nextInt(0x10000);
final int x = chunk1.getX() << 4 | value & 0xf;
final int z = chunk1.getZ() << 4 | (value >> 4) & 0xf;
final Entity entity = world.createEntity(EntityTypes.LIGHTNING, new Vector3d(x, world.getHighestYAt(x, z), z));
world.spawnEntity(entity);
}
}
}
示例15: ejectRecordItem
import org.spongepowered.api.entity.EntityTypes; //导入依赖的package包/类
/**
* Resets the record {@link ItemStackSnapshot} and
* returns it. If present.
*
* @return The record item
*/
public Optional<Entity> ejectRecordItem() {
final ItemStack recordItem = this.inventory.getRawItemStack();
if (recordItem == null) {
return Optional.empty();
}
stopRecord();
final Location<World> location = getLocation();
final Vector3d entityPosition = location.getBlockPosition().toDouble().add(0.5, 0.9, 0.5);
final Entity item = location.getExtent().createEntity(EntityTypes.ITEM, entityPosition);
item.offer(Keys.VELOCITY, new Vector3d(0, 0.1, 0));
item.offer(Keys.REPRESENTED_ITEM, recordItem.createSnapshot());
this.inventory.clear();
updateBlockState();
return Optional.of(item);
}