use of com.lying.variousoddities.species.Species in project VariousOddities by Lyinginbedmon.
the class ScreenSelectSpecies method render.
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
renderDirtBackground(0);
this.speciesList.render(matrixStack, mouseX, mouseY, partialTicks);
this.abilityList.render(matrixStack, mouseX, mouseY, partialTicks);
renderBackgroundLayer(matrixStack, partialTicks);
hideListEdge();
drawListBorder(matrixStack, this.speciesList, this.height, 0, 180, 6, TEXTURE);
int yPos = 20;
drawCenteredString(matrixStack, this.font, this.title, this.width / 2, 12, 16777215);
yPos += 15;
if (selectableSpecies.isEmpty())
return;
// Draw species display name
Species currentSpecies = getCurrentSpecies();
this.selectButton.setMessage(currentSpecies.getDisplayName());
yPos += this.font.FONT_HEIGHT + 12;
// Render stars of appropriate colour for power
drawStars(matrixStack, yPos, currentSpecies.getPower());
yPos += this.font.FONT_HEIGHT + 3;
// Display types
int health = 20;
if (currentSpecies.hasTypes()) {
ITextComponent typesHeader = currentSpecies.getTypes().toHeader();
drawCenteredString(matrixStack, this.font, typesHeader, this.width / 2, yPos, -1);
health = (int) currentSpecies.getTypes().getPlayerHealth();
}
// Health and armour
yPos += this.font.FONT_HEIGHT + 3;
double armour = 0;
List<Ability> abilities = currentSpecies.getFullAbilities();
if (!abilities.isEmpty())
for (Ability ability : abilities) {
if (ability.getRegistryName().equals(AbilityNaturalArmour.REGISTRY_NAME))
armour += ((AbilityNaturalArmour) ability).amount();
if (ability.getRegistryName().equals(AbilityModifierCon.REGISTRY_NAME))
health += ((AbilityModifier) ability).amount();
}
;
drawHealthAndArmour(matrixStack, this.font, this.width / 2, yPos, health, (int) armour);
// Display abilities
yPos += this.font.FONT_HEIGHT + 3;
this.abilityList.setTop(yPos);
super.render(matrixStack, mouseX, mouseY, partialTicks);
}
use of com.lying.variousoddities.species.Species in project VariousOddities by Lyinginbedmon.
the class PacketSpeciesSelected method handle.
public static void handle(PacketSpeciesSelected msg, Supplier<NetworkEvent.Context> cxt) {
NetworkEvent.Context context = cxt.get();
if (context.getDirection().getReceptionSide().isServer()) {
World world = context.getSender().getEntityWorld();
PlayerEntity player = world.getPlayerByUuid(msg.playerID);
if (player != null) {
LivingData data = LivingData.forEntity(player);
if (data != null) {
if (msg.selectedSpecies == null)
data.setSpecies((SpeciesInstance) null);
else {
Species selected = SpeciesRegistry.getSpecies(msg.selectedSpecies);
if (!data.hasSpecies() || (data.getSpecies().getRegistryName() != msg.selectedSpecies && selected != null))
data.setSpecies(selected);
}
data.setSpeciesSelected();
if (!msg.keepTypes && data.hasCustomTypes())
data.clearCustomTypes();
data.clearTemplates();
for (ResourceLocation templateName : msg.selectedTemplates) {
Template template = VORegistries.TEMPLATES.get(templateName);
if (template != null)
data.addTemplateInitial(template);
}
SpeciesEvent.SpeciesSelected event = new SpeciesSelected(player, msg.selectedSpecies, msg.selectedTemplates);
MinecraftForge.EVENT_BUS.post(event);
}
}
}
context.setPacketHandled(true);
}
use of com.lying.variousoddities.species.Species in project VariousOddities by Lyinginbedmon.
the class CommandSpecies method setSpecies.
private static int setSpecies(Entity entity, ResourceLocation name, CommandSource source) throws CommandSyntaxException {
if (entity instanceof LivingEntity) {
LivingEntity living = (LivingEntity) entity;
LivingData data = LivingData.forEntity(living);
Species species = SpeciesRegistry.getSpecies(name);
if (species != null) {
data.setSpecies(species);
source.sendFeedback(new TranslationTextComponent(translationSlug + "set", living.getDisplayName(), name), true);
return 15;
} else
throw SPECIES_INVALID_EXCEPTION.create(name);
} else
throw INVALID_ENTITY_EXCEPTION.create();
}
use of com.lying.variousoddities.species.Species in project VariousOddities by Lyinginbedmon.
the class VOSpeciesProvider method act.
public void act(DirectoryCache cache) throws IOException {
Path path = this.dataGenerator.getOutputFolder();
Map<ResourceLocation, Species> map = Maps.newHashMap();
SpeciesRegistry.getDefaultSpecies().forEach((species) -> {
if (map.put(species.getRegistryName(), species) != null)
throw new IllegalStateException("Duplicate species " + species.getRegistryName());
});
map.forEach((name, species) -> {
Path filePath = getPath(path, name);
try {
IDataProvider.save(GSON, cache, species.toJson(), filePath);
} catch (IOException e) {
VariousOddities.log.error("Couldn't save species {}", filePath, e);
}
});
}
use of com.lying.variousoddities.species.Species in project VariousOddities by Lyinginbedmon.
the class PacketSyncSpecies method handle.
public static void handle(PacketSyncSpecies msg, Supplier<NetworkEvent.Context> cxt) {
VORegistries.SPECIES.clear();
ListNBT data = msg.speciesData.getList("Species", 10);
for (int i = 0; i < data.size(); i++) {
Species species = null;
try {
species = Species.createFromNBT(data.getCompound(i));
} catch (Exception e) {
VariousOddities.log.error("Malformed species received from server, data: " + data.getCompound(i));
}
if (species != null && species.getRegistryName() != null)
VORegistries.SPECIES.put(species.getRegistryName(), species);
}
cxt.get().setPacketHandled(true);
}
Aggregations