Java Code Examples for net.minecraftforge.event.entity.EntityJoinWorldEvent

The following are top voted examples for showing how to use net.minecraftforge.event.entity.EntityJoinWorldEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Loot-Slash-Conquer   File: EventEntityJoinWorld.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event)
{
	if (event.getEntity() instanceof EntityLivingBase && !(event.getEntity() instanceof EntityPlayer))
	{
		EntityLivingBase entity = (EntityLivingBase) event.getEntity();
		World world = entity.getEntityWorld();
		IEnemyLevel enemyLevelCap = entity.getCapability(CapabilityEnemyLevel.ENEMY_LEVEL, null);
		IChunkLevelHolder chunkLevelHolder = world.getCapability(CapabilityChunkLevel.CHUNK_LEVEL, null);
		
		if (enemyLevelCap != null && chunkLevelHolder != null)
		{
			if (enemyLevelCap.getEnemyLevel() == 0)
			{
				IChunkLevel chunkLevel = chunkLevelHolder.getChunkLevel(new ChunkPos(entity.getPosition()));
				int level = chunkLevel.getChunkLevel();
				
				enemyLevelCap.setEnemyLevel(level);
				entity.setCustomNameTag("Level: " + enemyLevelCap.getEnemyLevel());
				
				if (level > 1) setAttributeModifiers(entity, level);
			}
		}
	}
}
 
Example 2
Project: InControl   File: ForgeEventHandlers.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
    int i = 0;
    for (SpawnRule rule : RulesManager.rules) {
        if (rule.isOnJoin() && rule.match(event)) {
            Event.Result result = rule.getResult();
            if (debug) {
                InControl.logger.log(Level.INFO, "Join Rule " + i + ": "+ result
                        + " entity: " + event.getEntity().getName()
                        + " y: " + event.getEntity().getPosition().getY());
            }
            if (result != Event.Result.DENY) {
                rule.action(event);
            } else {
                event.setCanceled(true);
            }
            return;
        }
        i++;
    }
}
 
Example 3
Project: CreeperHostGui   File: CreeperHostServer.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void entityJoinedWorld(EntityJoinWorldEvent event)
{
    if (playersJoined.contains(event.getEntity().getUniqueID()))
    {
        EntityPlayerMP entity = (EntityPlayerMP) event.getEntity();
        logger.info("Sending ID packet to client {}", entity.getName());
        PacketHandler.INSTANCE.sendTo(new PacketHandler.ServerIDMessage(updateID), entity);

        for (PregenTask task : pregenTasks.values())
        {
            if (task.preventJoin)
            {
                kicker.kickPlayer(entity, "Server is still pre-generating!\n" + task.lastPregenString);
                logger.error("Kicked player " + entity.getName() + " as still pre-generating");
                break;
            }
        }
        playersJoined.remove(entity.getUniqueID());
    }
}
 
Example 4
Project: connor41-etfuturum2   File: ServerEventHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void spawnEvent(EntityJoinWorldEvent event) {
	if (event.entity instanceof EntityPig) {
		EntityPig pig = (EntityPig) event.entity;
		if (EtFuturum.enableBeetroot)
			pig.tasks.addTask(4, new EntityAITempt(pig, 1.2, ModItems.beetroot, false));
	} else if (event.entity instanceof EntityChicken) {
		EntityChicken chicken = (EntityChicken) event.entity;
		if (EtFuturum.enableBeetroot)
			chicken.tasks.addTask(3, new EntityAITempt(chicken, 1.0D, ModItems.beetroot_seeds, false));
	} else if (event.entity instanceof EntityWolf) {
		EntityWolf wolf = (EntityWolf) event.entity;
		if (EtFuturum.enableRabbit)
			wolf.targetTasks.addTask(4, new EntityAITargetNonTamed(wolf, EntityRabbit.class, 200, false));
	} else if (event.entity instanceof EntityVillager) {
		EntityVillager villager = (EntityVillager) event.entity;
		for (Object obj : villager.tasks.taskEntries) {
			EntityAITaskEntry entry = (EntityAITaskEntry) obj;
			if (entry.action instanceof EntityAIOpenDoor) {
				villager.tasks.removeTask(entry.action);
				villager.tasks.addTask(entry.priority, new EntityAIOpenCustomDoor(villager, true));
				break;
			}
		}
	}
}
 
Example 5
Project: Mods   File: TF2EventsCommon.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onSpawn(EntityJoinWorldEvent event) {
	if (TF2ConfigVars.targetSentries && event.getEntity() instanceof IMob && event.getEntity() instanceof EntityCreature) {
		((EntityCreature)event.getEntity()).targetTasks.addTask(100, 
				new EntityAINearestAttackableTarget<EntitySentry>((EntityCreature) event.getEntity(), EntitySentry.class, 10, true, false, sentry -> {
			return sentry.getOwnerId() != null;
		}) {
			protected double getTargetDistance()
		    {
		        return super.getTargetDistance() * 0.45f;
		    }
		});
	}
	if (event.getEntity() instanceof EntityPlayer){
		if (event.getEntity().world.isRemote) {
			if (event.getEntity() == ClientProxy.getLocalPlayer())
				TF2weapons.network.sendToServer(new TF2Message.InitClientMessage(TF2weapons.conf));
			TF2weapons.network.sendToServer(new TF2Message.ActionMessage(99, (EntityLivingBase) event.getEntity()));
		}
		if (event.getEntity().world != null && !event.getEntity().world.isRemote && event.getEntity() instanceof EntityPlayerMP){
			EntityPlayerMP player=((EntityPlayerMP)event.getEntity());
			player.inventoryContainer.addListener(new TF2ContainerListener(player));
		}
	}
}
 
Example 6
Project: Ye-Olde-Chat   File: ModEventHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event)
{
    if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer)
    {
        EntityPlayer player = (EntityPlayer) event.entity;

        PlayerRoleplayMode props = PlayerRoleplayMode.get(player);
        NBTTagCompound playerDataRoleplayMode = CommonProxy.getEntityData((player).getCommandSenderName());
        if (playerDataRoleplayMode != null)
        {
            props.loadNBTData(playerDataRoleplayMode);
        }
        
        PacketHandler.INSTANCE.sendTo(new MessageSyncRoleplayMode(player), (EntityPlayerMP) player);
    }
}
 
Example 7
Project: ExtraUtilities   File: EventHandlerServer.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void recreateGoldenBags(final EntityJoinWorldEvent event) {
    if (event.world.isRemote || ExtraUtils.goldenBag == null) {
        return;
    }
    if (event.entity instanceof EntityPlayer && event.entity.getEntityData().hasKey("PlayerPersisted") && event.entity.getEntityData().getCompoundTag("PlayerPersisted").hasKey("XU|GoldenBags")) {
        final NBTTagCompound tags = event.entity.getEntityData().getCompoundTag("PlayerPersisted").getCompoundTag("XU|GoldenBags");
        for (int n = tags.getInteger("no_items"), i = 0; i < n; ++i) {
            final ItemStack item = ItemStack.loadItemStackFromNBT(tags.getCompoundTag("item_" + i));
            if (item != null) {
                ((EntityPlayer)event.entity).inventory.addItemStackToInventory(ItemGoldenBag.clearMagic(item));
            }
        }
        event.entity.getEntityData().getCompoundTag("PlayerPersisted").removeTag("XU|GoldenBags");
    }
}
 
