use of com.lying.variousoddities.species.Template in project VariousOddities by Lyinginbedmon.
the class ScreenSelectTemplates method removeTemplate.
/**
* Removes the given template from the applied list and updates the available list
*/
public void removeTemplate(Template template) {
List<Template> applied = this.listApplied.getTemplates();
applied.remove(template);
// Quality control
boolean noHits = false;
while (!noHits) {
// Iterate through applied templates, breaking when invalid found
List<Template> tested = Lists.newArrayList();
Template hitFound = null;
for (Template extant : applied) {
Pair<Types, Map<ResourceLocation, Ability>> atStep = processTemplates(tested.toArray(new Template[0]));
if (testTemplate(extant, atStep))
tested.add(extant);
else {
hitFound = extant;
break;
}
}
if (hitFound != null)
applied.remove(hitFound);
else
noHits = true;
}
this.listApplied.setEntries(applied);
this.listAvailable.setEntries(getViableTemplates());
}
use of com.lying.variousoddities.species.Template in project VariousOddities by Lyinginbedmon.
the class ScreenSelectTemplates method renderHighlightedEntry.
private void renderHighlightedEntry(MatrixStack matrixStack, int mouseX, int mouseY) {
Template template = this.highlightEntry.template;
List<ITextComponent> tooltip = Lists.newArrayList();
if (!template.getPreconditions().isEmpty() && !this.player.isCreative()) {
tooltip.add(new TranslationTextComponent("command." + Reference.ModInfo.MOD_ID + ".species.templates.info_preconditions", template.getPreconditions().size()));
template.getPreconditions().forEach((precondition) -> {
tooltip.add(new StringTextComponent(" ").append(precondition.translate()));
});
}
if (!template.getOperations().isEmpty()) {
if (!tooltip.isEmpty())
tooltip.add(new StringTextComponent(""));
tooltip.add(new TranslationTextComponent("command." + Reference.ModInfo.MOD_ID + ".species.templates.info_operations", template.getOperations().size()));
List<TemplateOperation> totalOperations = Lists.newArrayList();
totalOperations.addAll(template.getOperations());
while (!totalOperations.isEmpty()) {
List<TemplateOperation> group = Lists.newArrayList();
for (TemplateOperation operation : totalOperations) if (group.isEmpty() || operation.canStackWith(group.get(0)))
group.add(operation);
totalOperations.removeAll(group);
if (group.size() > 1)
group.get(0).stackAsList(group).forEach((entry) -> {
tooltip.add(new StringTextComponent(" ").append(entry));
});
else
tooltip.add(new StringTextComponent(" ").append(group.get(0).translate()));
}
}
renderWrappedToolTip(matrixStack, tooltip, mouseX, mouseY, font);
}
use of com.lying.variousoddities.species.Template in project VariousOddities by Lyinginbedmon.
the class ScreenSelectTemplates method getViableTemplates.
/**
* Returns a list of templates applicable to the current set and within the power budget
*/
public List<Template> getViableTemplates() {
List<Template> templates = Lists.newArrayList();
List<Template> applied = this.listApplied == null ? Lists.newArrayList() : this.listApplied.getTemplates();
if (player.isCreative()) {
templates.addAll(VORegistries.TEMPLATES.values());
templates.removeAll(applied);
} else {
int currentPower = totalPower();
for (Template template : VORegistries.TEMPLATES.values()) if (!applied.contains(template))
if (currentPower + template.getPower() <= this.targetPower && testTemplate(template))
templates.add(template);
}
templates.sort(TEMPLATE_SORT);
return templates;
}
use of com.lying.variousoddities.species.Template in project VariousOddities by Lyinginbedmon.
the class Abilities method getEntityAbilities.
public Map<ResourceLocation, Ability> getEntityAbilities(@Nullable LivingEntity entityIn) {
if (entityIn != null) {
Map<ResourceLocation, Ability> abilityMap = new HashMap<>();
// Collect abilities from creature's types
EnumCreatureType.getTypes(entityIn).addAbilitiesToMap(abilityMap);
// Collect abilities from creature's LivingData
LivingData bodyData = LivingData.forEntity(entityIn);
if (bodyData != null) {
if (bodyData.hasSpecies())
abilityMap = bodyData.getSpecies().addToMap(abilityMap);
if (bodyData.hasTemplates())
for (Template template : bodyData.getTemplates()) template.applyAbilityOperations(abilityMap);
abilityMap = bodyData.getAbilities().addCustomToMap(abilityMap);
}
// Remove any existing temporary abilities (these should never exist in the standard sources)
List<ResourceLocation> invalid = Lists.newArrayList();
abilityMap.forEach((mapName, ability) -> {
if (ability.isTemporary())
invalid.add(mapName);
});
for (ResourceLocation mapName : invalid) abilityMap.remove(mapName);
GatherAbilitiesEvent event = new GatherAbilitiesEvent(entityIn, abilityMap, cachedAbilities);
MinecraftForge.EVENT_BUS.post(event);
abilityMap = event.getAbilityMap();
// Add in new temporary abilities
for (Ability ability : event.getTempAbilities().values()) if (!abilityMap.containsKey(ability.getMapName()))
abilityMap.put(ability.getMapName(), ability);
List<Ability> subAbilities = gatherSubAbilities(abilityMap.values());
if (!subAbilities.isEmpty())
for (Ability ability : subAbilities) if (!abilityMap.containsKey(ability.getMapName()))
abilityMap.put(ability.getMapName(), ability.clone().setTemporary());
return abilityMap;
}
return new HashMap<>();
}
use of com.lying.variousoddities.species.Template 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);
}
Aggregations