Search in sources :

Example 16 with IMorphCapability

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

the class Events method onPlayerJoined.

@SubscribeEvent
public static void onPlayerJoined(PlayerLoggedInEvent event) {
    if (!event.getEntity().world.isRemote) {
        PlayerEntity player = event.getPlayer();
        LazyOptional<IMorphCapability> cap = player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
        if (cap.isPresent()) {
            MinecraftForge.EVENT_BUS.post(new PlayerMorphEvent.Server.Pre(player, cap.resolve().get(), cap.resolve().get().getCurrentMorph().orElse(null)));
            // ServerSetup.server.getPlayerList().getPlayers().forEach(serverPlayer -> cap.resolve().get().syncWithClient(event.getPlayer(), serverPlayer));
            // ServerSetup.server.getPlayerList().getPlayers().forEach(serverPlayer -> cap.resolve().get().syncWithClient(serverPlayer, (ServerPlayerEntity) event.getPlayer()));
            cap.resolve().get().getCurrentMorph().ifPresent(morph -> cap.resolve().get().setCurrentAbilities(MORPH_ABILITY_MANAGER.getAbilitiesFor(morph)));
            cap.resolve().get().syncWithClients(player);
            cap.resolve().get().applyHealthOnPlayer(player);
            cap.resolve().get().applyAbilities(player);
            MinecraftForge.EVENT_BUS.post(new PlayerMorphEvent.Server.Post(player, cap.resolve().get(), cap.resolve().get().getCurrentMorph().orElse(null)));
            PufferfishCapabilityHandler.synchronizeWithClients(player);
            PufferfishCapabilityHandler.synchronizeWithClient(player, (ServerPlayerEntity) player);
            GuardianBeamCapabilityHandler.synchronizeWithClients(player);
            GuardianBeamCapabilityHandler.synchronizeWithClient(player, (ServerPlayerEntity) player);
        }
    }
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 17 with IMorphCapability

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

the class Events method onTargetBeingSet.

@SubscribeEvent
public static void onTargetBeingSet(LivingSetAttackTargetEvent event) {
    if (event.getEntityLiving() instanceof MobEntity && event.getTarget() instanceof PlayerEntity && event.getTarget() != event.getEntityLiving().getRevengeTarget()) {
        PlayerEntity player = (PlayerEntity) event.getTarget();
        MobEntity aggressor = (MobEntity) event.getEntityLiving();
        LazyOptional<IMorphCapability> cap = player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
        if (cap.isPresent()) {
            IMorphCapability resolved = cap.resolve().get();
            if (resolved.getCurrentMorph().isPresent()) {
                if (!resolved.shouldMobsAttack() && (ServerSetup.server.getTickCounter() - resolved.getLastAggroTimestamp()) > resolved.getLastAggroDuration())
                    aggressor.setAttackTarget(null);
                else {
                    aggro(resolved, ServerSetup.server.getGameRules().getInt(BMorphMod.MORPH_AGGRO_DURATION));
                }
            } else
                // Do this so that we can't morph to player, wait the 10 sec, and move back.
                aggro(resolved, ServerSetup.server.getGameRules().getInt(BMorphMod.MORPH_AGGRO_DURATION));
        }
    }
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) MobEntity(net.minecraft.entity.MobEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 18 with IMorphCapability

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

the class Events method onDatapackSyncing.

@SubscribeEvent
public static void onDatapackSyncing(OnDatapackSyncEvent event) {
    if (event.getPlayer() == null) {
        BMorphMod.DYNAMIC_ABILITY_REGISTRY.syncWithClients();
        ServerSetup.server.getPlayerList().getPlayers().forEach(player -> {
            IMorphCapability cap = MorphUtil.getCapOrNull(player);
            if (cap != null) {
                MorphUtil.morphToServer(cap.getCurrentMorphItem(), cap.getCurrentMorphIndex(), player);
            }
        });
    } else
        BMorphMod.DYNAMIC_ABILITY_REGISTRY.syncWithClient(event.getPlayer());
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 19 with IMorphCapability

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

the class Events method onClonePlayer.

@SubscribeEvent
public static void onClonePlayer(PlayerEvent.Clone event) {
    // I've tested it and it doesnt cause a crash. That's good.
    if (!(event.isWasDeath() && !ServerSetup.server.getGameRules().getBoolean(BMorphMod.KEEP_MORPH_INVENTORY))) {
        LazyOptional<IMorphCapability> oldCap = event.getOriginal().getCapability(MorphCapabilityAttacher.MORPH_CAP);
        LazyOptional<IMorphCapability> newCap = event.getPlayer().getCapability(MorphCapabilityAttacher.MORPH_CAP);
        if (oldCap.isPresent() && newCap.isPresent()) {
            IMorphCapability oldResolved = oldCap.resolve().get();
            IMorphCapability newResolved = newCap.resolve().get();
            newResolved.setMorphList(oldResolved.getMorphList());
            MinecraftForge.EVENT_BUS.post(new PlayerMorphEvent.Server.Pre(event.getPlayer(), newResolved, newResolved.getCurrentMorph().orElse(null)));
            oldResolved.getCurrentMorphIndex().ifPresent(morph -> newResolved.setMorph(morph));
            oldResolved.getCurrentMorphItem().ifPresent(morph -> newResolved.setMorph(morph));
            newResolved.setCurrentAbilities(oldResolved.getCurrentAbilities());
            MinecraftForge.EVENT_BUS.post(new PlayerMorphEvent.Server.Post(event.getPlayer(), newResolved, newResolved.getCurrentMorph().orElse(null)));
        }
    }
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 20 with IMorphCapability

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

the class MorphEntity method tick.

@Override
public void tick() {
    super.tick();
    if (this.ticksExisted > 20 * 300)
        this.remove();
    if (!isOnGround())
        this.setMotion(this.getMotion().x, this.getMotion().y - 0.04f, this.getMotion().z);
    if (!this.onGround || horizontalMag(this.getMotion()) > (double) 1.0E-5F || (this.ticksExisted + this.getEntityId()) % 4 == 0) {
        this.move(MoverType.SELF, this.getMotion());
    }
    // Check if the entity is being picked up and handle it
    if (!this.world.isRemote) {
        List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, getBoundingBox());
        for (Entity entity : list) {
            if (entity instanceof PlayerEntity) {
                PlayerEntity player = (PlayerEntity) entity;
                LazyOptional<IMorphCapability> lazyCaps = player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
                if (!this.world.isRemote) {
                    if (lazyCaps.isPresent()) {
                        IMorphCapability resolvedCaps = lazyCaps.resolve().get();
                        if (this.dataManager.get(MORPH_ITEM).isAllowedToPickUp(player) && !resolvedCaps.getMorphList().contains(getMorphItem())) {
                            resolvedCaps.getMorphList().addToMorphList(getMorphItem());
                            resolvedCaps.syncMorphAcquisition(player, getMorphItem());
                            this.remove();
                            this.world.playSound(null, getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.AMBIENT, 2, (this.rand.nextFloat() - 0.5f) + 1);
                        }
                    }
                }
            }
        }
    }
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) 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