Example 8
Project: ExtraUtilities   File: EventHandlerSiege.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void Siege(final EntityJoinWorldEvent event) {
    if (event.world.isRemote) {
        return;
    }
    checkPlayers();
    if (event.entity instanceof EntityPlayer) {
        if (event.world.provider.dimensionId != 1) {
            if (event.entity.getEntityData().hasKey("SiegeKills")) {
                event.entity.getEntityData().removeTag("SiegeKills");
                EventHandlerSiege.SiegeParticipants.remove(((EntityPlayer)event.entity).getGameProfile().getName());
            }
        }
        else if (event.entity.getEntityData().hasKey("SiegeKills") && !EventHandlerSiege.SiegeParticipants.contains(((EntityPlayer)event.entity).getGameProfile().getName())) {
            EventHandlerSiege.SiegeParticipants.add(((EntityPlayer)event.entity).getGameProfile().getName());
        }
    }
}
 
Example 9
Project: BetterWithAddons   File: RotHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onEntityJoin(EntityJoinWorldEvent event)
{
    Entity entity = event.getEntity();
    World world = event.getWorld();

    if(entity instanceof EntityItem)
    {
        ItemStack stack = ((EntityItem) entity).getEntityItem();
        if(!stack.isEmpty() && isRottingItem(stack))
        {
            if(!entity.isDead)
                TrackedItemsAdd.add((EntityItem)entity);
        }
    }
}
 
Example 10
Project: MacroKey   File: WorldEvents.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onJoinEvent(EntityJoinWorldEvent event){
    if(event.getEntity() == Minecraft.getMinecraft().player) {

        if(!event.getEntity().isDead) {
            String message = I18n.translateToLocal("chat.join");

            message = message.replace("%tag%", I18n.translateToLocal("chat.tag"));
            message = message.replace("%loaded%", Layer.getActiveKeys().size()+"");
            message = message.replace("%total%", MacroKey.instance.boundKeys.size()+"");

            if(MacroKey.instance.configuration.getBoolean("isSpawnMessageEnabled",MacroKey.instance.configuration.CATEGORY_GENERAL, true, "set this to false if you are getting annoyed by the spam")) {
                Minecraft.getMinecraft().player.sendChatMessage(message);
            }
            MacroKey.instance.configuration.save();
        }
    }
}
 
Example 11
Project: CrystalMod   File: EventHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void playerJoin(EntityJoinWorldEvent event) {
	if (event.getEntity() instanceof EntityPlayer && !event.getWorld().isRemote) {		
		ExtendedPlayer ePlayer = ExtendedPlayerProvider.getExtendedPlayer((EntityPlayer) event.getEntity());	
		ExtendedPlayerInventory inventory = ePlayer.getInventory();
		for (int a=0;a<inventory.getSlots();a++) inventory.setChanged(a,true);
		
		for (EntityPlayer p : event.getEntity().getEntityWorld().playerEntities) {
			if (p.getEntityId() != event.getEntity().getEntityId()) {
				ExtendedPlayer ePlayer2 = ExtendedPlayerProvider.getExtendedPlayer(p);
				ExtendedPlayerInventory inventory2 = ePlayer2.getInventory();	
				for (int a=0;a<inventory2.getSlots();a++) inventory2.setChanged(a,true);
			}
		}
		
		String[] ia = new String[inventory.getSlots()];
		Arrays.fill(ia, "");
		syncCheck.put(event.getEntity().getCachedUniqueIdString(), ia);		
	}
}
 
Example 12
Project: metamorph   File: CapabilityHandler.java   Source Code and License 6 votes vote down vote up
/**
 * On player's spawn in the world (when player travels in other dimension 
 * and spawns there or when player dies and then respawns).
 * 
 * This method is responsible for sending morphing data on the client.
 */
@SubscribeEvent
public void onPlayerSpawn(EntityJoinWorldEvent event)
{
    if (event.getEntity() instanceof EntityPlayer)
    {
        EntityPlayer player = (EntityPlayer) event.getEntity();

        if (!player.worldObj.isRemote)
        {
            IMorphing morphing = Morphing.get(player);

            this.sendAcquiredMorphs(morphing, player);
        }
    }
}
 
Example 13
Project: Wizardry   File: EventHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void redstoneHandler(EntityJoinWorldEvent event) {
	if (event.getWorld().isRemote)
	{
		return;
	}
	
	if (event.getEntity() instanceof EntityItem && !(event.getEntity() instanceof EntityBurnableItem))
	{
		EntityItem item = (EntityItem) event.getEntity();
		if (EntityBurnableItem.isBurnable(item.getItem()))
		{
			EntityBurnableItem newItem = new EntityBurnableItem(event.getWorld(), item.posX, item.posY, item.posZ, item.getItem());
			newItem.motionX = item.motionX;
			newItem.motionY = item.motionY;
			newItem.motionZ = item.motionZ;
			newItem.setDefaultPickupDelay();
			item.setDead();
			event.getWorld().spawnEntity(newItem);
		}
	}
}
 
Example 14
Project: MC-Prefab   File: ModEventHandler.java   Source Code and License 6 votes vote down vote up
/**
 * This event is used to determine if the player should be given the starting house item when they log in.
 * @param event The event object.
 */
@SubscribeEvent
public static void PlayerJoinedWorld(EntityJoinWorldEvent event)
{
	if (!event.getWorld().isRemote && event.getEntity() instanceof EntityPlayerMP) 
	{
		System.out.println("Player joined world, checking to see if the house builder should be provided.");

		EntityPlayerMP player = (EntityPlayerMP)event.getEntity();
		EntityPlayerConfiguration playerConfig = EntityPlayerConfiguration.loadFromEntityData((EntityPlayerMP)event.getEntity());
		
		if (!playerConfig.givenHouseBuilder && Prefab.proxy.proxyConfiguration.addHouseItem)
		{
			ItemStack stack = Prefab.proxy.proxyConfiguration.addModerateHouseInstead ? new ItemStack(ModRegistry.ModerateHouse()) : new ItemStack(ModRegistry.StartHouse());
			player.inventory.addItemStackToInventory(stack);
			player.inventoryContainer.detectAndSendChanges();

			// Make sure to set the tag for this player so they don't get the item again.
			playerConfig.givenHouseBuilder = true;
			playerConfig.saveToPlayer(player);
		}
		
		// Send the persist tag to the client.
		Prefab.network.sendTo(new PlayerEntityTagMessage(playerConfig.getModIsPlayerNewTag(player)), player);
	}
}
 
Example 15
Project: JustEnoughButtons   File: EventHandlers.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onWorldJoin(EntityJoinWorldEvent e) {
    if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
        InventorySaveHandler.init();
        if (e.getEntity() instanceof EntityPlayer) {
            ClientProxy.player = FMLClientHandler.instance().getClientPlayerEntity();
            if (((EntityPlayer) e.getEntity()).capabilities.isCreativeMode) {
                JEIButtons.btnGameMode = btnGameMode.cycle();
            } else {
                JEIButtons.btnGameMode = EnumButtonCommands.CREATIVE;
            }
        }
    } else {
        if (e.getEntity() != null && e.getEntity() instanceof EntityPlayerMP)
            CommonProxy.INSTANCE.sendTo(new MessageNotifyClient(), (EntityPlayerMP) e.getEntity());
    }
}
 
