Java Code Examples for net.minecraftforge.fml.common.eventhandler.EventPriority#HIGHEST

The following examples show how to use net.minecraftforge.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: ItemCyberheart.java    From Cyberware with MIT License 6 votes vote down vote up
@SubscribeEvent(priority=EventPriority.HIGHEST)
public void power(CyberwareUpdateEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	ItemStack test = new ItemStack(this);
	if (e.ticksExisted % 20 == 0 && CyberwareAPI.isCyberwareInstalled(e, test))
	{
		if (!CyberwareAPI.getCapability(e).usePower(test, getPowerConsumption(test)))
		{
			e.attackEntityFrom(EssentialsMissingHandler.heartless, Integer.MAX_VALUE);
		}
	}
	
	if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(this)))
	{
		e.removePotionEffect(MobEffects.WEAKNESS);
	}
}
 
Example 2
Source File: EventsCommon.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onWorldUnload(WorldEvent.Unload event) {
    if (!event.getWorld().isRemote) {
        ValkyrienSkiesMod.VS_CHUNK_MANAGER.removeWorld(event.getWorld());
    } else {
        // Fixes memory leak; @DaPorkChop please don't leave static maps lying around D:
        lastPositions.clear();
    }
    ValkyrienSkiesMod.VS_PHYSICS_MANAGER.removeWorld(event.getWorld());
    IHasShipManager shipManager = (IHasShipManager) event.getWorld();
    shipManager.getManager().onWorldUnload();
}
 
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.getEntity();
    if (!(entity instanceof EntityPlayerMP)) {
        return;
    }
    EntityPlayerMP player = (EntityPlayerMP) entity;
    if (player.world.isRemote) {
        return;
    }
}
 
Example 4
Source File: EventsCommon.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerInteractEvent(PlayerInteractEvent event) {
    BlockPos pos = event.getPos();

    Optional<PhysicsObject> physicsObject = ValkyrienUtils
        .getPhysicsObject(event.getWorld(), pos);
    if (physicsObject.isPresent()) {
        event.setResult(Result.ALLOW);
    }
}
 
Example 5
Source File: EventsCommon.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onWorldLoad(WorldEvent.Load event) {
    World world = event.getWorld();
    event.getWorld().addEventListener(new VSWorldEventListener(world));
    IHasShipManager shipManager = (IHasShipManager) world;
    if (!event.getWorld().isRemote) {
        ValkyrienSkiesMod.VS_CHUNK_MANAGER.initWorld(world);
        shipManager.setManager(WorldServerShipManager::new);
    } else {
        shipManager.setManager(WorldClientShipManager::new);
    }
}
 
Example 6
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.getEntity();
    if (!(entity instanceof EntityPlayerMP)) {
        return;
    }
    EntityPlayerMP player = (EntityPlayerMP) entity;
    if (player.world.isRemote) {
        return;
    }
}
 
Example 7
Source File: PotionTimeSlow.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void entityPreUpdate(EntityUpdateEvent event) {
	Entity entity = event.getEntity();
	float scale = timeScale(entity);

	if (!entity.hasNoGravity() && scale > 0) {
		double gravity = entity instanceof EntityLivingBase ? -0.08 : -0.04;

		entity.motionY -= gravity * (1 - scale);
	}
}
 
Example 8
Source File: ServerEventHandler.java    From HoloInventory with MIT License 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onRightClick(PlayerInteractEvent.RightClickBlock event)
{
    if (catchNext == Type.NONE) return;
    boolean ban = catchNext == Type.BAN;
    catchNext = Type.NONE;
    event.setCanceled(true);

    TileEntity te = event.getWorld().getTileEntity(event.getPos());

    if (te == null)
    {
        event.getEntityPlayer().sendMessage(new TextComponentString("That block does not have a TileEntity.").setStyle(new Style().setColor(TextFormatting.RED)));
        return;
    }

    if (ban)
    {
        if (Helper.banned.add(te.getClass().getCanonicalName()))
            event.getEntityPlayer().sendMessage(new TextComponentString("Banned " + te.getClass().getCanonicalName()).setStyle(new Style().setColor(TextFormatting.GREEN)));
        else
            event.getEntityPlayer().sendMessage(new TextComponentString(te.getClass().getCanonicalName() + " is already banned.").setStyle(new Style().setColor(TextFormatting.RED)));
    }
    else
    {
        boolean wasBanned = Helper.banned.remove(te.getClass().getCanonicalName());
        if (wasBanned)
            event.getEntityPlayer().sendMessage(new TextComponentString("Unbanned " + te.getClass().getCanonicalName()).setStyle(new Style().setColor(TextFormatting.GREEN)));
        else
            event.getEntityPlayer().sendMessage(new TextComponentString(te.getClass().getCanonicalName() + " is not banned. Perhaps it is banned on the " + (FMLCommonHandler.instance().getSide().isClient() ? "server" : "client") + "?").setStyle(new Style().setColor(TextFormatting.RED)));
    }

    HoloInventory.getInstance().saveBanned();
}
 
