Java Code Examples for cpw.mods.fml.common.eventhandler.EventPriority#HIGHEST

The following examples show how to use cpw.mods.fml.common.eventhandler.EventPriority#HIGHEST . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerEventHandler.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void dropEvent(LivingDropsEvent event) {
	if (event.entityLiving.worldObj.isRemote)
		return;

	if (EtFuturum.enableSkullDrop)
		dropHead(event.entityLiving, event.source, event.lootingLevel, event.drops);

	Random rand = event.entityLiving.worldObj.rand;
	if (EtFuturum.enableMutton && event.entityLiving instanceof EntitySheep) {
		int amount = rand.nextInt(3) + 1 + rand.nextInt(1 + event.lootingLevel);
		for (int i = 0; i < amount; i++)
			if (event.entityLiving.isBurning())
				addDrop(new ItemStack(ModItems.cooked_mutton), event.entityLiving, event.drops);
			else
				addDrop(new ItemStack(ModItems.raw_mutton), event.entityLiving, event.drops);
	}
}
 
Example 2
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 6 votes vote down vote up
@SuppressWarnings("unchecked")
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent ev) {
    if (ev.entityPlayer.worldObj.isRemote || ev.isCanceled()) {
        return;
    }

    Resident res = MyTownUniverse.instance.getOrMakeResident(ev.entityPlayer);
    if(ev.entityPlayer.getHeldItem() != null) {
        ProtectionManager.checkUsage(ev.entityPlayer.getHeldItem(), res, ev.action, createBlockPos(ev), ev.face, ev);
    }
    if (!ev.isCanceled()) {
        ProtectionManager.checkBlockInteraction(res, new BlockPos(ev.x, ev.y, ev.z, ev.world.provider.dimensionId), ev.action, ev);
    }

    // Some things (Autonomous Activator) only care about these. So always deny them if the event is canceled.
    if (ev.isCanceled()) {
        ev.useBlock = Event.Result.DENY;
        ev.useItem = Event.Result.DENY;
    }
}
 
Example 3
Source File: ForgeMain.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerChangedWorld(EntityJoinWorldEvent event) {
    Entity entity = event.entity;
    if (!(entity instanceof EntityPlayerMP)) {
        return;
    }
    EntityPlayerMP player = (EntityPlayerMP) entity;
    if (player.worldObj.isRemote) {
        return;
    }
}
 
Example 4
Source File: RenderEventHandler.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void onSetArmor(RenderPlayerEvent.SetArmorModel event) {
    if(event.entityPlayer == current) {
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
        GL11.glDepthMask(true);
    }
}
 
Example 5
Source File: EventHandlerGolem.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void on(EntityEvent.EnteringChunk event) {
    if(event.entity instanceof EntityGolemBase) {
        EntityGolemBase golem = (EntityGolemBase) event.entity;
        if(GadomancyApi.isAdditionalGolemType(golem.getGolemType())) {
            ExtendedGolemProperties props = (ExtendedGolemProperties)event.entity.getExtendedProperties(Gadomancy.MODID);
            if(props.shouldUpdateHealth()) {
                props.resetUpdateHealth();
                golem.setHealth(props.getHealth());
            }
        }
    }
}
 
Example 6
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onModifyBiome(ModifyBiomeEvent ev) {
    if (ev.world.isRemote || ev.isCanceled() || Config.instance.taintSpreadInTowns.get()) {
        return;
    }

    if(MyTownUniverse.instance.blocks.contains(ev.world.provider.dimensionId, ev.x >> 4, ev.z >> 4)) {
        ev.setCanceled(true);
    }
}
 
Example 7
Source File: MOPHelper.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onRenderHighlight(DrawBlockHighlightEvent event) {

    if (!(event.target instanceof ExtendedMOP)
            && event.player.worldObj.getTileEntity(event.target.blockX, event.target.blockY, event.target.blockZ) instanceof TileMultipart)
        event.setCanceled(true);
}
 
Example 8
Source File: PlayerSpecials.java    From Chisel-2 with GNU General Public License v2.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerRenderPre(RenderLivingEvent.Pre event) {
       if(nameIsGood(event.entity)){
           GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.75F);
           GL11.glEnable(GL11.GL_BLEND);
           GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
       }
}
 
