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);
}
}
}
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));
}
}
}
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());
}
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)));
}
}
}
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);
}
}
}
}
}
}
}
Aggregations