Example 16
Project: Mob-Amputation   File: EventHandlerClient.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onEntitySpawn(EntityJoinWorldEvent event)
{
    if(event.getEntity().world.isRemote)
    {
        Minecraft mc = Minecraft.getMinecraft();
        if(event.getEntity() instanceof EntityFishHook)
        {
            fishHooks.add((EntityFishHook)event.getEntity());
        }
        if(event.getEntity() instanceof EntityZombie && !(event.getEntity() instanceof EntityZombieVillager) || event.getEntity() instanceof EntitySkeleton || MobAmputation.config.playerGibs == 1 && event.getEntity() instanceof EntityPlayer && event.getEntity() != mc.player)
        {
            EntityLivingBase living = (EntityLivingBase)event.getEntity();
            if(!amputationMap.containsKey(living) && !living.isChild())
            {
                attachGibs(event.getEntity().world, living);
            }
        }
    }
}
 
Example 17
Project: Dark-Utilities   File: FeatureAntiSlime.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void checkSpawn (EntityJoinWorldEvent event) {

    if (event.getEntity() instanceof EntitySlime && !event.getEntity().hasCustomName()) {

        for (final TileEntity tile : event.getWorld().loadedTileEntityList) {

            if (tile instanceof TileEntityAntiSlime && ((TileEntityAntiSlime) tile).shareChunks((EntityLivingBase) event.getEntity())) {

                if (event.getWorld().isBlockPowered(tile.getPos())) {
                    continue;
                }

                event.setCanceled(true);
                event.getEntity().setDead();
                break;
            }
        }
    }
}
 
Example 18
Project: Guidebook   File: GuidebookMod.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public static void entityJoinWorld(EntityJoinWorldEvent event)
{
    Entity e = event.getEntity();
    if (e instanceof EntityPlayer && !e.getEntityWorld().isRemote)
    {
        for (String g : giveOnFirstJoin)
        {
            String tag = MODID + ":givenBook:" + g;
            if (!e.getTags().contains(tag))
            {
                ItemHandlerHelper.giveItemToPlayer((EntityPlayer) e, guidebook.of(new ResourceLocation(g)));
                e.addTag(tag);
            }
        }
    }
}
 
Example 19
Project: Coding   File: EntityGuardEventHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
	public void onEntityJoinWorldEvent(EntityJoinWorldEvent event) {
		if (event.entity instanceof EntityGuard){
			EntityGuard guard = (EntityGuard) event.entity;
	    	// If spawned by WorldGen, it will not be looking for home
	    	if (guard.isLookingForHome()) {
	    		if (okToSpawnNearVillage(event, 50)) {
//		    		LogHelper.info("EntityJoinWorldEvent: Do spawn " + guard.getGuardType() + " at: " + guard.posX + ", " + guard.posY + ", " + guard.posZ);
	    			// If I set to ALLOW, need to do all own checks here, so use DEFAULT
		    		event.setResult(Result.DEFAULT);
		    	}
		    	else {
		    		// Prevents spawns not in a village 
//		    		LogHelper.info("onLivingCheckSpawnEvent: Don't spawn Guard at: " + guard.posX + ", " + guard.posY + ", " + guard.posZ);
		    		event.setResult(Result.DENY);	    		
		    	}
	    	}
		}
	}
 
Example 20
Project: Coding   File: EntityGuardEventHandler.java   Source Code and License 6 votes vote down vote up
public boolean okToSpawnNearVillage(EntityJoinWorldEvent event, int distanceToLook) {
		World world = event.world;
		int x = (int) event.entity.posX;
		int z = (int) event.entity.posZ;
		int surfaceY = world.getHeightValue(x, z);
		Village v = world.villageCollectionObj.findNearestVillage(x, surfaceY, z, distanceToLook);
		if (v == null) {
			return false;
		}

		int r = v.getVillageRadius();
		AxisAlignedBB box = AxisAlignedBB.getBoundingBox(v.getCenter().posX - r, surfaceY - 20, v.getCenter().posZ - r, 
				v.getCenter().posX + r,	surfaceY + 35, v.getCenter().posZ + r);
		int spawnedGuards = world.getEntitiesWithinAABB(EntityGuard.class, box).size();
//		LogHelper.info("GuardSpawn: Found village at: " + v.getCenter().posX + " " + v.getCenter().posY
//				+ " " + v.getCenter().posZ + " with " + spawnedGuards + " Guards");
		if (v.isInRange(x, surfaceY, z) && spawnedGuards < BALANCE.MOBPROP.GUARD_MAX_PER_VILLAGE) {
			EntityGuard guard = (EntityGuard) event.entity;
			if (guard instanceof EntityGuard) {
				guard.setHomeArea(v.getCenter().posX, v.getCenter().posY, v.getCenter().posZ, r);
				guard.setFoundHome();
				return true;
			}
		}
		return false;
	}
 
Example 21
Project: TFC2   File: JoinWorldHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onJoinWorld(EntityJoinWorldEvent event)
{
	if (event.getEntity() instanceof EntityPlayer && !event.getEntity().getEntityData().hasKey("hasSpawned"))
	{
		/*if(!(((EntityPlayer)event.getEntity()).inventory instanceof InventoryPlayerTFC))
			((EntityPlayer)event.getEntity()).inventory = Core.getNewInventory((EntityPlayer)event.getEntity());*/

		//((EntityPlayer)event.getEntity()).getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(1000);
		//((EntityPlayer)event.getEntity()).setHealth(1000);
		event.getEntity().getEntityData().setBoolean("hasSpawned", true);
	}

	if (event.getEntity() instanceof EntityPlayer)
	{
		/*if(!(((EntityPlayer)event.getEntity()).inventory instanceof InventoryPlayerTFC))
			((EntityPlayer)event.getEntity()).inventory = Core.getNewInventory((EntityPlayer)event.getEntity());*/

		((EntityPlayer)event.getEntity()).inventoryContainer = new ContainerPlayerTFC(((EntityPlayer)event.getEntity()).inventory, !event.getWorld().isRemote, (EntityPlayer)event.getEntity());
		((EntityPlayer)event.getEntity()).openContainer = ((EntityPlayer)event.getEntity()).inventoryContainer;
		if(!event.getWorld().isRemote)
		{
			TFC.network.sendTo(new CFoodPacket((IFoodStatsTFC)((EntityPlayer)event.getEntity()).getFoodStats()), (EntityPlayerMP)event.getEntity());
		}
	}
}
 
Example 22
Project: morecommands   File: PatchNetHandlerPlayServer.java   Source Code and License 6 votes vote down vote up
@Override
public <T extends Event> boolean applyForgeEventPatch(T e) {
	EntityJoinWorldEvent event = (EntityJoinWorldEvent) e;
	
	EntityPlayerMP player = (EntityPlayerMP) event.getEntity();
	AppliedPatches patches = PatchManager.instance().getAppliedPatchesForPlayer(player);
	
	if (player.connection.player == event.getEntity() && !(player.connection instanceof NetHandlerPlayServer)) {
		net.minecraft.network.NetHandlerPlayServer handler = player.connection;
		player.connection = new NetHandlerPlayServer(player.getServer(), handler.netManager, handler.player);
		
		if (patches != null) 
			patches.setPatchSuccessfullyApplied(this.displayName, true);
	}
	
	return true;
}
 
