cpw.mods.fml.common.eventhandler.Event Java Examples

The following examples show how to use cpw.mods.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: MinetweakerFurnaceFix.java    From NewHorizonsCoreMod with GNU General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void onFuelBurnTime(FuelBurnTimeEvent event) {
    /*
        Minetweaker's feature to change fuel burn values is implemented through an `IFuelHandler` which is
        forcibly registered with GameRegistry as the only fuel handler. However, the vanilla Furnace code
        always checks a small hardcoded list of fuels (including a check for `material == WOOD`) before calling
        the `IFuelHandler`.

        Before checking the hardcoded list, the Furnace is patched by Forge to obey any result returned by a
        `FuelBurnTimeEvent`, allowing the event handler to override the vanilla handling.

        This event handler simply delegates the fuel value to Minetweaker's `IFuelHandler`, which will be the only
        fuel handler registered, by simply calling `GameRegistry.getFuelValue`. In turn, this fuel handler will
        delegate to this mod's `CustomFuelsHandler` if no MT script changes the fuel value for the item.
     */
    int burnTime = GameRegistry.getFuelValue(event.fuel);
    if (burnTime > 0) {
        event.burnTime = burnTime;
        event.setResult(Event.Result.ALLOW);
    }
}
 
Example #2
Source File: TileEntityUniversalSensor.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
public void onEvent(Event event){
    ISensorSetting sensor = SensorHandler.instance().getSensorFromPath(sensorSetting);
    if(sensor != null && sensor instanceof IEventSensorSetting && getPressure(ForgeDirection.UNKNOWN) > PneumaticValues.MIN_PRESSURE_UNIVERSAL_SENSOR) {
        int newRedstoneStrength = ((IEventSensorSetting)sensor).emitRedstoneOnEvent(event, this, getRange(), sensorGuiText);
        if(newRedstoneStrength != 0) eventTimer = ((IEventSensorSetting)sensor).getRedstonePulseLength();
        if(invertedRedstone) newRedstoneStrength = 15 - newRedstoneStrength;
        if(eventTimer > 0 && ThirdPartyManager.computerCraftLoaded) {
            if(event instanceof PlayerInteractEvent) {
                PlayerInteractEvent e = (PlayerInteractEvent)event;
                notifyComputers(newRedstoneStrength, e.x, e.y, e.z);
            } else {
                notifyComputers(newRedstoneStrength);
            }
        }
        if(newRedstoneStrength != redstoneStrength) {
            redstoneStrength = newRedstoneStrength;
            updateNeighbours();
        }
    }
}
 
Example #3
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 #4
Source File: ItemCompost.java    From GardenCollection with MIT License 6 votes vote down vote up
public boolean applyEnrichment (ItemStack itemStack, World world, int x, int y, int z, EntityPlayer player) {
    ConfigManager config = GardenCore.config;
    Block block = world.getBlock(x, y, z);

    EnrichedSoilEvent event = new EnrichedSoilEvent(player, world, block, x, y, z);
    if (MinecraftForge.EVENT_BUS.post(event))
        return false;

    if (!config.enableCompostBonemeal)
        return false;

    if (event.getResult() == Event.Result.ALLOW) {
        if (!world.isRemote)
            itemStack.stackSize--;
        return true;
    }

    int prob = (config.compostBonemealStrength == 0) ? 0 : (int)(1 / config.compostBonemealStrength);
    if (world.rand.nextInt(prob) == 0)
        return ItemDye.applyBonemeal(itemStack, world, x, y, z, player);
    else
        --itemStack.stackSize;

    return true;
}
 
