net.minecraftforge.fml.common.eventhandler.Event Java Examples

The following examples show how to use net.minecraftforge.fml.common.eventhandler.Event. 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: GTEventOnLivingFall.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void onEntityFall(LivingFallEvent event) {
	if (event.getEntityLiving() instanceof EntityPlayer) {
		EntityPlayer player = (EntityPlayer) event.getEntityLiving();
		for (ItemStack armor : player.getEquipmentAndArmor()) {
			if (armor.getItem() instanceof GTItemSpringBoots) {
				float amount = event.getDistance();
				if (amount < 20) {
					event.setResult(Event.Result.DENY);
					event.setCanceled(true);
				} else {
					armor.damageItem(Math.round(amount), player);
					event.setDamageMultiplier(event.getDamageMultiplier() * 0.5F);
					player.jump();
					event.getEntity().playSound(GTSounds.SPRING, 1.0F, 1.0F
							+ player.getEntityWorld().rand.nextFloat());
				}
			}
		}
	}
}
 
Example #2
Source File: EventUtil.java    From VanillaFix with MIT License 6 votes vote down vote up
public static void postEventAllowingErrors(Event event) {
    int busID;
    try {
        Field busIDField = EventBus.class.getDeclaredField("busID");
        busIDField.setAccessible(true);
        busID = busIDField.getInt(MinecraftForge.EVENT_BUS);
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }

    IEventListener[] listeners = event.getListenerList().getListeners(busID);
    for (IEventListener listener : listeners) {
        try {
            listener.invoke(event);
        } catch (Throwable t) {
            LOGGER.error(event + " listener '" + listener + "' threw exception, models may be broken", t);
        }
    }
}
 
Example #3
Source File: ForgeEventHandler.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void playerInteractEvent(PlayerInteractEvent event) {
	if (event.world != null && event.pos != null) {
		nova.core.event.PlayerEvent.Interact evt = new nova.core.event.PlayerEvent.Interact(
			WorldConverter.instance().toNova(event.world),
			VectorConverter.instance().toNova(event.pos),
			EntityConverter.instance().toNova(event.entityPlayer),
			nova.core.event.PlayerEvent.Interact.Action.values()[event.action.ordinal()]
		);

		Game.events().publish(evt);

		event.useBlock = Event.Result.values()[evt.useBlock.ordinal()];
		event.useItem = Event.Result.values()[evt.useItem.ordinal()];
		event.setCanceled(evt.isCanceled());
	}
}
 
Example #4
Source File: ForgeEventHandler.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void playerInteractEvent(PlayerInteractEvent event) {
	if (event.getWorld() != null) {
		nova.core.event.PlayerEvent.Interact evt = new nova.core.event.PlayerEvent.Interact(
			WorldConverter.instance().toNova(event.getWorld()),
			VectorConverter.instance().toNova(event.getPos()),
			EntityConverter.instance().toNova(event.getEntityPlayer()),
			nova.core.event.PlayerEvent.Interact.Action.values()[toNovaInteractOrdinal(event)]
		);

		Game.events().publish(evt);

		if (event instanceof RightClickBlock) {
			((RightClickBlock)event).setUseBlock(Event.Result.values()[evt.useBlock.ordinal()]);
			((RightClickBlock)event).setUseItem(Event.Result.values()[evt.useItem.ordinal()]);
		} else if (event instanceof LeftClickBlock) {
			((LeftClickBlock)event).setUseBlock(Event.Result.values()[evt.useBlock.ordinal()]);
			((LeftClickBlock)event).setUseItem(Event.Result.values()[evt.useItem.ordinal()]);
		}
		if (event.isCancelable()) event.setCanceled(evt.isCanceled());
	}
}
 