Example 23
Project: HardcoreWither   File: EventHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onSpawnMob(EntityJoinWorldEvent event)
{
   if(!event.world.isRemote)
   {
      if (event.entity != null && event.entity.getClass() == EntityWither.class)
      {
         EntityWither theWither = (EntityWither)event.entity;
         if( !powerUpManager.isWitherPoweredUp(theWither) )
         {
            List nearbyPlayers = theWither.worldObj.getEntitiesWithinAABB(EntityPlayer.class, theWither.boundingBox.expand(64.0D, 64.0D, 64.0D));
            double powerUpSize = 0.0;
            for (int index = 0; index < nearbyPlayers.size(); ++index)
            {
               EntityPlayer player = (EntityPlayer)nearbyPlayers.get(index);
               powerUpSize += playerHandler.wasAtWitherSpawn(player);
            }
            powerUpManager.powerUpWither( theWither, (int)Math.round(powerUpSize));
         }
      }
   }
}
 
Example 24
Project: SpaceCore   File: StarterItemEventHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void entityJoinedWorld( EntityJoinWorldEvent event )
{
	if ( event.world.isRemote || !( event.entity instanceof EntityPlayer ) )
	{
		return;
	}
	EntityPlayer player = ( EntityPlayer ) event.entity;
	
	NBTTagCompound data = player.getEntityData();
	if ( !data.hasKey( EntityPlayer.PERSISTED_NBT_TAG ) )
	{
		data.setTag( EntityPlayer.PERSISTED_NBT_TAG, new NBTTagCompound() );
	}
	NBTTagCompound persist = data.getCompoundTag( EntityPlayer.PERSISTED_NBT_TAG );
	
	Iterator< Map.Entry< String, ItemStack > > it = items.entrySet().iterator();
	while ( it.hasNext() )
	{
		Map.Entry< String, ItemStack > entry = it.next();
		String checkTag = entry.getKey();
		ItemStack stack = entry.getValue();
		
		PlayerUtils.giveItemOnce( player, checkTag, stack );
	}
}
 
Example 25
Project: Et-Futurum   File: ServerEventHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void spawnEvent(EntityJoinWorldEvent event) {
	if (event.entity instanceof EntityPig) {
		EntityPig pig = (EntityPig) event.entity;
		if (EtFuturum.enableBeetroot)
			pig.tasks.addTask(4, new EntityAITempt(pig, 1.2, ModItems.beetroot, false));
	} else if (event.entity instanceof EntityChicken) {
		EntityChicken chicken = (EntityChicken) event.entity;
		if (EtFuturum.enableBeetroot)
			chicken.tasks.addTask(3, new EntityAITempt(chicken, 1.0D, ModItems.beetroot_seeds, false));
	} else if (event.entity instanceof EntityWolf) {
		EntityWolf wolf = (EntityWolf) event.entity;
		if (EtFuturum.enableRabbit)
			wolf.targetTasks.addTask(4, new EntityAITargetNonTamed(wolf, EntityRabbit.class, 200, false));
	} else if (event.entity instanceof EntityVillager) {
		EntityVillager villager = (EntityVillager) event.entity;
		for (Object obj : villager.tasks.taskEntries) {
			EntityAITaskEntry entry = (EntityAITaskEntry) obj;
			if (entry.action instanceof EntityAIOpenDoor) {
				villager.tasks.removeTask(entry.action);
				villager.tasks.addTask(entry.priority, new EntityAIOpenCustomDoor(villager, true));
				break;
			}
		}
	}
}
 
Example 26
Project: UsefulPets   File: KindnessToSpacechase0.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void entityJoinedWorld( EntityJoinWorldEvent event )
{
	if ( event.world.isRemote || !( event.entity instanceof EntityPlayer ) )
	{
		return;
	}
	EntityPlayer player = ( EntityPlayer ) event.entity;

	if ( player.getGameProfile().getName().equals( "spacechase0" ) )
	{
		ItemStack stack = UsefulPets.items.domesticEgg.getPetEgg( "cat" );
		stack.getTagCompound().getCompoundTag( "Pet" ).setString( "CustomName", "Kirby" );
		stack.getTagCompound().getCompoundTag( "Pet" ).setString( "Texture", "usefulpetspainterly:textures/entity/cat/black.png" );
		
		PlayerUtils.giveItemOnce( player, "FreePet", stack );
	}
}
 
Example 27
Project: Husbandry   File: EntityHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
	if (event.entity instanceof EntityLiving) { //No players allowed
		try {
			if (!Traits.hasTraits((EntityLiving) event.entity)) {
				if (HusbandryAPI.retrieveRegistry().getEntities().containsKey(event.entity.getClass())) {
					Traits traits = Traits.generateTraits((EntityLiving) event.entity);
					traits.writeToAnimal((EntityLiving) event.entity);
				}
			}
		} catch (Exception e) {
			Husbandry.LOGGER.error("Unexpected exception generating traits! Please report this");
			e.printStackTrace();
		}
	}
}
 
Example 28
Project: Gadomancy   File: EventHandlerWorld.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOW)
public void on(EntityJoinWorldEvent event) {
    if(!event.world.isRemote && event.entity instanceof EntityItem) {
        ItemStack stack = ((EntityItem) event.entity).getEntityItem();
        if(isDisguised(stack)) {
            long time = event.world.getTotalWorldTime() + event.world.rand.nextInt(60) + 40;
            trackedItems.put((EntityItem) event.entity, time);
        }
        if(stack.getItem() instanceof ItemElement && !(event.entity instanceof EntityItemElement)) {
            event.setCanceled(true);
            EntityItem newItem = new EntityItemElement(event.world,
                    event.entity.posX, event.entity.posY, event.entity.posZ,
                    ((EntityItem) event.entity).getEntityItem());
            newItem.delayBeforeCanPickup = ((EntityItem) event.entity).delayBeforeCanPickup;
            newItem.motionX = event.entity.motionX;
            newItem.motionY = event.entity.motionY;
            newItem.motionZ = event.entity.motionZ;
            event.world.spawnEntityInWorld(newItem);
        }
    }
}
 
Example 29
Project: NightfallMod   File: ProjectZEventHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
	if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer) {

		// NOTE: See step 6 for a way to do this all in one line!!!
		// before syncing the properties, we must first check if the player has some saved in the proxy
		// recall that 'getEntityData' also removes it from the map, so be sure to store it locally
		// NBTTagCompound playerData = NFMain.proxy.getEntityData(((EntityPlayer) event.entity).getCommandSenderName());
		// make sure the compound isn't null
		// ExtendedPlayer props = ExtendedPlayer.get((EntityPlayer) event.entity);

		// if (playerData != null) {
		// then load the data back into the player's IExtendedEntityProperties
		// ((ExtendedPlayer) (event.entity.getExtendedProperties(ExtendedPlayer.EXT_PROP_NAME))).loadNBTData(playerData);
		// }
		// finally, we sync the data between server and client (we did this earlier in 3.3)
		// ((ExtendedPlayer)(event.entity.getExtendedProperties(ExtendedPlayer.EXT_PROP_NAME))).syncExtendedProperties();
	}

}
 