Example #5
Source File: ForgeEventHandler.java    From GardenCollection with MIT License 6 votes vote down vote up
@SubscribeEvent
public void applyEnrichedSoil (EnrichedSoilEvent event) {
    if (!GardenTrees.config.compostGrowsOrnamentalTrees)
        return;

    Item sapling = Item.getItemFromBlock(event.block);
    int saplingMeta = event.world.getBlockMetadata(event.x, event.y, event.z);
    if (sapling == null)
        return;

    WorldGenerator generator = (WorldGenerator) SaplingRegistry.instance().getExtendedData(sapling, saplingMeta, "sm_generator");
    if (generator == null)
        return;

    event.world.setBlockToAir(event.x, event.y, event.z);

    if (generator.generate(event.world, event.world.rand, event.x, event.y, event.z)) {
        event.setResult(Event.Result.ALLOW);
        return;
    }

    event.world.setBlock(event.x, event.y, event.z, event.block, saplingMeta, 0);
}
 
Example #6
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 6 votes vote down vote up
public static void checkBlockInteraction(Resident res, BlockPos bp, PlayerInteractEvent.Action action, Event ev) {
    if(!ev.isCancelable()) {
        return;
    }

    World world = MinecraftServer.getServer().worldServerForDimension(bp.getDim());
    Block block = world.getBlock(bp.getX(), bp.getY(), bp.getZ());

    // Bypass for SellSign
    if (block instanceof BlockSign) {
        TileEntity te = world.getTileEntity(bp.getX(), bp.getY(), bp.getZ());
        if(te instanceof TileEntitySign && SellSign.SellSignType.instance.isTileValid((TileEntitySign) te)) {
            return;
        }
    }

    for(SegmentBlock segment : segmentsBlock.get(block.getClass())) {
        if(!segment.shouldInteract(res, bp, action)) {
            ev.setCanceled(true);
        }
    }
}
 
Example #7
Source File: EventHandlerUniversalSensor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
private void sendEventToSensors(World world, Event event){
    if(!world.isRemote) {
        for(TileEntity te : (List<TileEntity>)world.loadedTileEntityList) {
            if(te instanceof TileEntityUniversalSensor) {
                ((TileEntityUniversalSensor)te).onEvent(event);
            }
        }
    }
}
 
Example #8
Source File: BlockInteractSensor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int emitRedstoneOnEvent(Event event, TileEntity sensor, int range, Set<ChunkPosition> positions){
    if(event instanceof PlayerInteractEvent) {
        PlayerInteractEvent interactEvent = (PlayerInteractEvent)event;
        return positions.contains(new ChunkPosition(interactEvent.x, interactEvent.y, interactEvent.z)) ? 15 : 0;
    }
    return 0;
}
 
Example #9
Source File: PlayerEventSensor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int emitRedstoneOnEvent(Event event, TileEntity sensor, int range, String textboxText){
    if(event instanceof PlayerEvent) {
        EntityPlayer player = ((PlayerEvent)event).entityPlayer;
        if(Math.abs(player.posX - sensor.xCoord + 0.5D) < range + 0.5D && Math.abs(player.posY - sensor.yCoord + 0.5D) < range + 0.5D && Math.abs(player.posZ - sensor.zCoord + 0.5D) < range + 0.5D) {
            return emitRedstoneOnEvent((PlayerEvent)event, sensor, range);
        }
    }
    return 0;
}
 
Example #10
Source File: ForgeEventHandler.java    From GardenCollection with MIT License 5 votes vote down vote up
@SubscribeEvent
public void useHoe (UseHoeEvent event) {
    Block block = event.world.getBlock(event.x, event.y, event.z);
    if (block instanceof BlockGarden) {
        if (((BlockGarden) block).applyHoe(event.world, event.x, event.y, event.z))
            event.setResult(Event.Result.ALLOW);
    }
}
 
Example #11
Source File: ForgeEventHandler.java    From GardenCollection with MIT License 5 votes vote down vote up
@SubscribeEvent
public void applyBonemeal (BonemealEvent event) {
    if (event.block instanceof IPlantProxy) {
        IPlantProxy proxy = (IPlantProxy) event.block;
        if (proxy.applyBonemeal(event.world, event.x, event.y, event.z))
            event.setResult(Event.Result.ALLOW);
    }
}
 
