Java Code Examples for net.minecraftforge.event.entity.EntityJoinWorldEvent.setCanceled()

The following are Jave code examples for showing how to use setCanceled() of the net.minecraftforge.event.entity.EntityJoinWorldEvent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: InControl   File: ForgeEventHandlers.java   View Source Code Vote up 6 votes
@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 2
Project: Dark-Utilities   File: FeatureAntiSlime.java   View Source Code Vote up 6 votes
@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 3
Project: Gadomancy   File: EventHandlerWorld.java   View Source Code Vote up 6 votes
@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 4
Project: ItFellFromTheSky   File: EventHandler.java   View Source Code Vote up 6 votes
@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 5
Project: MobTotems   File: CowLogic.java   View Source Code Vote up 6 votes
@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 6
Project: MobTotems   File: CreeperLogic.java   View Source Code Vote up 6 votes
@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 7
Project: uniquecrops   File: UCEventHandlerServer.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void onBlockFall(EntityJoinWorldEvent event) {
	
	if (event.getEntity() != null && event.getEntity() instanceof EntityFallingBlock) {
		EntityPlayer player = event.getEntity().worldObj.getClosestPlayerToEntity(event.getEntity(), range);
		if (player != null && player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() == UCItems.precisionShovel) {
			if (NBTUtils.getInt(player.getHeldItemMainhand(), ItemGeneric.TAG_UPGRADE, -1) == 10)
				event.setCanceled(true);
		}
	}
}
 
Example 8
Project: NemesisSystem   File: SpawnHandler.java   View Source Code Vote up 5 votes
private void handleRespawnOfNemesis(EntityJoinWorldEvent event) {
	Entity entity = event.getEntity();
	NemesisEntry nemesis = NemesisUtil.loadNemesisFromEntity(event.getEntity());
	if (nemesis == null) {
		/*
		 * missing nemesis data
		 */
		entity.setDead();
		event.setCanceled(true);
	} else if (entity.getTags().contains(NemesisSystem.TAG_SPAWNING)) {
		/*
		 * new nemesis spawn in progress
		 */
		entity.removeTag(NemesisSystem.TAG_SPAWNING);
		nemesis.setSpawned(entity.getEntityId());
		nemesis.setUnloaded(null);
		NemesisRegistryProvider.get(entity.world).update(nemesis);
		sendNemesisDataToClient(nemesis);
	} else if (!nemesis.isSpawned()) {
		/*
		 * nemesis has been marked as despawned
		 */
		event.setCanceled(true);
	} else {
		/*
		 * nemesis is marked unloaded, mark as loaded now he is respawning
		 */
		if (!entity.getPersistentID().equals(nemesis.getEntityUuid())) {
			event.setCanceled(true);
			return;
		}

		nemesis.setSpawned(entity.getEntityId());
		nemesis.setUnloaded(null);
		nemesis.setLastSpawned(entity.world.getTotalWorldTime());
		NemesisRegistryProvider.get(event.getWorld()).update(nemesis);
		sendNemesisDataToClient(nemesis);
	}
}
 
Example 9
Project: runesofwizardry-classics   File: RuneLockedTime.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void onEntityCreation(EntityJoinWorldEvent event){
	if(Config.lockedTimeFalling && (event.getEntity() instanceof EntityFallingBlock)){
		if(LockedTimeData.get(event.getWorld()).getNumRunes()>0){
			EntityFallingBlock fb = (EntityFallingBlock)event.getEntity();
			IBlockState state = fb.getBlock();
			fb.setDead();
			event.getWorld().setBlockState(fb.getPosition(), state);
			event.setCanceled(true);
		}
	}
}
 
Example 10
Project: Overlord   File: CommonEvents.java   View Source Code Vote up 5 votes
@SubscribeEvent
public static void entitySpawn(EntityJoinWorldEvent event){
	if(ConfigValues.XPOVERRIDE && !event.getWorld().isRemote && event.getEntity().getClass() == EntityXPOrb.class){
		event.setCanceled(true);
		EntityXPOrb xp = (EntityXPOrb) event.getEntity();
		EntityCustomXPOrb newXP = new EntityCustomXPOrb(xp.world, xp.posX, xp.posY, xp.posZ, xp.xpValue);
		event.getWorld().spawnEntity(newXP);
	}
}
 
