Search in sources :

Example 1 with IMorphCapability

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());
        }
    });
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability)

Example 2 with IMorphCapability

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);
            }
        }
    });
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) ResourceLocation(net.minecraft.util.ResourceLocation) BlacklistData(de.budschie.bmorph.capabilities.blacklist.BlacklistData) StringTextComponent(net.minecraft.util.text.StringTextComponent)

Example 3 with IMorphCapability

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);
            }
        }
    });
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 4 with IMorphCapability

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());
            }
        }
    });
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability)

Example 5 with IMorphCapability

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);
    }
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability)

Aggregations

IMorphCapability (de.budschie.bmorph.capabilities.IMorphCapability)24 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)12 PlayerEntity (net.minecraft.entity.player.PlayerEntity)11 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)7 MorphItem (de.budschie.bmorph.morph.MorphItem)5 MorphEntity (de.budschie.bmorph.entity.MorphEntity)3 UUID (java.util.UUID)3 Entity (net.minecraft.entity.Entity)3 MobEntity (net.minecraft.entity.MobEntity)3 StringTextComponent (net.minecraft.util.text.StringTextComponent)3 ArrayList (java.util.ArrayList)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 BlacklistData (de.budschie.bmorph.capabilities.blacklist.BlacklistData)1 Ability (de.budschie.bmorph.morph.functionality.Ability)1 AdvancedAbstractClientPlayerEntity (de.budschie.bmorph.morph.player.AdvancedAbstractClientPlayerEntity)1 MorphRequestFavouriteChangePacket (de.budschie.bmorph.network.MorphRequestFavouriteChange.MorphRequestFavouriteChangePacket)1 Pair (de.budschie.bmorph.util.Pair)1 HashMap (java.util.HashMap)1 AbstractClientPlayerEntity (net.minecraft.client.entity.player.AbstractClientPlayerEntity)1 EntitySize (net.minecraft.entity.EntitySize)1