Example #12
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public static void checkBreakWithItem(ItemStack stack, Resident res, BlockPos bp, Event ev) {
    if(!ev.isCancelable()) {
        return;
    }

    for(SegmentItem segment : segmentsItem.get(stack.getItem().getClass())) {
        if(!segment.shouldBreakBlock(stack, res, bp)) {
            ev.setCanceled(true);
        }
    }
}
 
Example #13
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public static void checkUsage(ItemStack stack, Resident res, PlayerInteractEvent.Action action, BlockPos bp, int face, Event ev) {
    if(!ev.isCancelable()) {
        return;
    }

    for(SegmentItem segment : segmentsItem.get(stack.getItem().getClass())) {
        if(!segment.shouldInteract(stack, res, action, bp, face)) {
            ev.setCanceled(true);
        }
    }
}
 
Example #14
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public static void checkPVP(Entity entity, Resident res, Event event) {
    if(!event.isCancelable()) {
        return;
    }

    for(SegmentEntity segment : segmentsEntity.get(entity.getClass())) {
        if(!segment.shouldAttack(entity, res)) {
            event.setCanceled(true);
        }
    }
}
 
Example #15
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public static void checkInteraction(Entity entity, Resident res, Event event) {
    if(!event.isCancelable()) {
        return;
    }

    for(SegmentEntity segment : segmentsEntity.get(entity.getClass())) {
        if(!segment.shouldInteract(entity, res)) {
            event.setCanceled(true);
        }
    }
}
 
Example #16
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public static void checkImpact(Entity entity, Resident owner, MovingObjectPosition mop, Event event) {
    for(SegmentEntity segment : segmentsEntity.get(entity.getClass())) {
        if(!segment.shouldImpact(entity, owner, mop)) {
            event.setCanceled(true);
            entity.isDead = true;
            entity.setDead();
        }
    }
}
 
Example #17
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@SubscribeEvent
public void checkSpawn(LivingSpawnEvent.CheckSpawn ev) {
    if (ev.getResult() == Event.Result.DENY) {
        return;
    }

    if(ProtectionManager.checkExist(ev.entity, true)) {
        ev.setResult(Event.Result.DENY);
    }
}
 
Example #18
Source File: PlayerEventSensor.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int emitRedstoneOnEvent(Event event, TileEntity sensor, int range, String textboxText){
    if(event instanceof PlayerEvent) {
        EntityPlayer player = ((PlayerEvent)event).entityPlayer;
        if(Math.abs(player.posX - sensor.xCoord + 0.5D) < range + 0.5D && Math.abs(player.posY - sensor.yCoord + 0.5D) < range + 0.5D && Math.abs(player.posZ - sensor.zCoord + 0.5D) < range + 0.5D) {
            return emitRedstoneOnEvent((PlayerEvent)event, sensor, range);
        }
    }
    return 0;
}
 
Example #19
Source File: EventHandlerEntity.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void on(LivingSpawnEvent.CheckSpawn event) {
    if(event.entityLiving.isCreatureType(EnumCreatureType.monster, false)) {
        double rangeSq = AuraEffects.LUX.getRange() * AuraEffects.LUX.getRange();
        Vector3 entityPos = MiscUtils.getPositionVector(event.entity);
        for(ChunkCoordinates luxPylons : registeredLuxPylons) {
            Vector3 pylon = Vector3.fromCC(luxPylons);
            if(entityPos.distanceSquared(pylon) <= rangeSq) {
                event.setResult(Event.Result.DENY);
                return;
            }
        }
    }
}
 