Example 9
Source File: AutoMine.java    From ForgeHax with MIT License 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onGuiOpened(GuiOpenEvent event) {
  // process keys and mouse input even if this gui is open
  if (getWorld() != null && getLocalPlayer() != null && event.getGui() != null) {
    event.getGui().allowUserInput = true;
  }
}
 
Example 10
Source File: PlayerInteractEventHandler.java    From AgriCraft with MIT License 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void waterPadCreation(PlayerInteractEvent.RightClickBlock event) {
    // Fetch held item.
    final ItemStack stack = event.getItemStack();

    // Check if holding shovel.
    if (!StackHelper.isValid(stack, ItemSpade.class)) {
        return;
    }

    // Fetch world information.
    final BlockPos pos = event.getPos();
    final World world = event.getWorld();
    final IBlockState state = world.getBlockState(pos);

    // Fetch the block at the location.
    final Block block = state.getBlock();

    // Test that clicked block was farmland.
    if (block != Blocks.FARMLAND) {
        return;
    }

    // Deny the event.
    event.setUseBlock(Event.Result.DENY);
    event.setUseItem(Event.Result.DENY);
    event.setResult(Event.Result.DENY);

    // If we are on the client side we are done.
    if (event.getSide().isClient()) {
        return;
    }

    // Fetch the player.
    final EntityPlayer player = event.getEntityPlayer();

    // Create the new block on the server side.
    world.setBlockState(pos, AgriBlocks.getInstance().WATER_PAD.getDefaultState(), 3);

    // Damage player's tool if not in creative.
    if (!player.capabilities.isCreativeMode) {
        stack.damageItem(1, player);
    }
}
 
Example 11
Source File: EventsCommon.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onBlockBreakFirst(BlockEvent event) {
    BlockPos pos = event.getPos();
    Chunk chunk = event.getWorld()
        .getChunk(pos);
    IPhysicsChunk physicsChunk = (IPhysicsChunk) chunk;
    if (physicsChunk.getPhysicsObjectOptional()
        .isPresent()) {
        event.setResult(Result.ALLOW);
    }
}
 
Example 12
Source File: GrassDropHandler.java    From AgriCraft with MIT License 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void interceptGrassDrop(BlockEvent.HarvestDropsEvent event) {

    // Skip silk touch.
    if (event.isSilkTouching()) {
        return;
    }

    // Fetch the blockstate.
    final IBlockState state = event.getState();

    // Skip Air or Error
    if (state == null || state.getBlock() == null) {
        return;
    }

    // Fetch the world random.
    final Random rand = event.getWorld().rand;

    // Log
    // This line was oddly ignoring the debug settings...
    //AgriCore.getLogger("agricraft").debug("Intercepted! Block: {0}", state.getBlock());
    // Add grass drops if grass block.
    if (state.getBlock() instanceof BlockTallGrass) {
        // Wipe other drops, if needed.
        if (AgriCraftConfig.wipeGrassDrops) {
            event.getDrops().clear();
        }
        // Log
        // Commenented out to prevent spam.
        //AgriCore.getLogger("agricraft").debug("Inserting Drops!");
        // Add the drops.
        addGrassDrops(event.getDrops(), rand);
    }
}
 
Example 13
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.getEntity();
    if (!(entity instanceof EntityPlayerMP)) {
        return;
    }
    EntityPlayerMP player = (EntityPlayerMP) entity;
    if (player.worldObj.isRemote) {
        return;
    }
}
 
Example 14
Source File: ModGenuinePeoplePersonalities.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onItemActivated(PlayerInteractEvent.RightClickItem event) {
    EventData data = new EventData(event);
    if (data.getPlayer() == null || data.getPlayer().world.isRemote) return;
    if (!testCooldown(data.getPlayer())) return;
    if (generateComplaint(StringType.ACTIVATE, data.getPlayer(), event.getItemStack(), data)) {
        resetCooldown(data.getPlayer());
    }
}
 
Example 15
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.getEntity();
    if (!(entity instanceof EntityPlayerMP)) {
        return;
    }
    EntityPlayerMP player = (EntityPlayerMP) entity;
    if (player.worldObj.isRemote) {
        return;
    }
}
 
Example 16
Source File: PotionTimeSlow.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onAttack(PlayerInteractEvent.LeftClickEmpty e) {
	if(timeScale(e.getEntityPlayer()) == 0) {
		e.setResult(Event.Result.DENY);
	}
}
 
Example 17
Source File: PotionTimeSlow.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onSpell(SpellCastEvent e) {
	if(timeScale(e.getSpellData().getCaster(e.getWorld())) == 0) {
		e.setSpellData(new SpellData());
	}
}
 
