use of com.lying.variousoddities.species.Species.SpeciesInstance 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.SpeciesInstance in project VariousOddities by Lyinginbedmon.
the class SpeciesRegistry method instanceFromNBT.
@Nullable
public static SpeciesInstance instanceFromNBT(CompoundNBT compound) {
ResourceLocation name = new ResourceLocation(compound.getString("Name"));
Species species = getSpecies(name);
if (species != null) {
SpeciesInstance instance = species.createInstance();
instance.readFromNBT(compound);
return instance;
}
return null;
}
Aggregations