Example 9
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onBlockTrample(BlockTrampleEvent ev) {
    if(ev.world.isRemote || ev.isCanceled())
        return;

    Entity entity = ev.entity;
    Resident res = null;

    if(!(entity instanceof EntityPlayer)) {
        // Protect from players ridding any entity
        if(entity.riddenByEntity != null && (entity.riddenByEntity instanceof EntityPlayer))
            entity = entity.riddenByEntity;
        // Protect from players jumping and leaving the horse in mid-air
        else
            res = ProtectionManager.getOwner(entity);
    }

    // Fake players are special
    if(entity instanceof FakePlayer) {
        if(!ProtectionManager.getFlagValueAtLocation(FlagType.FAKERS, ev.world.provider.dimensionId, ev.x, ev.y, ev.z)) {
            ev.setCanceled(true);
        }
    } else {
        // Will be null if we didn't find the player responsible for this trampling
        if(res == null) {
            res = MyTownUniverse.instance.getOrMakeResident(entity);
            // Will be null if it wasn't caused by a known player
            if(res == null)
                return;
        }

        // Trampling crops will break them and will modify the terrain
        if (!ProtectionManager.checkBlockBreak(ev.block)) {
            if(!ProtectionManager.hasPermission(res, FlagType.MODIFY, ev.world.provider.dimensionId, ev.x, ev.y, ev.z)) {
                ev.setCanceled(true);
            }
        }
    }
}
 
Example 10
Source File: Ticker.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent ev) {
    Resident res = MyTownUniverse.instance.getOrMakeResident(ev.player);
    if (res != null) {
        res.setPlayer(ev.player);
    } else {
        MyTown.instance.LOG.error("Didn't create resident for player {} ({})", ev.player.getCommandSenderName(), ev.player.getPersistentID());
    }
}
 
Example 11
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@SuppressWarnings("unchecked")
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerAttackEntityEvent(AttackEntityEvent ev) {
    if(ev.entity.worldObj.isRemote || ev.isCanceled()) {
        return;
    }

    Resident res = MyTownUniverse.instance.getOrMakeResident(ev.entityPlayer);
    ProtectionManager.checkInteraction(ev.target, res, ev);
}
 
Example 12
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onProjectileImpact(ProjectileImpactEvent ev) {
    if (ev.entity.worldObj.isRemote || ev.isCanceled()) {
        return;
    }

    EntityLivingBase firingEntity = ev.firingEntity;
    Resident owner = null;
    if (firingEntity instanceof EntityPlayerMP && !(firingEntity instanceof FakePlayer)) {
        owner = MyTownUniverse.instance.getOrMakeResident(firingEntity);
    }
    ProtectionManager.checkImpact(ev.entity, owner, ev.movingObjectPosition, ev);
}
 
Example 13
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onAE2PartPlace(AE2PartPlaceEvent ev) {
    if (ev.world.isRemote || ev.isCanceled()) {
        return;
    }

    Resident res = MyTownUniverse.instance.getOrMakeResident(ev.player);
    if(ev.player.getHeldItem() != null) {
        ProtectionManager.checkUsage(ev.player.getHeldItem(), res, Action.RIGHT_CLICK_BLOCK, new BlockPos(ev.x, ev.y, ev.z, ev.world.provider.dimensionId), ev.face, ev);
    }
}
 
Example 14
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onModifyBlock(ModifyBlockEvent ev) {
    if (ev.world.isRemote || ev.isCanceled() || Config.instance.fireSpreadInTowns.get()) {
        return;
    }

    if(!ProtectionManager.getFlagValueAtLocation(FlagType.MODIFY, ev.world.provider.dimensionId, ev.x, ev.y, ev.z)) {
        ev.setCanceled(true);
        return;
    }
}
 
