Example usage for net.minecraftforge.event.entity EntityJoinWorldEvent getEntity

List of usage examples for net.minecraftforge.event.entity EntityJoinWorldEvent getEntity

Introduction

In this page you can find the example usage for net.minecraftforge.event.entity EntityJoinWorldEvent getEntity.

Prototype

public Entity getEntity() 

Source Link

Usage

From source file:buildcraft.lib.BCLibEventDist.java

License:Mozilla Public License

@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof EntityPlayerMP) {
        EntityPlayerMP playerMP = (EntityPlayerMP) entity;
        // Delay sending join messages to player as it makes it work when in single-player
        MessageUtil.doDelayed(() -> MarkerCache.onPlayerJoinWorld(playerMP));
    }//from w  w w  . ja  va2s.  c om
}

From source file:com.blogspot.jabelarminecraft.magicbeans.EventHandler.java

License:Open Source License

@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
public static void onEvent(EntityJoinWorldEvent event) {
    World world = event.getWorld();/*from   w  ww  .  jav  a 2 s.c o m*/
    if (world.isRemote) {
        return;
    }

    Entity theEntity = event.getEntity();
    if (theEntity instanceof EntityCreeper) {
        //          // DEBUG
        //          System.out.println("EntityJoinWorldEvent creeper at height = "+theEntity.posY);
        if (theEntity.posZ > MagicBeans.configMaxStalkHeight) {
            // assumes that must be in castle at this height
            event.setCanceled(true); // creepers would wreck castle
            return;
        }
    }
}

From source file:com.fatality.skillcraft.common.events.EventPlayer.java

License:Open Source License

@SubscribeEvent
public void firstJoin(EntityJoinWorldEvent event) {
    if (event.getEntity() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getEntity();
        NBTTagCompound entityData = player.getEntityData();
        if (!entityData.getBoolean("joinedBefore")) {
            entityData.setBoolean("joinedBefore", true);
            player.inventory.addItemStackToInventory(new ItemStack(Items.ITEM_SKILL_BOOK.getItem()));
        }//w  w  w.  j a va2s.co  m

        if (event.getEntity() instanceof EntityPlayer && !player.worldObj.isRemote) {
            for (SkillBase skills : SkillRegistry.instance().getRegisteredSkills()) {
                SkillProvider.get((EntityPlayer) event.getEntity())
                        .addSkill(new PlayerSkill(skills.getSkillName(), skills.defaultLevel(), 0));
            }
        }
    }
}

From source file:com.gmail.socraticphoenix.forge.randore.module.equip.RandoresMobEquip.java

License:Open Source License

@SubscribeEvent
public void onMobSpawn(EntityJoinWorldEvent ev) {
    Entity entity1 = ev.getEntity();
    if (entity1 instanceof EntityLiving) {
        EntityLiving entity = (EntityLiving) entity1;
        if (!entity.world.isRemote && !entity.getEntityData().getBoolean("randores_applied_equip")) {
            ConfigCategory config = Randores.getInstance().getConfiguration().getCategory("modules");
            entity.getEntityData().setBoolean("randores_applied_equip", true);
            if (config.get("mobequip").getBoolean()) {
                World world = entity1.world;
                if (RandoresProbability.percentChance(20, random)) {
                    List<MaterialDefinition> materials = MaterialDefinitionRegistry
                            .get(Randores.getRandoresSeed(entity.world));
                    MaterialDefinition material = materials.get(random.nextInt(materials.size()));
                    if (entity instanceof AbstractSkeleton) {
                        List<Component> applicable = new ArrayList<Component>();
                        applicable.add(material.getComponent(Components.SWORD));
                        applicable.add(material.getComponent(Components.BATTLEAXE));
                        applicable.add(material.getComponent(Components.SLEDGEHAMMER));
                        applicable.add(material.getComponent(Components.AXE));

                        while (applicable.contains(null)) {
                            applicable.remove(null);
                        }//  ww w. j  ava  2 s. co m

                        if (!applicable.isEmpty()) {
                            entity.setDropChance(EntityEquipmentSlot.MAINHAND, 0.25f);
                            entity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND,
                                    applyEnchant(
                                            Randores.applyData(
                                                    new ItemStack(applicable
                                                            .get(random.nextInt(applicable.size())).makeItem()),
                                                    world),
                                            entity.getRNG()));
                        }

                        if (material.hasComponent(Components.HELMET)) {
                            for (Components component : armor) {
                                entity.setItemStackToSlot(component.getSlot(),
                                        applyEnchant(Randores.applyData(
                                                new ItemStack(material.getComponent(component).makeItem()),
                                                world), entity.getRNG()));
                                entity.setDropChance(component.getSlot(), 0.25f);
                            }
                        }
                    } else if (entity instanceof EntityZombie) {
                        List<Component> applicable = new ArrayList<Component>();
                        applicable.add(material.getComponent(Components.SWORD));
                        applicable.add(material.getComponent(Components.BATTLEAXE));
                        applicable.add(material.getComponent(Components.SLEDGEHAMMER));
                        applicable.add(material.getComponent(Components.AXE));

                        while (applicable.contains(null)) {
                            applicable.remove(null);
                        }

                        if (!applicable.isEmpty()) {
                            entity.setDropChance(EntityEquipmentSlot.MAINHAND, 0.25f);
                            entity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND,
                                    applyEnchant(
                                            Randores.applyData(
                                                    new ItemStack(applicable
                                                            .get(random.nextInt(applicable.size())).makeItem()),
                                                    world),
                                            entity.getRNG()));
                        }

                        if (material.hasComponent(Components.HELMET)) {
                            for (Components component : armor) {
                                entity.setDropChance(component.getSlot(), 0.25f);
                                entity.setItemStackToSlot(component.getSlot(),
                                        applyEnchant(Randores.applyData(
                                                new ItemStack(material.getComponent(component).makeItem()),
                                                world), entity.getRNG()));
                            }
                        }
                    } else if (entity instanceof EntityVindicator) {
                        List<Component> applicable = new ArrayList<Component>();
                        applicable.add(material.getComponent(Components.BATTLEAXE));
                        applicable.add(material.getComponent(Components.AXE));

                        while (applicable.contains(null)) {
                            applicable.remove(null);
                        }

                        if (!applicable.isEmpty()) {
                            entity.setDropChance(EntityEquipmentSlot.MAINHAND, 0.25f);
                            entity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND,
                                    applyEnchant(
                                            Randores.applyData(
                                                    new ItemStack(applicable
                                                            .get(random.nextInt(applicable.size())).makeItem()),
                                                    world),
                                            entity.getRNG()));
                        }
                    }
                }
            }
        }
    }
}