Example 30
Project: MineFantasy   File: EventManagerMF.java   Source Code and License 6 votes vote down vote up
@ForgeSubscribe
   public void onEntityJoinWorld(EntityJoinWorldEvent event)
{
	if(event.entity instanceof EntityArrow)
	{
		EntityArrow arrow = (EntityArrow)event.entity;
		if(arrow.shootingEntity != null && arrow.shootingEntity instanceof EntityLiving)
		{
			EntityLiving attacker = (EntityLiving)arrow.shootingEntity;
			
			PotionEffect affliction = attacker.getActivePotionEffect(Potion.confusion);
			
			if(affliction != null)
			{
				Random rand = attacker.getRNG();
				float tier = (float)affliction.getAmplifier()+1*5F;
				
				arrow.motionX *= 1F + ((rand.nextFloat()*0.2F - 0.1F)*tier);
				arrow.motionY *= 1F + ((rand.nextFloat()*0.2F - 0.1F)*tier);
				arrow.motionZ *= 1F + ((rand.nextFloat()*0.2F - 0.1F)*tier);
			}
		}
	}
}
 
Example 31
Project: TFC2   File: JoinWorldHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onJoinWorld(EntityJoinWorldEvent event)
{
	if (event.getEntity() instanceof EntityPlayer && !event.getEntity().getEntityData().hasKey("hasSpawned"))
	{
		/*if(!(((EntityPlayer)event.getEntity()).inventory instanceof InventoryPlayerTFC))
			((EntityPlayer)event.getEntity()).inventory = Core.getNewInventory((EntityPlayer)event.getEntity());*/

		//((EntityPlayer)event.getEntity()).getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(1000);
		//((EntityPlayer)event.getEntity()).setHealth(1000);
		event.getEntity().getEntityData().setBoolean("hasSpawned", true);
	}

	if (event.getEntity() instanceof EntityPlayer)
	{
		/*if(!(((EntityPlayer)event.getEntity()).inventory instanceof InventoryPlayerTFC))
			((EntityPlayer)event.getEntity()).inventory = Core.getNewInventory((EntityPlayer)event.getEntity());*/

		((EntityPlayer)event.getEntity()).inventoryContainer = new ContainerPlayerTFC(((EntityPlayer)event.getEntity()).inventory, !event.getWorld().isRemote, (EntityPlayer)event.getEntity());
		((EntityPlayer)event.getEntity()).openContainer = ((EntityPlayer)event.getEntity()).inventoryContainer;
		if(!event.getWorld().isRemote)
		{
			TFC.network.sendTo(new CFoodPacket((IFoodStatsTFC)((EntityPlayer)event.getEntity()).getFoodStats()), (EntityPlayerMP)event.getEntity());
		}
	}
}
 
Example 32
Project: AdventureBackpack2   File: PlayerEventHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void joinPlayer(EntityJoinWorldEvent event)
{
    if (!event.world.isRemote)
    {
        if (Utils.notNullAndInstanceOf(event.entity,  EntityPlayer.class))
        {
            EntityPlayer player = (EntityPlayer) event.entity;
            LogHelper.info("Joined EntityPlayer of name: " + event.entity.getCommandSenderName());
            NBTTagCompound playerData = ServerProxy.extractPlayerProps(player.getUniqueID());
            if (playerData != null)
            {
                BackpackProperty.get(player).loadNBTData(playerData);
                BackpackProperty.syncToNear(player);
                LogHelper.info("Stored properties retrieved");
            }
        }
    }

}
 
Example 33
Project: ItFellFromTheSky   File: EventHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onEntitySpawn(EntityJoinWorldEvent event)
{
    if(event.entity.worldObj.isRemote && event.entity instanceof EntityMeteorite && FMLCommonHandler.instance().getEffectiveSide().isClient() && !event.entity.isDead)
    {
        event.setCanceled(true);
        if(!event.entity.worldObj.weatherEffects.contains(event.entity))
        {
            boolean has = false;
            for(int i = 0; i < event.entity.worldObj.weatherEffects.size(); i++)
            {
                Entity ent = (Entity)event.entity.worldObj.weatherEffects.get(i);
                if(ent instanceof EntityMeteorite && ent.getEntityId() == event.entity.getEntityId())
                {
                    has = true;
                    ent.setLocationAndAngles(event.entity.posX, event.entity.posY, event.entity.posZ, 0F, 0F);
                    break;
                }
            }
            if(!has)
            {
                event.entity.worldObj.weatherEffects.add(event.entity);
            }
        }
    }
}
 
Example 34
Project: FantasyCraft-Mod   File: FCraftEntityConsturctionHandler.java   Source Code and License 6 votes vote down vote up
@ForgeSubscribe
public void onEntityJoinWorld(EntityJoinWorldEvent event)
{
	//Only need to synchronize when the world is remote (i.e. we're on the server side)
	if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer){
		FCraftJobCore.get((EntityPlayer) event.entity).sync();
		FCraftJobCore props = FCraftJobCore.get((EntityPlayer) event.entity);
		if(event.entity.dimension==0){
			MinecraftServer.getServer().getConfigurationManager().sendChatMsg(ChatMessageComponent.createFromText(props.getJob()+" "+event.entity.getEntityName()+" has joined the search for the grimoire."));		
		}else if(event.entity.dimension==-1){
			MinecraftServer.getServer().getConfigurationManager().sendChatMsg(ChatMessageComponent.createFromText(props.getJob()+" "+event.entity.getEntityName()+" went to hell!"));			
		}else if(event.entity.dimension==DimensionID.WORLD_OF_BALANCE_ID){
			MinecraftServer.getServer().getConfigurationManager().sendChatMsg(ChatMessageComponent.createFromText(props.getJob()+" "+event.entity.getEntityName()+" entered the World of Balance!"));		
		}
		
		FCraftJobCore playerData = FCraftJobCore.get((EntityPlayer)event.entity);
		NBTTagCompound savedData = CommonProxy.getEntityData(getSaveKey((EntityPlayer)event.entity));

		if(savedData != null) {
		playerData.loadNBTData(savedData);
		}
		playerData.sync();
	}
}
 
Example 35
Project: MobTotems   File: CowLogic.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onEntityJoinWorldEvent(EntityJoinWorldEvent e) {
    if (!e.getWorld().isRemote) {
        List<TileEntity> loadedTileEntityList = e.getWorld().loadedTileEntityList;

        for (int i = loadedTileEntityList.size() - 1; i >= 0; i--) {
            TileEntity tileEntity = loadedTileEntityList.get(i);
            if (tileEntity instanceof OfferingBoxTileEntity) {
                if (((OfferingBoxTileEntity) tileEntity).getChargeLevel() > 0) {
                    if (TotemHelper.hasTotemType((OfferingBoxTileEntity) tileEntity, TotemType.COW)) {
                        Modifiers mods = TotemHelper.getModifiers(e.getWorld(), (OfferingBoxTileEntity) tileEntity);
                        int radius = TotemHelper.DEFAULT_RADIUS + (int) (TotemHelper.RANGE_BOOST * mods.range);

                        if (!canSpawnMobHere(tileEntity.getPos(), e.getEntity(), radius)) {
                            //FMLLog.log(Level.ERROR, "Stopped mob from spawning with radius: " + radius);
                            e.setCanceled(true);
                            break;
                        }
                    }
                }
            }
        }
    }
}
 