Example 15
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 4 votes vote down vote up
@SuppressWarnings("unchecked")
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerBreaksBlock(BlockEvent.BreakEvent ev) {
    if(ev.world.isRemote || ev.isCanceled()) {
        return;
    }

    if(ev.getPlayer() instanceof FakePlayer) {
        if(!ProtectionManager.getFlagValueAtLocation(FlagType.FAKERS, ev.world.provider.dimensionId, ev.x, ev.y, ev.z)) {
            ev.setCanceled(true);
        }
    } else {
        Resident res = MyTownUniverse.instance.getOrMakeResident(ev.getPlayer());

        if (!MyTownUniverse.instance.blocks.contains(ev.world.provider.dimensionId, ev.x >> 4, ev.z >> 4)) {
            int range = Config.instance.placeProtectionRange.get();
            Volume breakBox = new Volume(ev.x-range, ev.y-range, ev.z-range, ev.x+range, ev.y+range, ev.z+range);

            if(!ProtectionManager.checkBlockBreak(ev.block)) {
                if(!ProtectionManager.hasPermission(res, FlagType.MODIFY, ev.world.provider.dimensionId, breakBox)) {
                    ev.setCanceled(true);
                    return;
                }
            }

        } else {
            if (!ProtectionManager.checkBlockBreak(ev.block)) {
                if(!ProtectionManager.hasPermission(res, FlagType.MODIFY, ev.world.provider.dimensionId, ev.x, ev.y, ev.z)) {
                    ev.setCanceled(true);
                    return;
                }
            }
        }

        if(ev.getPlayer().getHeldItem() != null) {
            ProtectionManager.checkBreakWithItem(ev.getPlayer().getHeldItem(), res, new BlockPos(ev.x, ev.y, ev.z, ev.world.provider.dimensionId), ev);
        }
    }

    if (!ev.isCanceled() && ev.block instanceof ITileEntityProvider) {
        TileEntity te = ((ITileEntityProvider) ev.block).createNewTileEntity(ev.world, ev.blockMetadata);
        if(te != null && ProtectionManager.isOwnable(te.getClass())) {
            te = ev.world.getTileEntity(ev.x, ev.y, ev.z);
            ownedTileEntities.remove(te);
            MyTown.instance.LOG.info("Removed te {}", te.toString());
        }
    }
}
 
Example 16
Source File: TooltipEventHandler.java    From bartworks with MIT License 4 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void getTooltip(ItemTooltipEvent event) {

    if (event == null || event.itemStack == null || event.itemStack.getItem() == null)
        return;

    if (TooltipCache.getTooltip(event.itemStack).isEmpty()) {
        ItemStack tmp = event.itemStack.copy();
        Pair<Integer,Short> abstractedStack = new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage());
        List<String> tooAdd = new ArrayList<>();
        if (OreDictHandler.getNonBWCache().contains(abstractedStack)) {
            for (Pair<Integer,Short> pair : OreDictHandler.getNonBWCache()) {
                if (pair.equals(abstractedStack)) {
                    GameRegistry.UniqueIdentifier UI = GameRegistry.findUniqueIdentifierFor(tmp.getItem());
                    if (UI == null)
                        UI = GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(tmp.getItem()));
                    if (UI != null) {
                        for (ModContainer modContainer : Loader.instance().getModList()) {
                            if (UI.modId.equals(MainMod.MOD_ID) || UI.modId.equals(BartWorksCrossmod.MOD_ID) || UI.modId.equals("BWCore"))
                                break;
                            if (UI.modId.equals(modContainer.getModId())) {
                                tooAdd.add("Shared ItemStack between " + ChatColorHelper.DARKGREEN + "BartWorks" + ChatColorHelper.GRAY + " and " + ChatColorHelper.RED + modContainer.getName());
                            }
                        }
                    } else
                        tooAdd.add("Shared ItemStack between " + ChatColorHelper.DARKGREEN + "BartWorks" + ChatColorHelper.GRAY + " and another Mod, that doesn't use the ModContainer propperly!");
                }
            }
        }

        Block BLOCK = Block.getBlockFromItem(event.itemStack.getItem());
        if (BLOCK != null && BLOCK != Blocks.air) {
            if (BLOCK instanceof BW_Blocks) {
                TooltipCache.put(event.itemStack, tooAdd);
                return;
            }
            BioVatLogicAdder.BlockMetaPair PAIR = new BioVatLogicAdder.BlockMetaPair(BLOCK, (byte) event.itemStack.getItemDamage());
            HashMap<BioVatLogicAdder.BlockMetaPair, Byte> GLASSMAP = BioVatLogicAdder.BioVatGlass.getGlassMap();
            if (GLASSMAP.containsKey(PAIR)) {
                int tier = GLASSMAP.get(PAIR);
                tooAdd.add(
                        StatCollector.translateToLocal("tooltip.glas.0.name") +
                                " "
                                + BW_ColorUtil.getColorForTier(tier) + GT_Values.VN[tier] + ChatColorHelper.RESET);
            } else if (BLOCK.getMaterial().equals(Material.glass)) {
                tooAdd.add(StatCollector.translateToLocal("tooltip.glas.0.name") +
                        " "
                        + BW_ColorUtil.getColorForTier(3) + GT_Values.VN[3] + ChatColorHelper.RESET);
            }
        }

        TooltipCache.put(event.itemStack, tooAdd);
        event.toolTip.addAll(tooAdd);
    } else {
        event.toolTip.addAll(TooltipCache.getTooltip(event.itemStack));
    }
}
 