Example #20
Source File: ForgeEventHandler.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void playerInteractEvent(PlayerInteractEvent event) {
	nova.core.event.PlayerEvent.Interact evt = new nova.core.event.PlayerEvent.Interact(
		WorldConverter.instance().toNova(event.world),
		new Vector3D(event.x, event.y, event.z),
		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 #21
Source File: ItemTrowel.java    From GardenCollection with MIT License 4 votes vote down vote up
@Override
public boolean onItemUse (ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    if (!player.canPlayerEdit(x, y, z, side, itemStack))
        return false;

    UseTrowelEvent event = new UseTrowelEvent(player, itemStack, world, x, y, z);
    if (MinecraftForge.EVENT_BUS.post(event))
        return false;

    if (event.getResult() == Event.Result.ALLOW) {
        itemStack.damageItem(1, player);
        return true;
    }

    if (side == 0)
        return false;

    Block block = world.getBlock(x, y, z);

    if (block instanceof BlockGarden) {
        player.openGui(GardenCore.instance, GuiHandler.gardenLayoutGuiID, world, x, y, z);
        return true;
    }
    else if (block instanceof IPlantProxy) {
        IPlantProxy proxy = (IPlantProxy) block;
        TileEntityGarden te = proxy.getGardenEntity(world, x, y, z);

        if (te != null) {
            player.openGui(GardenCore.instance, GuiHandler.gardenLayoutGuiID, world, te.xCoord, te.yCoord, te.zCoord);
            return true;
        }
    }

    /*if (world.getBlock(x, y + 1, z).isAir(world, x, y + 1, z) && (block == Blocks.grass || block == Blocks.dirt)) {
        Block.SoundType stepSound = ModBlocks.gardenSoil.stepSound;
        world.playSoundEffect( + .5f, y + .5f, z + .5f, stepSound.getStepResourcePath(), (stepSound.getVolume() + .5f) / 2, stepSound.getPitch() * .8f);

        if (!world.isRemote) {
            world.setBlock(x, y, z, ModBlocks.gardenSoil);
            itemStack.damageItem(1, player);
        }

        return true;
    }*/

    return false;
}
 
Example #22
Source File: SensorHandler.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int emitRedstoneOnEvent(Event event, TileEntity tile, int sensorRange, String textboxText){
    TileEntityUniversalSensor teUs = (TileEntityUniversalSensor)tile;
    Set<ChunkPosition> positions = teUs.getGPSPositions();
    return positions == null ? 0 : coordinateSensor.emitRedstoneOnEvent(event, teUs, sensorRange, positions);
}
 
Example #23
Source File: IEventSensorSetting.java    From Framez with GNU General Public License v3.0 2 votes vote down vote up
/**
 * This method is only invoked when a subscribed event is triggered.
 * @param event
 * @param sensor
 * @param range
 * @param textboxText
 * @return Redstone strength for the given event.
 */
public int emitRedstoneOnEvent(Event event, TileEntity sensor, int range, String textboxText);
 
Example #24
Source File: IBlockAndCoordinateEventSensor.java    From PneumaticCraft with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Extended version of the normal emitRedstoneOnEvent. This method will only invoke with a valid GPS tool, and when all the coordinates are within range.
 * @param event
 * @param sensor
 * @param range
 * @param positions When only one GPS Tool is inserted this contains the position of just that tool. If two GPS Tools are inserted, These are both corners of a box, and every coordinate in this box is added to the positions argument.
 * @return
 */
public int emitRedstoneOnEvent(Event event, TileEntity sensor, int range, Set<ChunkPosition> positions);
 
Example #25
Source File: IEventSensorSetting.java    From PneumaticCraft with GNU General Public License v3.0 2 votes vote down vote up
/**
 * This method is only invoked when a subscribed event is triggered.
 * @param event
 * @param sensor
 * @param range
 * @param textboxText
 * @return Redstone strength for the given event.
 */
public int emitRedstoneOnEvent(Event event, TileEntity sensor, int range, String textboxText);
 
Example #26
Source File: IBlockAndCoordinateEventSensor.java    From Framez with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Extended version of the normal emitRedstoneOnEvent. This method will only invoke with a valid GPS tool, and when the coordinate is within range.
 * @param event
 * @param sensor
 * @param range
 * @param toolX
 * @param toolY
 * @param toolZ
 * @return
 */
public int emitRedstoneOnEvent(Event event, TileEntity sensor, int range, int toolX, int toolY, int toolZ);