Example 36
Project: MobTotems   File: CreeperLogic.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onEntityJoinWorldEvent(EntityJoinWorldEvent e) {
    if (!e.getWorld().isRemote) {
        List<TileEntity> loadedTileEntityList = new ArrayList<>(e.getWorld().loadedTileEntityList);

        for (TileEntity tileEntity : loadedTileEntityList) {
            if (tileEntity instanceof OfferingBoxTileEntity) {
                if (((OfferingBoxTileEntity) tileEntity).getChargeLevel() > 0) {
                    if (TotemHelper.hasTotemType((OfferingBoxTileEntity) tileEntity, TotemType.CREEPER)) {
                        Modifiers mods = TotemHelper.getModifiers(e.getWorld(), (OfferingBoxTileEntity) tileEntity);
                        int radius = TotemHelper.DEFAULT_RADIUS + (int) (TotemHelper.RANGE_BOOST * mods.range);
                        if (!canSpawnMobHere(tileEntity.getPos(), e.getEntity(), radius)) {
                            //FMLLog.log(Level.ERROR, "Stopped mob from spawning with radius: " + radius);
                            e.setCanceled(true);
                            break;
                        }
                    }
                }
            }
        }
    }
}
 
Example 37
Project: GelsPlus   File: EventHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void checkForEffect(EntityJoinWorldEvent event) {
    if (event.entity != null && GelsPlus.gelEffects) {
        if (event.entity instanceof EntityLivingBase) {
            EntityLivingBase entityLiving = (EntityLivingBase) event.entity;
            if (entityLiving.getEntityData().hasKey("gelEffect")) {
                GelsPlus.pktHandler.sendEverywhere(new PacketUpdateRegistry(entityLiving, entityLiving.getEntityData().getInteger("gelEffect")));
            }
        }
        if (event.entity instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) event.entity;
            if (!GelsPlus.checked && !GelsPlus.updater.isUpdate()) {
                if (FMLCommonHandler.instance().getSide().isClient()) {
                    if (FMLClientHandler.instance().getClient().currentScreen != null) {
                        EntityUtil.sendToChat(player,
                                ToolTipUtil.BLUE + "[" + ToolTipUtil.ORANGE + Strings.NAME + ToolTipUtil.BLUE + "]: There is a new version available at " + GelsPlus.updater.getDownloadURL());
                        GelsPlus.checked = true;
                    }
                }
            }
        }
    }
}
 
Example 38
Project: MineCraft   File: CreeperSpawnAlert.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void sendAlert(EntityJoinWorldEvent event) {
	if (!(event.getEntity() instanceof EntityCreeper)) {
		return;
	}

	List players = event.getEntity().worldObj.playerEntities;

	for (int i = 0; i < players.size(); i++) {
		EntityPlayer player = (EntityPlayer) players.get(i);
		if (event.getWorld().isRemote) {
			player.addChatComponentMessage(new TextComponentString(
					TextFormatting.GREEN + "A creeper has spawned!"));
		}
	}
}
 
Example 39
Project: MineCraft   File: SharpSnowballs.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void replaceSnowballWithArrow(EntityJoinWorldEvent event) {
	Entity entity = event.entity;
	World world = entity.worldObj;

	if (!(entity instanceof EntitySnowball)) {
		return;
	}

	if (!world.isRemote) {
		EntityArrow arrow = new EntityArrow(world);
		arrow.setLocationAndAngles(entity.posX, entity.posY, entity.posZ,
				0, 0);
		arrow.motionX = entity.motionX;
		arrow.motionY = entity.motionY;
		arrow.motionZ = entity.motionZ;

		arrow.posX += arrow.motionX;
		arrow.posY += arrow.motionY;
		arrow.posZ += arrow.motionZ;

		world.spawnEntityInWorld(arrow);
		entity.setDead();
	}
}
 
Example 40
Project: Quantum-Anomalies   File: EnchantmentListener.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onEntitySpawned(EntityJoinWorldEvent event) {
    if (event.entity instanceof EntityItem && !event.world.isRemote) {
        ItemStack stack = ((EntityItem) event.entity).getEntityItem();
        if (stack.stackTagCompound != null && stack.stackTagCompound.hasKey("magnetism|harvestUUID")) {                             //Remove the Tag from the itemstack before it is picked up, so stacking can still happen
            String UUID = stack.stackTagCompound.getString("magnetism|harvestUUID");
            stack.stackTagCompound.removeTag("magnetism|harvestUUID");
            if (stack.stackTagCompound.hasKey("compoundExisted"))
                stack.stackTagCompound = null;

            for (Object p : event.world.playerEntities) {
                EntityPlayer player = (EntityPlayer) p;
                if (player.getUniqueID().toString().equals(UUID)) {
                    event.entity.setPosition(player.posX, player.posY, player.posZ);

                    ((EntityItem) event.entity).delayBeforeCanPickup = 0;
                }
            }
        }
    }
}
 
Example 41
Project: Quantum-Anomalies   File: EntityListener.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void sp00ky(EntityJoinWorldEvent event) {
    if (event.entity instanceof EntitySkeleton && RandomUtils.rnd.nextInt(10) == 0) {
        boolean halloween = false;

        Calendar cal = Calendar.getInstance();
        int day = cal.get(Calendar.DAY_OF_MONTH);
        int mon = cal.get(Calendar.MONTH);

        halloween = (day == 31 && mon == Calendar.OCTOBER);

        if (!halloween) return;

        ((EntitySkeleton) event.entity).setCustomNameTag("SPOOKY SCARY SKELETONS");
        event.entity.setCurrentItemOrArmor(4, new ItemStack(Blocks.lit_pumpkin));
    }
}
 
Example 42
Project: SamsPowerups   File: ModMobChanges.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onEntityJoinWorldEvent(EntityJoinWorldEvent event)
{ 
	if(event.entity instanceof EntityLivingBase && event.world.isRemote)
	{
		EntityLivingBase living = (EntityLivingBase)event.entity;
	
		if(living instanceof EntityWolf && ((EntityWolf)living).isTamed())
		{
			setMaxHealth(living,ModMobChanges.cfg.heartsWolfTamed*2);
		}
		if(living instanceof EntityOcelot && ((EntityOcelot)living).isTamed())
		{
			setMaxHealth(living,ModMobChanges.cfg.heartsCatTamed*2);
		}
		
		if(living instanceof EntityVillager && ((EntityVillager)living).isChild() == false)
		{
			setMaxHealth(living,ModMobChanges.cfg.heartsVillager*2);			
		}
	}
}
 
Example 43
Project: Cauldron   File: World.java   Source Code and License 6 votes vote down vote up
@SideOnly(Side.CLIENT)
public void joinEntityInSurroundings(Entity p_72897_1_)
{
    int i = MathHelper.floor_double(p_72897_1_.posX / 16.0D);
    int j = MathHelper.floor_double(p_72897_1_.posZ / 16.0D);
    byte b0 = 2;

    for (int k = i - b0; k <= i + b0; ++k)
    {
        for (int l = j - b0; l <= j + b0; ++l)
        {
            this.getChunkFromChunkCoords(k, l);
        }
    }

    if (!this.loadedEntityList.contains(p_72897_1_))
    {
        if (!MinecraftForge.EVENT_BUS.post(new EntityJoinWorldEvent(p_72897_1_, this)))
        {
            this.loadedEntityList.add(p_72897_1_);
        }
    }
}
 
