Search in sources :

Example 11 with IMorphCapability

use of de.budschie.bmorph.capabilities.IMorphCapability in project BudschieMorphMod by Budschie.

the class Events method onPlayerTakingDamage.

@SubscribeEvent
public static void onPlayerTakingDamage(LivingDamageEvent event) {
    if (event.getEntityLiving() instanceof PlayerEntity) {
        PlayerEntity player = (PlayerEntity) event.getEntityLiving();
        LazyOptional<IMorphCapability> cap = player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
        if (cap.isPresent()) {
            IMorphCapability resolved = cap.resolve().get();
        }
    } else // Check if living is a Mob and therefore "evil"
    if (event.getSource().getTrueSource() instanceof PlayerEntity && event.getEntityLiving() instanceof IMob && !event.getEntity().world.isRemote) {
        PlayerEntity source = (PlayerEntity) event.getSource().getTrueSource();
        LazyOptional<IMorphCapability> cap = source.getCapability(MorphCapabilityAttacher.MORPH_CAP);
        aggro(cap.resolve().get(), ServerSetup.server.getGameRules().getInt(BMorphMod.MORPH_AGGRO_DURATION));
    }
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) IMob(net.minecraft.entity.monster.IMob) LazyOptional(net.minecraftforge.common.util.LazyOptional) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 12 with IMorphCapability

use of de.budschie.bmorph.capabilities.IMorphCapability in project BudschieMorphMod by Budschie.

the class FilteredSimpleMorphGui method showGui.

@Override
public void showGui() {
    @SuppressWarnings("resource") LazyOptional<IMorphCapability> cap = Minecraft.getInstance().player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
    if (cap.isPresent()) {
        IMorphCapability resolved = cap.resolve().get();
        // Create a list of indices of morphs
        List<Integer> morphList = new ArrayList<>();
        // This is dumb
        for (int i = 0; i < resolved.getMorphList().getMorphArrayList().size(); i++) {
            if (filter.test(resolved, i))
                morphList.add(i);
        }
        morphWidgets.add(new MorphWidget(null, false, -1));
        HashMap<EntityType<?>, Pair<MorphWidget, Integer>> currentWidgetHeads = new HashMap<>();
        for (int i = 0; i < morphList.size(); i++) {
            int indexOfMorph = morphList.get(i);
            MorphItem item = resolved.getMorphList().getMorphArrayList().get(indexOfMorph);
            MorphWidget widget = new MorphWidget(item, resolved.getFavouriteList().containsMorphItem(item), indexOfMorph);
            Pair<MorphWidget, Integer> currentWidgetHead = currentWidgetHeads.get(widget.morphItem.getEntityType());
            // Check if there is a head.
            if (currentWidgetHead != null) {
                // There is a head, add to head
                MorphWidget head = currentWidgetHead.getA();
                head.child = widget;
            } else {
                // No head, add to widget list
                morphWidgets.add(widget);
            }
            // Set as new entity head
            currentWidgetHeads.put(widget.morphItem.getEntityType(), new Pair<>(widget, currentWidgetHead == null ? 0 : currentWidgetHead.getB() + 1));
        }
        for (int i = 1; i < morphWidgets.size(); i++) {
            MorphWidget widget = morphWidgets.get(i);
            Pair<MorphWidget, Integer> currentWidgetHead = currentWidgetHeads.get(widget.morphItem.getEntityType());
            widget.depth = currentWidgetHead.getB();
        }
    }
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) MorphItem(de.budschie.bmorph.morph.MorphItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EntityType(net.minecraft.entity.EntityType) Pair(de.budschie.bmorph.util.Pair)

Example 13 with IMorphCapability

use of de.budschie.bmorph.capabilities.IMorphCapability in project BudschieMorphMod by Budschie.

the class MorphCommand method addMorph.

private static int addMorph(List<ServerPlayerEntity> entities, ResourceLocation rs, CompoundNBT nbtData) {
    MorphItem morphItemToAdd = MorphManagerHandlers.FALLBACK.createMorph(ForgeRegistries.ENTITIES.getValue(rs), nbtData, null, true);
    for (ServerPlayerEntity entity : entities) {
        IMorphCapability capability = entity.getCapability(MorphCapabilityAttacher.MORPH_CAP).resolve().get();
        if (capability.getMorphList().contains(morphItemToAdd))
            entity.sendMessage(new StringTextComponent(TextFormatting.RED + "You may not add a morph to your list that is already present."), new UUID(0, 0));
        else {
            entity.sendMessage(new StringTextComponent("Added " + rs.toString() + " with its NBT data to your morph list."), new UUID(0, 0));
            capability.addToMorphList(morphItemToAdd);
            capability.syncMorphAcquisition(entity, morphItemToAdd);
        }
    }
    return 0;
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) MorphItem(de.budschie.bmorph.morph.MorphItem) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) StringTextComponent(net.minecraft.util.text.StringTextComponent) UUID(java.util.UUID)