Example 11
Project: Gravestone-mod-Extended   File: GSEventsHandler.java   View Source Code Vote up 5 votes
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void entityJoinWorldEvent(EntityJoinWorldEvent event) {
    Entity entity = event.getEntity();

    if (ExtendedConfig.overrideVanillaFishing && entity instanceof EntityFishHook && entity.getClass().equals(EntityFishHook.class)) {
        World world = event.getWorld();
        if (!world.isRemote) {
            EntityPlayer player = ((EntityFishHook) entity).getAngler();
            ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND);
            if (stack.getItem() != Items.FISHING_ROD) {
                stack = player.getHeldItem(EnumHand.OFF_HAND);
            }
            entity.setDead();

            EntityCustomFishHook hook = new EntityCustomFishHook(world, player);

            int speed = EnchantmentHelper.getFishingSpeedBonus(stack);
            if (speed > 0) {
                hook.setLureSpeed(speed);
            }
            int luck = EnchantmentHelper.getFishingLuckBonus(stack);
            if (luck > 0) {
                hook.setLuck(luck);
            }

            world.spawnEntity(hook);
        }

        event.setCanceled(true);
    }
}
 
Example 12
Project: vsminecraft   File: ItemBlockCardboardBox.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void onEntitySpawn(EntityJoinWorldEvent event)
{
	if(event.entity instanceof EntityItem && isMonitoring)
	{
		event.setCanceled(true);
	}
}
 
Example 13
Project: sprinkles_for_vanilla   File: EntityHandlers.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void onEntityJoin(EntityJoinWorldEvent event)
{
    Entity entity = event.entity;
    Class<?> entityClass = entity.getClass();
    if (blockedMobClasses.containsValue(entityClass) && SprinklesForVanilla.isOnServer)
    {
        if (entityClass == EntityZombie.class)
        {
            if (blockedMobClasses.containsKey("zombieVillager") && ((EntityZombie) entity).isVillager())
            {
                event.setCanceled(true);
            }
            else if (blockedMobClasses.containsKey("zombie") && !((EntityZombie) entity).isVillager())
            {
                event.setCanceled(true);
            }
        }
        else if (entityClass == EntitySkeleton.class)
        {
            if (blockedMobClasses.containsKey("skeleton") && ((EntitySkeleton) entity).getSkeletonType() == 0)
            {
                event.setCanceled(true);
            }
            else if (blockedMobClasses.containsKey("witherSkeleton") && ((EntitySkeleton) entity).getSkeletonType() == 1)
            {
                event.setCanceled(true);
            }
        }
        else
        {
            event.setCanceled(true);
        }
    }
}
 
Example 14
Project: vintagecraft   File: VintageCraft.java   View Source Code Vote up 5 votes
@SubscribeEvent
  public void entityJoin(EntityJoinWorldEvent evt) {
if (!evt.world.isRemote && evt.entity instanceof EntityPlayerMP) {
	
	packetPipeline.sendTo(new WorldDataPacket(evt.world.getSeed()), (EntityPlayerMP)evt.entity);
}

if (evt.entity instanceof EntityZombie) {
	if (((EntityZombie)evt.entity).isChild()) {
		((EntityZombie)evt.entity).setChild(false);
		evt.setCanceled(true);
	}
}
  }
 
Example 15
Project: enderutilities   File: EntityEventHandler.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void onJoinWorld(EntityJoinWorldEvent event)
{
    if (event.getWorld().isRemote == false)
    {
        if ((event.getEntity() instanceof EntityLiving) && event.getEntity().getTags().contains(ItemSyringe.TAG_PASSIFIED))
        {
            ItemSyringe.passifyEntity((EntityLiving) event.getEntity());
        }
        else if (preventItemSpawningInWorld && (event.getEntity() instanceof EntityItem))
        {
            event.setCanceled(true);
        }
    }
}
 
