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;
}
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());
}
}
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]);
}
}
}
Aggregations