Example #5
Source File: AbsoluteMovementCommandsImplementation.java    From malmo with MIT License 6 votes vote down vote up
private void sendChanges()
{
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    if (player == null)
        return;

    // Send any changes requested over the wire to the server:
    double x = this.setX ? this.x : 0;
    double y = this.setY ? this.y : 0;
    double z = this.setZ ? this.z : 0;
    float yaw = this.setYaw ? this.rotationYaw : 0;
    float pitch = this.setPitch ? this.rotationPitch : 0;

    if (this.setX || this.setY || this.setZ || this.setYaw || this.setPitch)
    {
        MalmoMod.network.sendToServer(new TeleportMessage(x, y, z, yaw, pitch, this.setX, this.setY, this.setZ, this.setYaw, this.setPitch));
        if (this.setYaw || this.setPitch)
        {
            // Send a message that the ContinuousMovementCommands can pick up on:
            Event event = new CommandForWheeledRobotNavigationImplementation.ResetPitchAndYawEvent(this.setYaw, this.rotationYaw, this.setPitch, this.rotationPitch);
            MinecraftForge.EVENT_BUS.post(event);
        }
        this.setX = this.setY = this.setZ = this.setYaw = this.setPitch = false;
    }
}
 
Example #6
Source File: EventHandler.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public static void canCreateFluidSource(BlockEvent.CreateFluidSourceEvent event)
{
    if (event.getResult() != Event.Result.DEFAULT)
        return;

    if (applyModifiers(event))
        return;

    Block block = event.getState().getBlock();

    if (block instanceof CSBlock)
    {
        ContentBlockBase content = ((CSBlock) block).getContent();
        if (content instanceof ContentBlockFluid)
        {
            ContentBlockFluid fluid = (ContentBlockFluid) content;
            event.setResult(fluid.canCreateSource ? Event.Result.ALLOW : Event.Result.DENY);
        }
    }
}
 
Example #7
Source File: EventHandler.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
private static boolean applyModifiers(BlockEvent.CreateFluidSourceEvent event)
{
    Block block = event.getState().getBlock();

    for (FluidModifier modifier : FluidModifier.getModifiers())
    {
        if (block.getRegistryName() != null && block.getRegistryName().equals(modifier.block))
        {
            if (modifier.canCreateSource != null)
            {
                event.setResult(modifier.canCreateSource ? Event.Result.ALLOW : Event.Result.DENY);
                return true;
            }
        }
    }

    return false;
}
 
Example #8
Source File: PlayerInteractEventHandler.java    From AgriCraft with MIT License 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void denyBonemeal(PlayerInteractEvent.RightClickBlock event) {
    if (!event.getEntityPlayer().isSneaking()) {
        return;
    }
    ItemStack heldItem = event.getEntityPlayer().getActiveItemStack();
    if (!heldItem.isEmpty() && heldItem.getItem() == Items.DYE && heldItem.getItemDamage() == 15) {
        TileEntity te = event.getWorld().getTileEntity(event.getPos());
        if (te != null && (te instanceof TileEntityCrop)) {
            event.setUseItem(Event.Result.DENY);
        }
    }
}
 
Example #9
Source File: TraverseWorld.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public static void replaceVillageBlocks(BiomeEvent.GetVillageBlockID event) {
    if (villageReplacementBiomes.keySet().contains(event.getBiome())) {
        event.setReplacement(villageReplacementBiomes.get(event.getBiome()).getBiomeSpecificState(event.getOriginal()));
        event.setResult(Event.Result.DENY);
    }
}
 