Example 16
Project: AlchemicalBling   File: EntityEventHandler.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
	if (event.entity instanceof EntityPotion && !(event.entity instanceof EntitySplashPotion)) {
		EntitySplashPotion potion = new EntitySplashPotion((EntityPotion) event.entity);
		event.setCanceled(true);
		event.entity.setDead();
		event.entity.worldObj.spawnEntityInWorld(potion);
	}
}
 
Example 17
Project: IceAndShadow2   File: NyxEventHandlerCold.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void onFireball(EntityJoinWorldEvent e) {
	if (e.entity == null)
		return;

	if (e.entity.dimension == IaSFlags.dim_nyx_id) {
		if (e.entity instanceof EntitySmallFireball || e.entity instanceof EntityFireball
				|| e.entity instanceof EntityLargeFireball) {
			e.setCanceled(true);
		}
		e.entity.extinguish();
	}
}
 
Example 18
Project: ModTutoriel17   File: EntityEventHandler.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void onEntityJoin(EntityJoinWorldEvent event)
{
    if(event.entity instanceof EntityZombie)
    {
        event.setCanceled(true);
    }
}
 
Example 19
Project: Battlegear2   File: MobHookContainerClass.java   View Source Code Vote up 5 votes
/**
 * Listen to {@link EntityJoinWorldEvent} :
 * Adds random special {@link EntityArrow}s data to {@link AbstractSkeleton}s {@link net.minecraft.network.datasync.EntityDataManager} (for display)
 * Replace the vanilla fired {@link EntityTippedArrow} with the custom {@link AbstractMBArrow} (for actual action)
 * Note: Fails silently
 */
@SubscribeEvent(priority = EventPriority.LOW)
public void onEntityJoinWorld(EntityJoinWorldEvent event){
    if(event.getEntity() instanceof AbstractSkeleton){
        registerArrowType((AbstractSkeleton)event.getEntity());
    }else if(event.getEntity() instanceof EntityTippedArrow && ((EntityTippedArrow) event.getEntity()).getColor() == 0){
        EntityArrow arrow = ((EntityArrow)event.getEntity());
        if (arrow.shootingEntity instanceof AbstractSkeleton) {
            AbstractSkeleton skeleton = (AbstractSkeleton) arrow.shootingEntity;
            if(skeleton.getAttackTarget() != null) {
                ItemStack type = getArrowForMob(skeleton);
                if (type.getItem() instanceof ItemArrow) {
                    EntityArrow mbArrow = ((ItemArrow)type.getItem()).createArrow(skeleton.world, type, skeleton);
                    if (!(mbArrow instanceof EntityTippedArrow)) {
                        EntityLivingBase target = skeleton.getAttackTarget();
                        float pow = MathHelper.sqrt(skeleton.getDistanceSq(target.posX, target.getEntityBoundingBox().minY, target.posZ)) / 15F;
                        pow = MathHelper.clamp(pow, 0.1F, 1.0F);

                        mbArrow.setEnchantmentEffectsFromEntity(skeleton, pow);
                        if (skeleton instanceof EntityWitherSkeleton)
                            mbArrow.setFire(100);
                        double d0 = target.posX - skeleton.posX;
                        double d1 = target.getEntityBoundingBox().minY + (double)(target.height / 3.0F) - mbArrow.posY;
                        double d2 = target.posZ - skeleton.posZ;
                        double d3 = (double)MathHelper.sqrt(d0 * d0 + d2 * d2);
                        mbArrow.setThrowableHeading(d0, d1 + d3 * 0.2D, d2, 1.6F, (float)(14 - skeleton.world.getDifficulty().getDifficultyId() * 4));
                        mbArrow.setDamage(arrow.getDamage());
                        if (skeleton.world.spawnEntity(mbArrow))
                            event.setCanceled(true);
                    }
                }
            }
        }
    }
}
 
