Search in sources :

Example 1 with MorphItem

use of de.budschie.bmorph.morph.MorphItem in project BudschieMorphMod by Budschie.

the class MorphCapabilityFullSynchronizer method decode.

@Override
public MorphPacket decode(PacketBuffer buffer) {
    UUID playerUUID = buffer.readUniqueId();
    // Hmmm yeah the floor is made out of floor
    MorphList morphList = new MorphList();
    morphList.deserializePacket(buffer);
    FavouriteList favouriteList = new FavouriteList(morphList);
    favouriteList.deserializePacket(buffer);
    Optional<MorphItem> toMorph = Optional.empty();
    Optional<Integer> entityIndex = Optional.empty();
    boolean hasMorph = buffer.readBoolean(), hasIndex = buffer.readBoolean();
    if (hasMorph)
        toMorph = Optional.of(MorphHandler.deserializeMorphItem(buffer.readCompoundTag()));
    if (hasIndex)
        entityIndex = Optional.of(buffer.readInt());
    int amountOfAbilities = buffer.readInt();
    ArrayList<String> abilities = new ArrayList<>(amountOfAbilities);
    for (int i = 0; i < amountOfAbilities; i++) abilities.add(buffer.readString());
    return new MorphPacket(toMorph, entityIndex, morphList, favouriteList, abilities, playerUUID);
}
Also used : MorphPacket(de.budschie.bmorph.network.MorphCapabilityFullSynchronizer.MorphPacket) FavouriteList(de.budschie.bmorph.morph.FavouriteList) MorphItem(de.budschie.bmorph.morph.MorphItem) ArrayList(java.util.ArrayList) UUID(java.util.UUID) MorphList(de.budschie.bmorph.morph.MorphList)

Example 2 with MorphItem

use of de.budschie.bmorph.morph.MorphItem in project BudschieMorphMod by Budschie.

the class Events method onPlayerDeathEvent.

@SubscribeEvent
public static void onPlayerDeathEvent(LivingDeathEvent event) {
    if (event.getEntityLiving() instanceof PlayerEntity && !event.getEntity().world.isRemote) {
        PlayerEntity player = (PlayerEntity) event.getEntityLiving();
        LazyOptional<IMorphCapability> cap = player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
        if (cap.isPresent()) {
            IMorphCapability resolved = cap.resolve().get();
            resolved.deapplyAbilities(player);
            if (!ServerSetup.server.getGameRules().getBoolean(BMorphMod.KEEP_MORPH_INVENTORY)) {
                for (MorphItem item : resolved.getMorphList().getMorphArrayList()) {
                    MorphEntity morphEntity = new MorphEntity(player.world, item);
                    morphEntity.setPosition(player.getPosX(), player.getPosY(), player.getPosZ());
                    player.world.addEntity(morphEntity);
                }
            }
        }
    }
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) MorphItem(de.budschie.bmorph.morph.MorphItem) MorphEntity(de.budschie.bmorph.entity.MorphEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with MorphItem

use of de.budschie.bmorph.morph.MorphItem in project BudschieMorphMod by Budschie.

the class Events method onPlayerKilledLivingEntity.

@SubscribeEvent
public static void onPlayerKilledLivingEntity(LivingDeathEvent event) {
    if (!event.getEntity().world.isRemote && ServerSetup.server.getGameRules().getBoolean(BMorphMod.DO_MORPH_DROPS)) {
        if (event.getSource().getTrueSource() instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) event.getSource().getTrueSource();
            if (!(player instanceof FakePlayer)) {
                LazyOptional<IMorphCapability> playerMorph = player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
                if (playerMorph.isPresent()) {
                    MorphItem morphItem = MorphManagerHandlers.createMorphFromDeadEntity(event.getEntity());
                    if (morphItem != null) {
                        IMorphCapability resolved = playerMorph.resolve().get();
                        boolean shouldMorph = !ConfigManager.INSTANCE.get(BlacklistData.class).isInBlacklist(event.getEntity().getType().getRegistryName());
                        if (!resolved.getMorphList().contains(morphItem) && shouldMorph) {
                            MorphEntity morphEntity = new MorphEntity(event.getEntity().world, morphItem);
                            morphEntity.setPosition(event.getEntity().getPosX(), event.getEntity().getPosY(), event.getEntity().getPosZ());
                            event.getEntity().world.addEntity(morphEntity);
                        }
                    }
                }
            }
        }
    }
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) MorphItem(de.budschie.bmorph.morph.MorphItem) MorphEntity(de.budschie.bmorph.entity.MorphEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FakePlayer(net.minecraftforge.common.util.FakePlayer) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 4 with MorphItem

use of de.budschie.bmorph.morph.MorphItem 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 5 with MorphItem

use of de.budschie.bmorph.morph.MorphItem 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)

Aggregations

MorphItem (de.budschie.bmorph.morph.MorphItem)7 IMorphCapability (de.budschie.bmorph.capabilities.IMorphCapability)5 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)3 MorphEntity (de.budschie.bmorph.entity.MorphEntity)2 FavouriteList (de.budschie.bmorph.morph.FavouriteList)1 MorphList (de.budschie.bmorph.morph.MorphList)1 AdvancedAbstractClientPlayerEntity (de.budschie.bmorph.morph.player.AdvancedAbstractClientPlayerEntity)1 MorphPacket (de.budschie.bmorph.network.MorphCapabilityFullSynchronizer.MorphPacket)1 MorphChangedPacket (de.budschie.bmorph.network.MorphChangedSynchronizer.MorphChangedPacket)1 Pair (de.budschie.bmorph.util.Pair)1 HashMap (java.util.HashMap)1 AbstractClientPlayerEntity (net.minecraft.client.entity.player.AbstractClientPlayerEntity)1 Entity (net.minecraft.entity.Entity)1 EntityType (net.minecraft.entity.EntityType)1 MobEntity (net.minecraft.entity.MobEntity)1 AbstractSkeletonEntity (net.minecraft.entity.monster.AbstractSkeletonEntity)1