use of de.budschie.bmorph.morph.functionality.Ability in project BudschieMorphMod by Budschie.
the class MorphAbilityManager method apply.
@Override
protected void apply(Map<ResourceLocation, JsonElement> objectIn, IResourceManager resourceManagerIn, IProfiler profilerIn) {
abilityLookup.clear();
HashMap<String, MorphAbilityEntry> abilityEntries = new HashMap<>();
// Load in all granted and revoked abilities and store this data in an HashMap with a String representing the entity resource location as a
// key and a MorphAbilityEntry as a value.
objectIn.forEach((resourceLocation, json) -> {
try {
JsonObject root = json.getAsJsonObject();
String entity = root.get("entity_type").getAsString();
JsonArray grantedAbilities = root.getAsJsonArray("grant");
JsonArray revokedAbilities = root.getAsJsonArray("revoke");
MorphAbilityEntry entry = abilityEntries.computeIfAbsent(entity, key -> new MorphAbilityEntry());
for (int i = 0; i < grantedAbilities.size(); i++) {
entry.grantAbility(grantedAbilities.get(i).getAsString());
}
for (int i = 0; i < revokedAbilities.size(); i++) {
entry.revokeAbility(revokedAbilities.get(i).getAsString());
}
} catch (Exception e) {
e.printStackTrace();
}
});
// Resolve the stored data
this.lazyResolve = () -> {
abilityEntries.forEach((entity, entry) -> {
try {
EntityType<?> entityType = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(entity));
if (!ForgeRegistries.ENTITIES.containsKey(new ResourceLocation(entity))) {
LOGGER.warn(String.format("The given entity %s is not known to the game. Skipping this entry. Please make sure to only load this when the mod for the entity is present. You can do this by putting this JSON file in \"data/<modname>/morph_abilities\".", entity));
} else {
List<Ability> resolvedAbilities = entry.resolve();
abilityLookup.put(entityType, resolvedAbilities);
}
} catch (Exception ex) {
ex.printStackTrace();
}
});
};
}
use of de.budschie.bmorph.morph.functionality.Ability in project BudschieMorphMod by Budschie.
the class ConfiguredAbilitySynchronizer method encode.
@Override
public void encode(ConfiguredAbilityPacket packet, PacketBuffer buffer) {
for (Ability ability : packet.getAbilities()) {
Optional<CompoundNBT> serialized = ability.getConfigurableAbility().serializeNBTIAmTooDumbForJava(ability);
if (serialized.isPresent()) {
buffer.writeString(ability.getResourceLocation().toString());
buffer.writeString(ability.getConfigurableAbility().getRegistryName().toString());
buffer.writeCompoundTag(serialized.get());
}
}
buffer.writeString("");
}
use of de.budschie.bmorph.morph.functionality.Ability in project BudschieMorphMod by Budschie.
the class RandomDelegatingOnUseAbility method onUsedAbility.
@Override
public void onUsedAbility(PlayerEntity player, MorphItem currentMorph) {
if (!isCurrentlyStunned(player.getUniqueID())) {
stun(player.getUniqueID());
ResourceLocation randomRL = weightedList.getRandomValue(player.getEntityWorld().getRandom());
Ability ability = BMorphMod.DYNAMIC_ABILITY_REGISTRY.getAbility(randomRL);
if (ability == null) {
LOGGER.warn(String.format("The random delegating ability %s tried to delegate its work to %s, but that ability doesn't exist.", this.getResourceLocation(), randomRL));
} else {
ability.onUsedAbility(player, currentMorph);
}
}
}
use of de.budschie.bmorph.morph.functionality.Ability in project BudschieMorphMod by Budschie.
the class MorphUtil method morphToClient.
/**
* This method is used to invoke functions required for handling a sync on the server on the client side. *
*/
public static void morphToClient(Optional<MorphItem> morphItem, Optional<Integer> morphIndex, ArrayList<String> abilities, PlayerEntity player) {
if (player != null) {
LazyOptional<IMorphCapability> cap = player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
if (cap.isPresent()) {
IMorphCapability resolved = cap.resolve().get();
MorphItem aboutToMorphTo = null;
if (morphItem.isPresent())
aboutToMorphTo = morphItem.get();
else if (morphIndex.isPresent())
aboutToMorphTo = resolved.getMorphList().getMorphArrayList().get(morphIndex.get());
MinecraftForge.EVENT_BUS.post(new PlayerMorphEvent.Client.Pre(player, resolved, aboutToMorphTo));
resolved.deapplyAbilities(player);
if (morphIndex.isPresent())
resolved.setMorph(morphIndex.get());
else if (morphItem.isPresent())
resolved.setMorph(morphItem.get());
else
resolved.demorph();
ArrayList<Ability> resolvedAbilities = new ArrayList<>();
for (String name : abilities) {
ResourceLocation resourceLocation = new ResourceLocation(name);
Ability foundAbility = BMorphMod.DYNAMIC_ABILITY_REGISTRY.getAbility(resourceLocation);
if (foundAbility == null) {
LOGGER.warn("The ability %s is not present on the client. Ignoring this entry.", resourceLocation);
} else
resolvedAbilities.add(foundAbility);
}
MorphItem javaSucks = aboutToMorphTo;
resolved.setCurrentAbilities(resolvedAbilities);
// Create entity right before we apply the abilities
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> RenderHandler.onBuildNewEntity(player, resolved, javaSucks));
resolved.applyAbilities(player);
MinecraftForge.EVENT_BUS.post(new PlayerMorphEvent.Client.Post(player, resolved, aboutToMorphTo));
} else
System.out.println("Could not synchronize data, as the morph cap is not created yet.");
}
}
Aggregations