Example 20
Project: OpenBlocks   File: EntityEventHandler.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {

	final Entity entity = event.getEntity();
	if (entity != null) {
		Set<Class<? extends Entity>> blacklist = getBlacklist();
		if (blacklist.contains(entity.getClass())) {
			entity.setDead();
			event.setCanceled(true);
			return;
		}
	}

	/**
	 * If the player hasn't been given a manual, we'll give him one! (or
	 * throw it on the floor..)
	 */
	if (Config.spamInfoBook && !event.getWorld().isRemote && entity instanceof EntityPlayer) {
		EntityPlayer player = (EntityPlayer)entity;
		NBTTagCompound persistTag = PlayerUtils.getModPlayerPersistTag(player, "OpenBlocks");

		boolean shouldGiveManual = OpenBlocks.Items.infoBook != null && !persistTag.getBoolean(GIVEN_MANUAL_TAG);
		if (shouldGiveManual) {
			ItemStack manual = new ItemStack(OpenBlocks.Items.infoBook);
			if (!player.inventory.addItemStackToInventory(manual)) {
				BlockUtils.dropItemStackInWorld(player.world, player.posX, player.posY, player.posZ, manual);
			}
			persistTag.setBoolean(GIVEN_MANUAL_TAG, true);
		}
	}
}
 
Example 21
Project: CodeLyokoMod   File: EventHandler.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event)
{
    Entity ent = event.entity;
    if (!(ent instanceof EntityPlayer || ent instanceof EntityLyoko || ent instanceof EntitySpecter || ent instanceof IProjectile || ent instanceof EntityVehicle))
        if (CodeLyoko.entityInLyoko(ent))
            event.setCanceled(true);
}
 
Example 22
Project: minecraft-roguelike   File: EntityJoinWorld.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void OnEntityJoinWorld(EntityJoinWorldEvent event) {
	
	World world = event.getWorld();
	if(world.isRemote) return;
	
	Entity entity = event.getEntity();
	
	// slimes do not extend EntityMob for some reason
	if(!(entity instanceof EntityMob || entity instanceof EntitySlime)){
		return;
	}
	
	EntityLiving mob = (EntityLiving) entity;
	
	Collection<?> effects = mob.getActivePotionEffects();
	for(Object buff : effects){
		if(Potion.getIdFromPotion(((PotionEffect) buff).getPotion()) == 4){
			int level = ((PotionEffect) buff).getAmplifier();
			
			IEntity metaEntity = new MetaEntity((Entity)mob);
			MonsterProfile.equip(world, world.rand, level, metaEntity);
			if(entity.isDead) event.setCanceled(true);
			return;
		}
	}
}
 
Example 23
Project: ProgressiveDifficulty   File: DifficultyManager.java   View Source Code Vote up 4 votes
public static void onJoinWorldEvent(EntityJoinWorldEvent joinWorldEvent) {
    //we actually got to this step, so lets do something with it.
    //note: we check this conversion up in the caller of this class.  should be safe.
    EntityLiving mobToSpawn = (EntityLiving) joinWorldEvent.getEntity();
    if (MobNBTHandler.isModifiedMob(mobToSpawn) || !shouldModifyEntity(mobToSpawn))
        return;
    SpawnEventDetails details = eventsThisTickByDimension.computeIfAbsent(joinWorldEvent.getEntity().world.provider.getDimension(), thing -> new HashMap<>()).get(mobToSpawn);
    if (details == null) {//skipped an earlier check for some reason.  Give it defaults.
        details = new SpawnEventDetails();
        details.entity = mobToSpawn;
        details.fromSpawner = false;
    }

    //find region
    int dimension = joinWorldEvent.getWorld().provider.getDimension();
    Region homeRegion = getRegionForPosition(dimension, joinWorldEvent.getEntity().getPosition());
    int difficulty = homeRegion.determineDifficultyForSpawnEvent(details);
    if (difficulty < 0 && homeRegion.doesNegativeDifficultyPreventSpawn()) {
        int chance = joinWorldEvent.getWorld().rand.nextInt(100);
        if (Math.abs(difficulty) >= chance) {
            if (mobToSpawn.isBeingRidden() || mobToSpawn.isRiding()) {
                LOG.info("RIDER!: " + mobToSpawn.getClass());
            }
            //also remove anything riding or being ridden (zombies on chickens, skeletons on spiders)
            if (mobToSpawn.isBeingRidden()) {
                for (Entity passenger : mobToSpawn.getPassengers()) {
                    passenger.setDropItemsWhenDead(false);
                    passenger.setDead();
                }
            } else if (mobToSpawn.isRiding()) {
                Entity mount = mobToSpawn.getRidingEntity();
                mount.setDropItemsWhenDead(false);
                mount.setDead();
            }
            joinWorldEvent.setCanceled(true);
            return;
        }
    }
    if (difficulty >= homeRegion.getThreshold()) {
        homeRegion.makeDifficultyChanges(mobToSpawn, difficulty, joinWorldEvent.getWorld().rand);
    }
}
 
