Search in sources :

Example 1 with MorphRequestFavouriteChangePacket

use of de.budschie.bmorph.network.MorphRequestFavouriteChange.MorphRequestFavouriteChangePacket in project BudschieMorphMod by Budschie.

the class FavouriteNetworkingHelper method internalAddFavouriteMorph.

// DRY CODE
private static void internalAddFavouriteMorph(boolean add, int indexInMorphArray) {
    PlayerEntity player = Minecraft.getInstance().player;
    LazyOptional<IMorphCapability> cap = player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
    if (cap.isPresent()) {
        IMorphCapability resolved = cap.resolve().get();
        if (add)
            resolved.getFavouriteList().addFavourite(indexInMorphArray);
        else
            resolved.getFavouriteList().removeFavourite(indexInMorphArray);
        MorphRequestFavouriteChangePacket favouritePacket = new MorphRequestFavouriteChangePacket(add, indexInMorphArray);
        MainNetworkChannel.INSTANCE.sendToServer(favouritePacket);
    } else {
        LOGGER.warn("Can't " + (add ? "add" : "remove") + "morph " + indexInMorphArray + " as a favourite, as the capability for morphs is not loaded yet.");
    }
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) MorphRequestFavouriteChangePacket(de.budschie.bmorph.network.MorphRequestFavouriteChange.MorphRequestFavouriteChangePacket) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

IMorphCapability (de.budschie.bmorph.capabilities.IMorphCapability)1 MorphRequestFavouriteChangePacket (de.budschie.bmorph.network.MorphRequestFavouriteChange.MorphRequestFavouriteChangePacket)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1