use of org.spongepowered.api.entity.EntityArchetype in project SpongeCommon by SpongePowered.
the class SpawnerUtils method setEntities.
@SuppressWarnings("unchecked")
public static void setEntities(MobSpawnerBaseLogic logic, WeightedTable<EntityArchetype> table) {
logic.potentialSpawns.clear();
for (TableEntry<EntityArchetype> entry : table) {
if (!(entry instanceof WeightedObject)) {
continue;
}
WeightedObject<EntityArchetype> object = (WeightedObject<EntityArchetype>) entry;
NBTTagCompound compound = NbtTranslator.getInstance().translateData(object.get().getEntityData());
if (!compound.hasKey(NbtDataUtil.ENTITY_TYPE_ID)) {
final ResourceLocation key = EntityList.getKey((Class<? extends Entity>) object.get().getType().getEntityClass());
compound.setString(NbtDataUtil.ENTITY_TYPE_ID, key != null ? key.toString() : "");
}
logic.potentialSpawns.add(new WeightedSpawnerEntity((int) entry.getWeight(), compound));
}
}
use of org.spongepowered.api.entity.EntityArchetype in project modules-extra by CubeEngine.
the class Spawner method onBlockPlace.
@Listener(order = POST)
public void onBlockPlace(ChangeBlockEvent.Place event, @First Player player) {
EntityArchetype hidden = EntityArchetype.builder().type(SNOWBALL).set(INVISIBLE, true).build();
Optional<ItemStackSnapshot> inHand = event.getContext().get(EventContextKeys.USED_ITEM);
if (inHand.isPresent() && places(event, MOB_SPAWNER) && hasEnchantment(inHand.get(), LURE)) {
for (Transaction<BlockSnapshot> trans : event.getTransactions()) {
if (trans.getFinal().getState().getType().equals(MOB_SPAWNER)) {
BlockSnapshot snap = trans.getFinal();
Location<World> loc = snap.getLocation().get();
loc.offer(SPAWNER_ENTITIES, new WeightedTable<>());
loc.offer(SPAWNER_NEXT_ENTITY_TO_SPAWN, new WeightedSerializableObject<>(hidden, 1));
i18n.send(ACTION_BAR, player, POSITIVE, "Inactive Monster Spawner placed!");
return;
}
}
}
}
Aggregations