Example 24
Project: CustomWorldGen   File: ForgeInternalHandler.java   View Source Code Vote up 4 votes
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onEntityJoinWorld(EntityJoinWorldEvent event)
{
    if (!event.getWorld().isRemote)
    {
        ForgeChunkManager.loadEntity(event.getEntity());
    }

    Entity entity = event.getEntity();
    if (entity.getClass().equals(EntityItem.class))
    {
        ItemStack stack = ((EntityItem)entity).getEntityItem();

        if (stack == null)
        {
            //entity.setDead();
            //event.setCanceled(true);
            return;
        }

        Item item = stack.getItem();
        if (item == null)
        {
            FMLLog.warning("Attempted to add a EntityItem to the world with a invalid item at " +
                "(%2.2f,  %2.2f, %2.2f), this is most likely a config issue between you and the server. Please double check your configs",
                entity.posX, entity.posY, entity.posZ);
            entity.setDead();
            event.setCanceled(true);
            return;
        }

        if (item.hasCustomEntity(stack))
        {
            Entity newEntity = item.createEntity(event.getWorld(), entity, stack);
            if (newEntity != null)
            {
                entity.setDead();
                event.setCanceled(true);
                event.getWorld().spawnEntityInWorld(newEntity);
            }
        }
    }
}
 
Example 25
Project: Malgra   File: MalgraEventHandler.java   View Source Code Vote up 4 votes
@SubscribeEvent
public void onJoinWorld(EntityJoinWorldEvent event) {
	if (event.getEntity() instanceof EntityItem && !(event.getEntity() instanceof EntityItemMalgraTool)) {
		EntityItem entityItem = (EntityItem) event.getEntity();
		if (entityItem.getItem().getItem() == net.minecraft.init.Items.DIAMOND_PICKAXE) {
			event.setCanceled(true);
			ItemStack malgraPickaxe = new ItemStack(Items.malgraPickaxe);
			malgraPickaxe.setTagCompound(new NBTTagCompound());
			malgraPickaxe.getTagCompound().setInteger("malgra", ((MalgraTool)malgraPickaxe.getItem()).getMaxMalgra());

			EntityItemMalgraTool newEntity = new EntityItemMalgraTool(event.getWorld(), event.getEntity().posX, event.getEntity().posY, event.getEntity().posZ, ((EntityItem) event.getEntity()).getItem(), malgraPickaxe);
			event.getWorld().spawnEntity(newEntity);
			NBTTagCompound nbt = new NBTTagCompound();
			event.getEntity().writeToNBTOptional(nbt);
			newEntity.readFromNBT(nbt);
		}
	}
	if (event.getEntity() instanceof EntityPlayerMP) {
		PacketDispatcher.sendTo(new SyncManaData(event.getEntity().getCapability(CapabilityMana.MANA, null)), (EntityPlayerMP) event.getEntity());
		PacketDispatcher.sendTo(new SyncResearchPoints(event.getEntity().getCapability(CapabilityResearchPoints.RESEARCHPOINTS, null)), (EntityPlayerMP) event.getEntity());
		PacketDispatcher.sendTo(new SyncResearchActivites(event.getEntity().getCapability(CapabilityResearchActivites.RESEARCHACTIVITIES,  null)), (EntityPlayerMP) event.getEntity());
           if(ResearchDimensions.get(event.getWorld()).researchDimIDs.get(event.getEntity().getUniqueID().toString()) == null) {
               int researchDimID = DimensionManager.getNextFreeDimId();

               DimensionType researchDim = DimensionType.register("research" + event.getEntity().getUniqueID().toString(), "", researchDimID, WorldProviderResearch.class, false);
               DimensionManager.registerDimension(researchDimID, researchDim);

			ResearchDimensions.get(event.getWorld()).researchDimIDs.put(event.getEntity().getUniqueID().toString(), researchDimID);
			ResearchDimensions.get(event.getWorld()).researchDimTypes.put(researchDimID, researchDim);

               Iterator it = ResearchDimensions.get(event.getWorld()).researchDimIDs.entrySet().iterator();
               while (it.hasNext()) {
                   Map.Entry pair = (Map.Entry)it.next();
                   if(FMLCommonHandler.instance().getSide() == Side.SERVER)
                   PacketDispatcher.sendTo(new SyncResearchDimensions((String)pair.getKey(), (Integer)pair.getValue()), (EntityPlayerMP) event.getEntity());
               }

			ResearchDimensions.get(event.getWorld()).markDirty();

           }
	}

}
 