Example 17
Source File: SafemodeHandler.java    From MyTown2 with The Unlicense 4 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent ev) {
    if (safemode && ev.player instanceof EntityPlayerMP) {
        kickPlayer((EntityPlayerMP) ev.player);
    }
}
 
Example 18
Source File: TickDynamicMod.java    From TickDynamic with MIT License 4 votes vote down vote up
@SubscribeEvent(priority=EventPriority.HIGHEST)
public void tickEventStart(ServerTickEvent event) {
	if(event.phase == Phase.START)
	{
		if(!versionCheckDone)
		{
			VersionChecker.VersionData versionData = versionChecker.getVersionData();
			if(versionData != null)
			{
				versionCheckDone = true;
				if(versionData.checkOk)
				{
 				//TODO: Parse versions, split at ',', then split version numbers at '.'
 				System.out.println("TickDynamic version check: Latest version = " + versionData.modVersion + ". Download URL: http://" + versionData.updateUrl);
				}
				else
					System.out.println("TickDynamic version check: Error while checking latest version!");
			}
		}
		
		TimedGroup externalGroup = getTimedGroup("external");
		externalGroup.endTimer();
		
		//Set the correct externalGroup time
		long msPerTick = 50;
		long overTime = externalGroup.getTimeUsed() - (msPerTick*externalGroup.timeMilisecond); //overTime = time used above given tick time
		long overTimeTick = (msPerTick*externalGroup.timeMilisecond) - (root.getTimeUsed() - externalGroup.getTimeUsed());
		if(overTimeTick < 0)
			overTime += overTimeTick;
		/*System.out.println("TickTime: " + ((root.getTimeUsed()-externalGroup.getTimeUsed())/(double)externalGroup.timeMilisecond) + 
				" Full Tick time: " + (externalGroup.getTimeUsed()/(double)externalGroup.timeMilisecond) +
				" External time used: " + (overTime/(double)externalGroup.timeMilisecond)+"ms");*/
		if(overTime < 0)
			externalGroup.setTimeUsed(0);
		else
			externalGroup.setTimeUsed(overTime);
		
		externalGroup.startTimer();
		
		
     //Clear any values from the previous tick for all worlds.
		root.newTick(true);
		
		getTimedGroup("other").startTimer();
	}
}
 
Example 19
Source File: EventHandlerGolem.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void on(PlaySoundAtEntityEvent event) {
    if(!event.entity.worldObj.isRemote && event.entity instanceof EntityGolemBase
            && event.name.equals("thaumcraft:zap") && event.volume == 0.5F && event.pitch == 1.0F) {
        EntityGolemBase golem = (EntityGolemBase) event.entity;
        if(markedGolems.containsKey(golem)) {
            EntityPlayer player = markedGolems.get(golem);
            markedGolems.remove(golem);

            AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(golem);

            boolean movedPlacer = false;
            boolean movedCore = core == null || !player.isSneaking();

            for(EntityItem entityItem : golem.capturedDrops) {
                ItemStack item = entityItem.getEntityItem();

                if(!movedCore && item.getItem() == ConfigItems.itemGolemCore) {
                    entityItem.setEntityItemStack(core.getItem());
                }

                if(!movedPlacer && item.getItem() instanceof ItemGolemPlacer
                        || item.getItem() instanceof ItemAdditionalGolemPlacer) {
                    //move persistent data to item
                    NBTTagCompound persistent = (NBTTagCompound) NBTHelper.getPersistentData(golem).copy();
                    if(player.isSneaking()) {
                        persistent.removeTag("Core");
                    }
                    NBTHelper.getData(item).setTag(Gadomancy.MODID, persistent);
                    event.entity.setDead();
                    entityItem.setEntityItemStack(item);

                    MinecraftForge.EVENT_BUS.post(new GolemDropPlacerEvent(player, entityItem, golem));

                    movedPlacer = true;
                }
                event.entity.worldObj.spawnEntityInWorld(entityItem);
            }
            golem.capturedDrops.clear();
            golem.captureDrops = false;
        }
    }
}