use of de.budschie.bmorph.capabilities.IMorphCapability in project BudschieMorphMod by Budschie.
the class MorphRequestAbilityUsage method handle.
@Override
public void handle(MorphRequestAbilityUsagePacket packet, Supplier<Context> ctx) {
ctx.get().enqueueWork(() -> {
LazyOptional<IMorphCapability> cap = ctx.get().getSender().getCapability(MorphCapabilityAttacher.MORPH_CAP);
if (cap.isPresent()) {
IMorphCapability resolved = cap.resolve().get();
resolved.useAbility(ctx.get().getSender());
}
});
}
use of de.budschie.bmorph.capabilities.IMorphCapability in project BudschieMorphMod by Budschie.
the class MorphRequestMorphIndexChange method handle.
@Override
public void handle(RequestMorphIndexChangePacket packet, Supplier<Context> ctx) {
ctx.get().enqueueWork(() -> {
LazyOptional<IMorphCapability> cap = ctx.get().getSender().getCapability(MorphCapabilityAttacher.MORPH_CAP);
if (cap.isPresent()) {
IMorphCapability resolved = cap.resolve().get();
if (packet.getRequestedIndex() == -1) {
MorphUtil.morphToServer(Optional.empty(), Optional.empty(), ctx.get().getSender());
} else if (packet.getRequestedIndex() >= resolved.getMorphList().getMorphArrayList().size() || packet.getRequestedIndex() < 0) {
System.out.println("Player " + ctx.get().getSender().getName().getString() + " with UUID " + ctx.get().getSender().getUniqueID() + " has tried to send invalid data!");
} else {
ResourceLocation morphToRS = resolved.getMorphList().getMorphArrayList().get(packet.getRequestedIndex()).getEntityType().getRegistryName();
boolean shouldMorph = !ConfigManager.INSTANCE.get(BlacklistData.class).isInBlacklist(morphToRS);
if (shouldMorph)
MorphUtil.morphToServer(Optional.empty(), Optional.of(packet.getRequestedIndex()), ctx.get().getSender());
else
ctx.get().getSender().sendMessage(new StringTextComponent(TextFormatting.RED + "I'm sorry but you can't morph into " + morphToRS.toString() + " as this entity is currently blacklisted."), Util.DUMMY_UUID);
}
}
});
}
use of de.budschie.bmorph.capabilities.IMorphCapability in project BudschieMorphMod by Budschie.
the class MorphCapabilityFullSynchronizer method handle.
@Override
public void handle(MorphPacket packet, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
if (Minecraft.getInstance().world != null) {
PlayerEntity player = Minecraft.getInstance().world.getPlayerByUuid(packet.getPlayer());
if (player != null) {
LazyOptional<IMorphCapability> cap = player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
if (cap.isPresent()) {
IMorphCapability resolved = cap.resolve().get();
resolved.setMorphList(packet.getMorphList());
resolved.setFavouriteList(packet.getFavouriteList());
}
MorphUtil.morphToClient(packet.getEntityData(), packet.getEntityIndex(), packet.getAbilities(), player);
}
}
});
}
use of de.budschie.bmorph.capabilities.IMorphCapability in project BudschieMorphMod by Budschie.
the class MorphRemovedSynchronizer method handle.
@Override
public void handle(MorphRemovedPacket packet, Supplier<Context> ctx) {
ctx.get().enqueueWork(() -> {
if (Minecraft.getInstance().world != null) {
LazyOptional<IMorphCapability> cap = Minecraft.getInstance().world.getPlayerByUuid(packet.getPlayerUUID()).getCapability(MorphCapabilityAttacher.MORPH_CAP);
if (cap.isPresent()) {
IMorphCapability resolved = cap.resolve().get();
resolved.removeFromMorphList(packet.getRemovedMorph());
}
}
});
}
use of de.budschie.bmorph.capabilities.IMorphCapability in project BudschieMorphMod by Budschie.
the class MorphUtil method processCap.
public static void processCap(PlayerEntity player, Consumer<IMorphCapability> capConsumer) {
LazyOptional<IMorphCapability> cap = player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
if (cap.isPresent()) {
IMorphCapability resolved = cap.resolve().get();
capConsumer.accept(resolved);
}
}
Aggregations