Example 18
Source File: PotionTimeSlow.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onItemTickUse(LivingEntityUseItemEvent.Tick.Start event) {
	stopEvent(event);
}
 
Example 19
Source File: PlayerInteractEventHandler.java    From AgriCraft with MIT License 4 votes vote down vote up
/**
 * Event handler to disable vanilla farming.
 * 
 * @param event
 */
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void vanillaSeedPlanting(PlayerInteractEvent.RightClickBlock event) {
    // If not disabled, don't bother.
    if (!AgriCraftConfig.disableVanillaFarming) {
        return;
    }

    // Fetch the event itemstack.
    final ItemStack stack = event.getItemStack();

    // If the stack is null, or otherwise invalid, who cares?
    if (!StackHelper.isValid(stack)) {
        return;
    }

    // If the item in the player's hand is not a seed, who cares?
    if (!AgriApi.getSeedRegistry().hasAdapter(stack)) {
        return;
    }

    // Fetch world information.
    final BlockPos pos = event.getPos();
    final World world = event.getWorld();
    final IBlockState state = world.getBlockState(pos);

    // Fetch the block at the location.
    final Block block = state.getBlock();

    // If clicking crop block, who cares?
    if (block instanceof IAgriCrop) {
        return;
    }

    // If the item is an instance of IPlantable we need to perfom an extra check.
    if (stack.getItem() instanceof IPlantable) {
        // If the clicked block cannot support the given plant, then who cares?
        if (!block.canSustainPlant(state, world, pos, EnumFacing.UP, (IPlantable) stack.getItem())) {
            return;
        }
    }

    // If clicking crop tile, who cares?
    if (WorldHelper.getTile(event.getWorld(), event.getPos(), IAgriCrop.class).isPresent()) {
        return;
    }

    // The player is attempting to plant a seed, which is simply unacceptable.
    // We must deny this event.
    event.setUseItem(Event.Result.DENY);

    // If we are on the client side we are done.
    if (event.getSide().isClient()) {
        return;
    }

    // Should the server notify the player that vanilla farming has been disabled?
    if (AgriCraftConfig.showDisabledVanillaFarmingWarning) {
        MessageUtil.messagePlayer(event.getEntityPlayer(), "`7Vanilla planting is disabled!`r");
    }
}
 
Example 20
Source File: EventsCommon.java    From Valkyrien-Skies with Apache License 2.0 3 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onExplosionStart(ExplosionEvent.Start event) {
    // Only run on server side
    if (!event.getWorld().isRemote) {
        Explosion explosion = event.getExplosion();
        Vector center = new Vector(explosion.x, explosion.y, explosion.z);
        Optional<PhysicsObject> optionalPhysicsObject = ValkyrienUtils
            .getPhysicsObject(event.getWorld(),
                new BlockPos(event.getExplosion().getPosition()), true);
        if (optionalPhysicsObject.isPresent()) {
            return;
        }
        // Explosion radius
        float radius = explosion.size;
        AxisAlignedBB toCheck = new AxisAlignedBB(center.X - radius, center.Y - radius,
            center.Z - radius,
            center.X + radius, center.Y + radius, center.Z + radius);
        // Find nearby ships, we will check if the explosion effects them
        List<PhysicsWrapperEntity> shipsNear = ValkyrienSkiesMod.VS_PHYSICS_MANAGER
            .getManagerForWorld(event.getWorld())
            .getNearbyPhysObjects(toCheck);
        // Process the explosion on the nearby ships
        for (PhysicsWrapperEntity ship : shipsNear) {
            Vector inLocal = new Vector(center);

            ship.getPhysicsObject().getShipTransformationManager().getCurrentTickTransform()
                .transform(inLocal, TransformType.GLOBAL_TO_SUBSPACE);

            Explosion expl = new Explosion(event.getWorld(), null, inLocal.X, inLocal.Y,
                inLocal.Z, radius, explosion.causesFire, true);

            double waterRange = .6D;

            for (int x = (int) Math.floor(expl.x - waterRange);
                x <= Math.ceil(expl.x + waterRange); x++) {
                for (int y = (int) Math.floor(expl.y - waterRange);
                    y <= Math.ceil(expl.y + waterRange); y++) {
                    for (int z = (int) Math.floor(expl.z - waterRange);
                        z <= Math.ceil(expl.z + waterRange); z++) {
                        IBlockState state = event.getWorld()
                            .getBlockState(new BlockPos(x, y, z));
                        if (state.getBlock() instanceof BlockLiquid) {
                            return;
                        }
                    }
                }
            }

            expl.doExplosionA();
            event.getExplosion().affectedBlockPositions.addAll(expl.affectedBlockPositions);
        }
    }
}