Search in sources :

Example 46 with EntityType

use of net.minecraft.entity.EntityType in project Vampirism by TeamLapen.

the class PlayerMinionController method deserializeNBT.

@Override
public void deserializeNBT(CompoundNBT nbt) {
    IFaction<?> f = VampirismAPI.factionRegistry().getFactionByID(new ResourceLocation(nbt.getString("faction")));
    if (!(f instanceof IPlayableFaction)) {
        this.maxMinions = 0;
        return;
    }
    this.faction = (IPlayableFaction<?>) f;
    this.maxMinions = nbt.getInt("max_minions");
    ListNBT data = nbt.getList("data", 10);
    MinionInfo[] infos = new MinionInfo[data.size()];
    // noinspection unchecked
    Optional<Integer>[] tokens = new Optional[data.size()];
    for (INBT n : data) {
        CompoundNBT tag = (CompoundNBT) n;
        int id = tag.getInt("id");
        MinionData d = MinionData.fromNBT(tag);
        ResourceLocation entityTypeID = new ResourceLocation(tag.getString("entity_type"));
        if (!ForgeRegistries.ENTITIES.containsKey(entityTypeID)) {
            LOGGER.warn("Cannot find saved minion type {}. Aborting controller load", entityTypeID);
            this.minions = new MinionInfo[0];
            // noinspection unchecked
            this.minionTokens = new Optional[0];
            return;
        }
        EntityType type = ForgeRegistries.ENTITIES.getValue(entityTypeID);
        MinionInfo i = new MinionInfo(id, d, type);
        i.deathCooldown = tag.getInt("death_timer");
        infos[id] = i;
        if (tag.contains("token", 99)) {
            tokens[id] = Optional.of(tag.getInt("token"));
        } else {
            tokens[id] = Optional.empty();
        }
    }
    this.minions = infos;
    this.minionTokens = tokens;
}
Also used : LazyOptional(net.minecraftforge.common.util.LazyOptional) CompoundNBT(net.minecraft.nbt.CompoundNBT) IPlayableFaction(de.teamlapen.vampirism.api.entity.factions.IPlayableFaction) EntityType(net.minecraft.entity.EntityType) ListNBT(net.minecraft.nbt.ListNBT) INBT(net.minecraft.nbt.INBT) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 47 with EntityType

use of net.minecraft.entity.EntityType in project Vampirism by TeamLapen.

the class ClientProxy method registerVampireEntityOverlays.

private void registerVampireEntityOverlays() {
    EntityRendererManager manager = Minecraft.getInstance().getEntityRenderDispatcher();
    registerVampirePlayerHead(manager);
    for (Map.Entry<EntityType<? extends CreatureEntity>, ResourceLocation> entry : VampirismAPI.entityRegistry().getConvertibleOverlay().entrySet()) {
        registerVampireEntityOverlay(manager, entry.getKey(), entry.getValue());
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) ResourceLocation(net.minecraft.util.ResourceLocation) CreatureEntity(net.minecraft.entity.CreatureEntity) Map(java.util.Map) EntityRendererManager(net.minecraft.client.renderer.entity.EntityRendererManager)

Example 48 with EntityType

use of net.minecraft.entity.EntityType in project cem by dorianpb.

the class EntityModelLoaderMixin method loadResourceFromId.

private void loadResourceFromId(ResourceManager manager, Identifier id, String namespace) {
    if (!id.getNamespace().equals(namespace)) {
        return;
    }
    CemFairy.getLogger().info(id.toString());
    try (InputStream stream = manager.getResource(id).getInputStream()) {
        // initialize the file
        @SuppressWarnings("unchecked") LinkedTreeMap<String, Object> json = CemFairy.getGson().fromJson(new InputStreamReader(stream, StandardCharsets.UTF_8), LinkedTreeMap.class);
        if (json == null) {
            throw new Exception("Invalid File");
        }
        JemFile file = new JemFile(json, id, manager);
        String entityName = CemFairy.getEntityNameFromId(id);
        Optional<EntityType<?>> entityTypeOptional = EntityType.get(entityName);
        Optional<BlockEntityType<?>> blockEntityTypeOptional = Registry.BLOCK_ENTITY_TYPE.getOrEmpty(Identifier.tryParse(entityName));
        if (entityTypeOptional.isPresent()) {
            EntityType<? extends Entity> entityType = entityTypeOptional.get();
            if (CemFairy.isUnsupported(entityType)) {
                throw new Exception("Entity \"" + EntityType.getId(entityType) + "\" is unsupported!");
            }
            CemRegistryManager.addRegistry(entityType, file);
        } else if (blockEntityTypeOptional.isPresent()) {
            BlockEntityType<? extends BlockEntity> entityType = blockEntityTypeOptional.get();
            if (CemFairy.isUnsupported(entityType)) {
                throw new Exception("Block Entity \"" + BlockEntityType.getId(entityType) + "\" is unsupported!");
            }
            CemRegistryManager.addRegistry(entityType, file);
        } else {
            if (CemFairy.isUnsupported(entityName)) {
                throw new Exception("Unknown object \"" + entityName + "\"!");
            } else {
                CemRegistryManager.addRegistry(entityName, file);
            }
        }
    } catch (Exception exception) {
        CemFairy.getLogger().error("Error parsing " + id + ":");
        String message = exception.getMessage();
        CemFairy.getLogger().error(exception);
        if (message == null || message.trim().equals("")) {
            CemFairy.getLogger().error(exception.getStackTrace()[0]);
            CemFairy.getLogger().error(exception.getStackTrace()[1]);
            CemFairy.getLogger().error(exception.getStackTrace()[2]);
        }
    }
}
Also used : BlockEntityType(net.minecraft.block.entity.BlockEntityType) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) JemFile(net.dorianpb.cem.internal.file.JemFile) EntityType(net.minecraft.entity.EntityType) BlockEntityType(net.minecraft.block.entity.BlockEntityType) BlockEntity(net.minecraft.block.entity.BlockEntity)

Aggregations

EntityType (net.minecraft.entity.EntityType)48 Entity (net.minecraft.entity.Entity)16 ResourceLocation (net.minecraft.util.ResourceLocation)13 LivingEntity (net.minecraft.entity.LivingEntity)11 CompoundNBT (net.minecraft.nbt.CompoundNBT)11 BlockPos (net.minecraft.util.math.BlockPos)11 PlayerEntity (net.minecraft.entity.player.PlayerEntity)9 ItemStack (net.minecraft.item.ItemStack)9 HashMap (java.util.HashMap)6 World (net.minecraft.world.World)5 ArrayList (java.util.ArrayList)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 EffectInstance (net.minecraft.potion.EffectInstance)4 List (java.util.List)3 Nonnull (javax.annotation.Nonnull)3 MobEntity (net.minecraft.entity.MobEntity)3 TileEntity (net.minecraft.tileentity.TileEntity)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 IPlacementHandler (com.ldtteam.structurize.placement.handlers.placement.IPlacementHandler)2 Random (java.util.Random)2