Search in sources :

Example 6 with EntityArchetype

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));
    }
}
Also used : WeightedObject(org.spongepowered.api.util.weighted.WeightedObject) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WeightedSpawnerEntity(net.minecraft.util.WeightedSpawnerEntity)

Example 7 with EntityArchetype

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;
            }
        }
    }
}
Also used : EntityArchetype(org.spongepowered.api.entity.EntityArchetype) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Aggregations

EntityArchetype (org.spongepowered.api.entity.EntityArchetype)7 EntityType (org.spongepowered.api.entity.EntityType)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 WeightedSpawnerEntity (net.minecraft.util.WeightedSpawnerEntity)2 WeightedSerializableObject (org.spongepowered.api.util.weighted.WeightedSerializableObject)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 Vector3i (com.flowpowered.math.vector.Vector3i)1 TypeToken (com.google.common.reflect.TypeToken)1 Field (java.lang.reflect.Field)1 Instant (java.time.Instant)1 List (java.util.List)1 UUID (java.util.UUID)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 Permission (org.cubeengine.libcube.service.permission.Permission)1 LanternKeyFactory.makeImmutableBoundedValueKey (org.lanternpowered.server.data.key.LanternKeyFactory.makeImmutableBoundedValueKey)1 LanternKeyFactory.makeListKey (org.lanternpowered.server.data.key.LanternKeyFactory.makeListKey)1 LanternKeyFactory.makeMutableBoundedValueKey (org.lanternpowered.server.data.key.LanternKeyFactory.makeMutableBoundedValueKey)1 LanternKeyFactory.makeOptionalKey (org.lanternpowered.server.data.key.LanternKeyFactory.makeOptionalKey)1 LanternKeyFactory.makePatternListKey (org.lanternpowered.server.data.key.LanternKeyFactory.makePatternListKey)1 LanternKeyFactory.makeSetKey (org.lanternpowered.server.data.key.LanternKeyFactory.makeSetKey)1