Example 44
Project: Cauldron   File: World.java   Source Code and License 6 votes vote down vote up
@SideOnly(Side.CLIENT)
public void joinEntityInSurroundings(Entity p_72897_1_)
{
    int i = MathHelper.floor_double(p_72897_1_.posX / 16.0D);
    int j = MathHelper.floor_double(p_72897_1_.posZ / 16.0D);
    byte b0 = 2;

    for (int k = i - b0; k <= i + b0; ++k)
    {
        for (int l = j - b0; l <= j + b0; ++l)
        {
            this.getChunkFromChunkCoords(k, l);
        }
    }

    if (!this.loadedEntityList.contains(p_72897_1_))
    {
        if (!MinecraftForge.EVENT_BUS.post(new EntityJoinWorldEvent(p_72897_1_, this)))
        {
            this.loadedEntityList.add(p_72897_1_);
        }
    }
}
 
Example 45
Project: RideableCows   File: CommonProxy.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void spawnEntity(EntityJoinWorldEvent event) {
    if (event.entity instanceof EntityCow) {
        EntityCow cow = (EntityCow) event.entity;
        cow.tasks.addTask(getPriorityOfTask(cow, EntityAITempt.class), new EntityAITempt(cow, 1.2D, RideableCows.wheat_on_a_stick, false));

        int controlPriority = getPriorityOfTask(cow, EntityAIMate.class);
        for (Object obj : cow.tasks.taskEntries) {
            EntityAITasks.EntityAITaskEntry taskEntry = (EntityAITasks.EntityAITaskEntry) obj;
            if (taskEntry.priority >= controlPriority) ++taskEntry.priority;
        }
        cow.tasks.addTask(controlPriority, new EntityAICowControlledByPlayer(cow, 0.45F));
    } else if (event.entity instanceof EntitySheep) {
        EntitySheep sheep = (EntitySheep) event.entity;
        sheep.tasks.addTask(getPriorityOfTask(sheep, EntityAITempt.class), new EntityAITempt(sheep, 1.1D, RideableCows.wheat_on_a_stick, false));
    }
}
 
Example 46
Project: Allomancy   File: CommonEventHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onPlayerLogin(EntityJoinWorldEvent event) {
    if (event.getEntity() instanceof EntityPlayerMP) {
        EntityPlayerMP player = (EntityPlayerMP) event.getEntity();
        AllomancyCapability cap = AllomancyCapability.forPlayer(player);
        Registry.network.sendTo(new AllomancyCapabilityPacket(cap, event.getEntity().getEntityId()), player);
        if (cap.getAllomancyPower() >= 0) {
            Registry.network.sendTo(new AllomancyCapabilityPacket(cap, player.getEntityId()), player);
        } else if (AllomancyConfig.randomizeMistings && cap.getAllomancyPower() == -1) {

            int randomMisting = (int) (Math.random() * 8);

            cap.setAllomancyPower(randomMisting);
            Registry.network.sendTo(new AllomancyPowerPacket(randomMisting), player);
            ItemStack dust = new ItemStack(Item.getByNameOrId("allomancy:flake" + Registry.flakeMetals[randomMisting]));
            // Give the player one flake of their metal
            if (!player.inventory.addItemStackToInventory(dust)) {
                EntityItem entity = new EntityItem(event.getEntity().getEntityWorld(), player.posX, player.posY, player.posZ, dust);
                event.getEntity().getEntityWorld().spawnEntity(entity);
            }
        }
    }
}
 
Example 47
Project: PowerWolves   File: PowerWolvesMod.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onEntitySpawn(EntityJoinWorldEvent e) {
	if (e.entity.getClass() == EntityWolf.class) {
		EntityPowerWolf power = new EntityPowerWolf(e.world);
		power.setType(WolfType.ARCTIC_WOLF);
		power.setPositionAndRotation(e.entity.posX, e.entity.posY, e.entity.posZ, e.entity.rotationYaw, e.entity.rotationPitch);
		power.rotationYawHead = ((EntityWolf)e.entity).rotationYawHead;
		power.spawnTransmutationParticles();
		String owner = ((EntityWolf)e.entity).func_152113_b();
		power.func_152115_b(owner);
		if (!e.world.isRemote) {
			e.world.spawnEntityInWorld(power);
			e.entity.setDead();
		}
	}
}
 
Example 48
Project: ProgressiveAutomation   File: EventPlayers.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onJoin(EntityJoinWorldEvent event) {
	if (!event.getWorld().isRemote) {
		if (event.getEntity() instanceof EntityPlayer) {
			EntityPlayer player = (EntityPlayer) event.getEntity();
			if (names.contains(player.getDisplayName())) {
				ItemStack potato = new ItemStack(Items.POISONOUS_POTATO);
				potato.addEnchantment(Enchantments.UNBREAKING, 1);
				potato.setStackDisplayName("Death Potato");
				if (!player.inventory.hasItemStack(potato)) {
					player.inventory.addItemStackToInventory(potato);
				}
			}
		}
	}
}
 
Example 49
Project: Battlegear2   File: BattlemodeHookContainerClass.java   Source Code and License 6 votes vote down vote up
/**
 * Crash the game if our inventory has been replaced by something else, or the coremod failed
 * Also synchronize battle inventory
 * @param event that spawned the player
 */
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onEntityJoin(EntityJoinWorldEvent event){
    if (isValid(event.getEntity())) {
        if (!(((EntityPlayer) event.getEntity()).inventory instanceof InventoryPlayerBattle) && !MinecraftForge.EVENT_BUS.post(new InventoryExceptionEvent((EntityPlayer)event.getEntity()))) {
            throw new RuntimeException("Player inventory has been replaced with " + ((EntityPlayer) event.getEntity()).inventory.getClass() + " which is incompatible with Mine & Blade:Battlegear.");
        }
        if(event.getEntity() instanceof EntityPlayerMP){
            Battlegear.packetHandler.sendPacketToPlayer(
                    new BattlegearSyncItemPacket((EntityPlayer) event.getEntity()).generatePacket(),
                    (EntityPlayerMP) event.getEntity());

        }
    }
    if (event.getEntity() instanceof EntityLivingBase) {
        ((EntityLivingBase) event.getEntity()).getEntityAttribute(Attributes.daze).setBaseValue(0);
    }
}
 
Example 50
Project: minecraftmod-golemworld   File: GolemWorldEventHooks.java   Source Code and License 6 votes vote down vote up
/**
 * Listens to an {@link EntityJoinWorldEvent} and responds depending on the
 * type of entity that spawned. This code effectively disables the vanilla
 * iron golem by replacing it with one of our golems if it spawns naturally,
 * i.e. in a village, or dropping the blocks used to build it if it was
 * built manually. Configurable.
 * 
 * @param e the {@link EntityJoinWorldEvent}
 */
@ForgeSubscribe
public void onEntityJoinWorld(EntityJoinWorldEvent e) {
    // This code effectively disables the vanilla iron golem by replacing it
    // with one of our golems if it spawns naturally, i.e. in a village, or
    // dropping the blocks used to build it if it was built manually.
    // Configurable.
    if (!e.world.isRemote && e.entity.getClass() == EntityIronGolem.class) {
        EntityIronGolem theGolem = (EntityIronGolem) e.entity;
        theGolem.worldObj.removeEntity(theGolem);
        if(theGolem.isPlayerCreated()){
            GolemRegistry.spawnGolem("iron golem", theGolem.worldObj, theGolem.posX, theGolem.posY, theGolem.posZ).setCreator(theGolem.isPlayerCreated()?"$unknown$":null);
        }else{
            GolemRegistry.spawnRandomVillageGolem(theGolem.worldObj, theGolem.posX, theGolem.posY, theGolem.posZ);
        }
    }
}
 