Example #10
Source File: PlayerInteractEventHandler.java    From AgriCraft with MIT License 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void applyVinesToGrate(PlayerInteractEvent.RightClickBlock event) {
    // Fetch the ItemStack
    final ItemStack stack = event.getItemStack();

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

    // If the player is not holding a stack of vines, who cares?
    if (stack.getItem() != Item.getItemFromBlock(Blocks.VINE)) {
        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 the player isn't clicking a grate, who cares?
    if (!(block instanceof BlockGrate)) {
        return;
    }

    // The player is trying to place vines! Scandalous!
    // We better deny the event!
    event.setUseItem(Event.Result.DENY);
}
 
Example #11
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 #12
Source File: PLEvent.java    From Production-Line with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onBucketFill(FillBucketEvent event) {
    if (event.getEntityPlayer() != null) {
        Biome biome = event.getWorld().getBiomeForCoordsBody(event.getTarget().getBlockPos());
        if (biome == Biomes.OCEAN || biome == Biomes.DEEP_OCEAN || biome == Biomes.FROZEN_OCEAN) {
            event.setResult(Event.Result.ALLOW);
            event.setFilledBucket(new ItemStack(PLItems.saltWaterBucket));
        }
    }
}
 
Example #13
Source File: EssentialsMissingHandler.java    From Cyberware with MIT License 5 votes vote down vote up
private void processEvent(Event event, EnumHand hand, EntityPlayer p, ICyberwareUserData cyberware)
{
	EnumHandSide mainHand = p.getPrimaryHand();
	EnumHandSide offHand = ((mainHand == EnumHandSide.LEFT) ? EnumHandSide.RIGHT : EnumHandSide.LEFT);
	EnumSide correspondingMainHand = ((mainHand == EnumHandSide.RIGHT) ? EnumSide.RIGHT : EnumSide.LEFT);
	EnumSide correspondingOffHand = ((offHand == EnumHandSide.RIGHT) ? EnumSide.RIGHT : EnumSide.LEFT);
	
	boolean leftUnpowered = false;
	ItemStack armLeft = cyberware.getCyberware(new ItemStack(CyberwareContent.cyberlimbs, 1, 0));
	if (armLeft != null && !ItemCyberlimb.isPowered(armLeft))
	{
		leftUnpowered = true;
	}
	
	boolean rightUnpowered = false;
	ItemStack armRight = cyberware.getCyberware(new ItemStack(CyberwareContent.cyberlimbs, 1, 1));
	if (armRight != null && !ItemCyberlimb.isPowered(armRight))
	{
		rightUnpowered = true;
	}

	if (hand == EnumHand.MAIN_HAND && (!cyberware.hasEssential(EnumSlot.ARM, correspondingMainHand) || leftUnpowered))
	{
		event.setCanceled(true);
	}
	else if (hand == EnumHand.OFF_HAND && (!cyberware.hasEssential(EnumSlot.ARM, correspondingOffHand) || rightUnpowered))
	{
		event.setCanceled(true);
	}
}
 
Example #14
Source File: PotionTimeSlow.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void stopEvent(LivingEvent event) {
	PotionEffect effect = ModPotions.TIME_SLOW.getEffect(event.getEntityLiving());
	if (effect == null)
		return;
	if (timeScale(event.getEntity()) == 0) {
		event.setCanceled(true);
		event.setResult(Event.Result.DENY);
	}
}
 
Example #15
Source File: VanishTracker.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public static void interact(PlayerInteractEvent event) {
	if (isVanished(event.getEntityPlayer())) {
		event.setCancellationResult(EnumActionResult.FAIL);
		event.setResult(Event.Result.DENY);
	}
}
 
Example #16
Source File: LocalPlayerUpdateEventService.java    From ForgeHax with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onUpdate(LivingEvent.LivingUpdateEvent event) {
  if (getWorld() != null
      && event.getEntity().getEntityWorld().isRemote
      && event.getEntityLiving().equals(getLocalPlayer())) {
    Event ev = new LocalPlayerUpdateEvent(event.getEntityLiving());
    MinecraftForge.EVENT_BUS.post(ev);
    event.setCanceled(ev.isCanceled());
  }
}
 
Example #17
Source File: HookReporter.java    From ForgeHax with MIT License 5 votes vote down vote up
/**
 * Gets all Forge Events represented by this hook
 *
 * @return immutable list of forge events
 */
@SuppressWarnings("unchecked")
public List<Class<? extends Event>> getForgeEventClasses() {
  return eventClasses
    .stream()
    .filter(Event.class::isAssignableFrom)
    .map(clazz -> (Class<? extends Event>) clazz)
    .collect(Immutables.toImmutableList());
}
 
Example #18
Source File: TraverseWorld.java    From Traverse-Legacy-1-12-2 with MIT License 5 votes vote down vote up
@SubscribeEvent
public static void replaceVillageBlocks(BiomeEvent.GetVillageBlockID event) {
	if (villageReplacementBiomes.keySet().contains(event.getBiome())) {
		event.setReplacement(villageReplacementBiomes.get(event.getBiome()).getBiomeSpecificState(event.getOriginal()));
		event.setResult(Event.Result.DENY);
	}
}
 
Example #19
Source File: GTEventDecorateBiome.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onEvent(DecorateBiomeEvent.Decorate event) {
	if (GTConfig.general.reduceGrassOnWorldGen && event.getType() == DecorateBiomeEvent.Decorate.EventType.GRASS
			&& event.getRand().nextInt(11) != 0) {
		event.setResult(Event.Result.DENY);
	}
}
 
Example #20
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 #21
Source File: ForgeHaxHooks.java    From ForgeHax with MIT License 4 votes vote down vote up
public static boolean fireEvent_b(Event event) {
  return MinecraftForge.EVENT_BUS.post(event);
}
 
Example #22
Source File: ForgeHaxHooks.java    From ForgeHax with MIT License 4 votes vote down vote up
/**
 * Convenient functions for firing events
 */
public static void fireEvent_v(Event event) {
  MinecraftForge.EVENT_BUS.post(event);
}
 
Example #23
Source File: HookReporter.java    From ForgeHax with MIT License 4 votes vote down vote up
public Builder forgeEvent(Class<? extends Event> clazz) {
  eventClasses.add(clazz);
  return this;
}
 
Example #24
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 #25
Source File: GTEventCheckSpawn.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onSpawn(CheckSpawn event) {
	if (event.getResult() == Event.Result.ALLOW) {
		return;
	}
	if (event.getEntityLiving().isCreatureType(EnumCreatureType.MONSTER, false)) {
		Entity entity = event.getEntity();
		BlockPos spawn = entity.getEntityWorld().getSpawnPoint();
		// This is the code for the safe spawn zone
		if (GTConfig.general.preventMobSpawnsCloseToSpawn
				&& entity.getEntityWorld().provider.getDimensionType().equals(DimensionType.OVERWORLD)
				&& entity.getPosition().distanceSq(spawn.getX(), spawn.getY(), spawn.getZ()) <= 128 * 128) {
			event.setResult(Event.Result.DENY);
		}
		// this is code for zombies spawning with pickaxes
		if (GTConfig.general.caveZombiesSpawnWithPickaxe && entity instanceof EntityZombie && event.getY() <= 50.0F
				&& event.getWorld().rand.nextInt(2) == 0) {
			EntityZombie zombie = (EntityZombie) entity;
			ItemStack tool = getRandomPickaxe(event.getWorld().rand);
			int damage = event.getWorld().rand.nextInt(tool.getMaxDamage() + 1);
			tool.damageItem(GTHelperMath.clip(damage, 1, tool.getMaxDamage() - 1), zombie);
			zombie.setHeldItem(EnumHand.MAIN_HAND, tool);
		}
		// This is the code for the mob repellator
		for (int[] rep : mobReps) {
			World world = event.getEntity().getEntityWorld();
			if (rep[3] == world.provider.getDimension()) {
				TileEntity tile = world.getTileEntity(new BlockPos(rep[0], rep[1], rep[2]));
				if (tile instanceof GTTileMobRepeller) {
					int r = ((GTTileMobRepeller) tile).range;
					double dx = rep[0] + 0.5F - event.getEntity().posX;
					double dy = rep[1] + 0.5F - event.getEntity().posY;
					double dz = rep[2] + 0.5F - event.getEntity().posZ;
					if ((dx * dx + dz * dz + dy * dy) <= Math.pow(r, 2)) {
						event.setResult(Event.Result.DENY);
					}
				}
			}
		}
	}
}
 
Example #26
Source File: ModGenuinePeoplePersonalities.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Event getEvent() {
    return event;
}