Example 26
Project: wolfarmor   File: EntityEventHandler.java   View Source Code Vote up 4 votes
/**
 * Converts old EntityWolfArmored back to EntityWolf to leverage capabilities system
 *
 * @param event The event data
 */
@Deprecated
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onEntityWolfArmoredJoinedWorld(@Nonnull EntityJoinWorldEvent event) {
    World world = event.getWorld();
    if (!world.isRemote) {
        Entity entity = event.getEntity();

        if (entity.getClass() == EntityWolfArmored.class) {
            WolfArmorMod.getLogger().warning("Replacing EntityWolfArmored with new capable wolf");

            EntityWolfArmored entityWolfArmored = (EntityWolfArmored) entity;
            EntityWolf entityWolf = new EntityWolf(world);
            IWolfArmorCapability wolfArmorCapability = entityWolf.getCapability(CapabilityWolfArmor.WOLF_ARMOR_CAPABILITY, null);
            if(wolfArmorCapability == null) {
                throw new RuntimeException("Failed to replace entity: Capabilities were not properly registered!");
            }

            IInventory wolfInventory = entityWolfArmored.getInventory();
            IInventory capabilityInventory = wolfArmorCapability.getInventory();
            for (int i = 0; i < wolfInventory.getSizeInventory(); i++) {
                ItemStack stack = wolfInventory.getStackInSlot(i);

                capabilityInventory.setInventorySlotContents(i, stack);
            }

            if (entityWolfArmored.getHasArmor()) {
                wolfArmorCapability.setArmorItemStack(entityWolfArmored.getArmorItemStack());
            }

            if (entityWolfArmored.getHasChest()) {
                wolfArmorCapability.setHasChest(true);
            }

            NBTTagCompound compound = new NBTTagCompound();
            entityWolfArmored.writeToNBT(compound);

            entityWolf.copyLocationAndAnglesFrom(entityWolfArmored);
            entityWolf.readEntityFromNBT(compound);

            world.spawnEntity(entityWolf);
            entityWolfArmored.setDead();
            event.setCanceled(true);
        }
    }
}
 
Example 27
Project: morecommands   File: CommandIgnorespawn.java   View Source Code Vote up 4 votes
@Override
public void onEvent(EntityJoinWorldEvent event) {
	if (isEntityIgnored(event.getEntity()))
		event.setCanceled(true);
}
 
Example 28
Project: morecommands   File: CommandDodrops.java   View Source Code Vote up 4 votes
@Override
public void onEvent(EntityJoinWorldEvent event) {
	if (event.getEntity() instanceof EntityItem && !this.dodrops) event.setCanceled(true);
}
 
Example 29
Project: PerFabricaAdAstra   File: RespirationHandler.java   View Source Code Vote up 4 votes
@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
    if (entityInIndustrialFluid(event.world, event.entity)) {
        event.setCanceled(true);
    }
}