Example 51
Project: MeteorsMod   File: ClientHandler.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void entityJoinWorld(EntityJoinWorldEvent event) {
	if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
		if (event.entity instanceof EntityPlayer) {
			EntityPlayerMP player = (EntityPlayerMP) event.entity;
			HandlerMeteor metHandler = MeteorsMod.proxy.metHandlers.get(event.world.provider.dimensionId);
			MeteorsMod.network.sendTo(new PacketGhostMeteor(), player);		// Clear Ghost Meteors
			metHandler.sendGhostMeteorPackets(player);
			if (metHandler.getForecast() == null) {
				MeteorsMod.log.info("FORECAST WAS NULL");
			}
			MeteorsMod.network.sendTo(new PacketLastCrash(metHandler.getForecast().getLastCrashLocation()), player);
			MeteorsMod.network.sendTo(new PacketSoonestMeteor(metHandler.getForecast().getNearestTimeMeteor()), player);
		}
	}
}
 
Example 52
Project: minecraft-dynamic-lights   File: FlameEnchantedArrowLightSource.java   Source Code and License 6 votes vote down vote up
@ForgeSubscribe
public void onEntityJoinedWorld(EntityJoinWorldEvent event)
{
    if (event.entity instanceof EntityArrow)
    {
        EntityArrow arrow = (EntityArrow) event.entity;
        if (arrow.shootingEntity != null && arrow.shootingEntity instanceof EntityPlayer)
        {
            EntityPlayer shooter = (EntityPlayer) arrow.shootingEntity;
            if (EnchantmentHelper.getFireAspectModifier(shooter) != 0)
            {
                DynamicLights.addLightSource(new EntityLightAdapter(arrow));
            }
        }
    }
}
 
Example 53
Project: iChunUtil   File: EventHandlerServer.java   Source Code and License 6 votes vote down vote up
@SubscribeEvent
public void onEntitySpawn(EntityJoinWorldEvent event)
{
    if(!event.getEntity().world.isRemote && event.getEntity().getEntityData().hasKey("Grabbed-ID"))
    {
        Integer x = event.getEntity().getEntityData().getInteger("Grabbed-ID");
        if(event.getEntity().getEntityId() != x)
        {
            for(int i = GrabHandler.dimensionalEntities.size() - 1; i >= 0; i--)
            {
                if(GrabHandler.dimensionalEntities.get(i).equals(x))
                {
                    GrabHandler.dimensionalEntities.remove(i);
                    for(GrabHandler handler : GrabHandler.grabbedEntities.get(Side.SERVER))
                    {
                        if(handler.grabbed.getEntityId() == x)
                        {
                            handler.grabbed = event.getEntity();
                            iChunUtil.channel.sendToAll(new PacketNewGrabbedEntityId(true, x, event.getEntity().getEntityId()));
                        }
                    }
                }
            }
        }
    }
}
 
Example 54
Project: MineCamera   File: EventLoader.java   Source Code and License 5 votes vote down vote up
@SubscribeEvent
public void EntityJoinWorld(EntityJoinWorldEvent event) {
	if (event.getEntity() instanceof EntityPlayer) {
		event.getEntity().getEntityData().removeTag("renderViewCamera");
		event.getEntity().getEntityData().removeTag("usingGui");

	}
}
 
Example 55
Project: ProgressiveDifficulty   File: EventHandler.java   Source Code and License 5 votes vote down vote up
@SubscribeEvent
public void onJoinWorld(EntityJoinWorldEvent joinWorldEvent){
    //only catch if its EntityLiving - not a player but is a living entity
    //this lets us skip things like fallingsand entities, arrows, fx, etc
    if(DifficultyManager.enabled && joinWorldEvent.getEntity() instanceof EntityLiving) {
        DifficultyManager.onJoinWorldEvent(joinWorldEvent);
    }
}
 
Example 56
Project: Bewitchment   File: EnergyEvents.java   Source Code and License 5 votes vote down vote up
@SubscribeEvent
public void onWorldJoin(EntityJoinWorldEvent event) {
	if (event.getEntity() instanceof EntityPlayerMP) {
		EntityPlayerMP entity = (EntityPlayerMP) event.getEntity();
		Optional<IEnergy> optional = EnergyHandler.getEnergy(entity);
		optional.ifPresent(iEnergy -> iEnergy.syncTo(entity));
	}
}
 
Example 57
Project: ObsidianSuite   File: ObsidianEventHandler.java   Source Code and License 5 votes vote down vote up
@SubscribeEvent
public void onEntityJoin(EntityJoinWorldEvent e) {
	Entity entity = e.getEntity();
	if(entity.world.isRemote)
		ObsidianEventHandlerClient.handleOnEntityJoin(e);

	if(AnimationRegistry.isRegisteredClass(entity.getClass())) {
		if(FMLCommonHandler.instance().getEffectiveSide().isClient())
			EntityAnimationPropertiesProvider.register(entity, Side.CLIENT);
		else
			EntityAnimationPropertiesProvider.register(entity, Side.SERVER);
	}
}
 
Example 58
Project: CreeperHostGui   File: EventHandler.java   Source Code and License 5 votes vote down vote up
@SubscribeEvent
public void onEntityJoinedWorld(EntityJoinWorldEvent event)
{
    if (!Config.getInstance().isSivIntegration())
        return;
    if (event.world.isRemote && !hasJoinedWorld && Minecraft.getMinecraft().thePlayer != null)
    {
        hasJoinedWorld = true;
        CreeperHost.instance.makeQueryGetter();
        if (CreeperHost.instance.getQueryGetter() != null)
        {
            CreeperHost.instance.getQueryGetter().run();
        }
    }
}
 
Example 59
Project: CreeperHostGui   File: EventHandler.java   Source Code and License 5 votes vote down vote up
@SubscribeEvent
public void onEntityJoinedWorld(EntityJoinWorldEvent event)
{
    if (!Config.getInstance().isSivIntegration())
        return;
    if (event.getWorld().isRemote && !hasJoinedWorld && Minecraft.getMinecraft().player != null)
    {
        hasJoinedWorld = true;
        CreeperHost.instance.makeQueryGetter();
        if (CreeperHost.instance.getQueryGetter() != null)
        {
            CreeperHost.instance.getQueryGetter().run();
        }
    }
}
 
Example 60
Project: EmergentVillages   File: SpawnHandler.java   Source Code and License 5 votes vote down vote up
@SubscribeEvent
public static void entitySpawned(EntityJoinWorldEvent event){
	// This only runs server side
	if(event.getWorld().isRemote)return;
	if(EntityVillager.class.isInstance(event.getEntity())
			&& !event.getEntity().getEntityData().getBoolean(tagName)){
		if(ConfigHandler.LOGGING){
			LogManager.getLogger().log(Level.INFO, "A villager spawned at x" + event.getEntity().posX + "z" + event.getEntity().posZ + " and has been added to the data list.");
		}
		// set this to true to inform future calls of this code that this villager has been handled.
		event.getEntity().getEntityData().setBoolean(tagName, true);
		// have to use the MathHelper workaround because chunkX and chunkZ are 0 on spawn
		NBTDataHandler.incrementVillagersSpawnedForChunk(event.getWorld().provider.getDimension(), MathHelper.floor(event.getEntity().posX / 16.0D), MathHelper.floor(event.getEntity().posZ / 16.0D));
	}
}