Example 14 with IMorphCapability

use of de.budschie.bmorph.capabilities.IMorphCapability in project BudschieMorphMod by Budschie.

the class MorphGuiHandler method onPressedKey.

@SubscribeEvent
public static void onPressedKey(ClientTickEvent event) {
    if (event.phase == Phase.END) {
        if (Minecraft.getInstance().world != null) {
            if (!currentMorphGui.isPresent())
                traverseToIndexAndSetGui();
            if (ClientSetup.TOGGLE_MORPH_UI.isPressed()) {
                if (guiHidden)
                    showGui();
                else
                    hideGui();
            }
            if (canGuiBeDisplayed()) {
                if (ClientSetup.SCROLL_DOWN_MORPH_UI.isPressed())
                    currentMorphGui.get().scroll(1);
                if (ClientSetup.SCROLL_UP_MORPH_UI.isPressed())
                    currentMorphGui.get().scroll(-1);
                if (ClientSetup.SCROLL_LEFT_MORPH_UI.isPressed())
                    currentMorphGui.get().horizontalScroll(-1);
                if (ClientSetup.SCROLL_RIGHT_MORPH_UI.isPressed())
                    currentMorphGui.get().horizontalScroll(1);
                if (ClientSetup.NEXT_MORPH_UI.isPressed()) {
                    currentIndex++;
                    currentIndex %= MorphGuiRegistry.REGISTRY.get().getValues().size();
                    traverseToIndexAndSetGui();
                    updateCurrentMorphUI();
                }
                if (ClientSetup.PREVIOUS_MORPH_UI.isPressed()) {
                    currentIndex--;
                    currentIndex %= MorphGuiRegistry.REGISTRY.get().getValues().size();
                    traverseToIndexAndSetGui();
                    updateCurrentMorphUI();
                }
                if (ClientSetup.TOGGLE_MORPH_FAVOURITE.isPressed()) {
                    LazyOptional<IMorphCapability> cap = Minecraft.getInstance().player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
                    if (cap.isPresent()) {
                        IMorphCapability resolved = cap.resolve().get();
                        int favouriteMorphIndex = currentMorphGui.get().getMorphIndex();
                        if (favouriteMorphIndex < 0)
                            System.out.println("Yo wat");
                        else {
                            if (resolved.getFavouriteList().containsMorphItem(resolved.getMorphList().getMorphArrayList().get(favouriteMorphIndex)))
                                FavouriteNetworkingHelper.removeFavouriteMorph(favouriteMorphIndex);
                            else
                                FavouriteNetworkingHelper.addFavouriteMorph(favouriteMorphIndex);
                        }
                    }
                    currentMorphGui.ifPresent(morphGui -> morphGui.onFavouriteChanged());
                }
            }
            if (ClientSetup.USE_ABILITY_KEY.isPressed())
                MainNetworkChannel.INSTANCE.sendToServer(new MorphRequestAbilityUsage.MorphRequestAbilityUsagePacket());
        }
    }
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 15 with IMorphCapability

use of de.budschie.bmorph.capabilities.IMorphCapability 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)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