From source file:com.lothrazar.cyclicmagic.event.EventPlayerData.java

License:Open Source License

@SubscribeEvent
//  @SideOnly(Side.SERVER)// no dont do this. breaks hearts in SSP
public void onJoinWorld(EntityJoinWorldEvent event) {
    if (event.getEntity() instanceof EntityPlayerMP && event.getEntity() != null
            && event.getEntity().isDead == false) {
        EntityPlayerMP p = (EntityPlayerMP) event.getEntity();
        if (p != null) {
            CapabilityRegistry.syncServerDataToClient(p);
            setDefaultHealth(p);//from  ww w . j  a va  2  s . c o m
        }
    }
}

From source file:com.techshroom.ludicroushooks.LudicrousHooks.java

License:MIT License

@SubscribeEvent
public void onPlayerEntitySpawn(EntityJoinWorldEvent event) {
    if (!(event.getEntity() instanceof EntityPlayer)) {
        return;//from  ww  w .  j  av a 2s.  com
    }
    Collection<NBTTagCompound> hooks = this.unspawnedHooks.get(event.getEntity().getUniqueID());
    hooks.forEach(h -> {
        Entity hook = EntityList.createEntityFromNBT(h, event.getWorld());
        if (!(hook instanceof EntityHook)) {
            LOGGER.warn("Unspanwed hook created an instance of " + hook.getClass().getName() + " rather than "
                    + EntityHook.class.getName());
        }
        event.getWorld().spawnEntityInWorld(hook);
    });
    hooks.clear();
}

From source file:de.canitzp.rarmor.event.CommonEvents.java

@SubscribeEvent
public void onPlayerJoin(EntityJoinWorldEvent event) {
    if (!event.getWorld().isRemote) {
        Entity entity = event.getEntity();
        if (entity instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) entity;

            for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
                ItemStack stack = player.inventory.getStackInSlot(i);
                if (!stack.isEmpty()) {
                    IRarmorData data = RarmorAPI.methodHandler.getDataForStack(player.getEntityWorld(), stack,
                            false);//  w w  w .j  a  v a  2  s . c om
                    if (data != null) {
                        data.queueUpdate(true);
                    }
                }
            }
        }
    }
}

From source file:de.sanandrew.mods.turretmod.registry.turret.GuiTcuRegistry.java

License:Creative Commons License

@SubscribeEvent
public void onEntitySpawn(EntityJoinWorldEvent event) {
    if (event.getEntity() instanceof EntityPlayerMP && !event.getWorld().isRemote) {
        PacketRegistry.sendToPlayer(new PacketSyncTcuGuis(), (EntityPlayerMP) event.getEntity());
    }/*from w  w w  .  j av  a 2 s  .  c  om*/
}

From source file:de.sanandrew.mods.turretmod.util.PlayerList.java

License:Creative Commons License

@SubscribeEvent
public void onEntitySpawn(EntityJoinWorldEvent event) {
    if (event.getEntity() instanceof EntityPlayer && !event.getWorld().isRemote) {
        this.playerMap.put(event.getEntity().getUniqueID(), event.getEntity().getName());
        this.syncList();
        this.markDirty();
    }//from  w  ww. ja v a2s  . c  o  m
}

From source file:hellfirepvp.astralsorcery.common.util.BlockDropCaptureAssist.java

License:Open Source License

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onDrop(EntityJoinWorldEvent event) {
    if (event.getEntity() instanceof EntityItem && capturing) {
        ItemStack stack = ((EntityItem) event.getEntity()).getEntityItem();
        event.setCanceled(true);//from   w  w  w.  ja v a  2s .  c om
        if (!stack.isEmpty()) {
            if (!expectCaptureStone) {
                if (stack.getItem() instanceof ItemBlock
                        && ((ItemBlock) stack.getItem()).getBlock().equals(Blocks.STONE)) {
                    event.getEntity().setDead();
                    return;
                }
            }
            capturedStacks.add(stack);
        }
        event.getEntity().setDead();
    }
}