Java 类net.minecraftforge.fml.common.eventhandler.Event 实例源码

项目:pnc-repressurized    文件:TileEntityUniversalSensor.java   
public void onEvent(Event event) {
    ISensorSetting sensor = SensorHandler.getInstance().getSensorFromPath(sensorSetting);
    if (sensor != null && sensor instanceof IEventSensorSetting && getPressure() > 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.getPos().getX(), e.getPos().getY(), e.getPos().getZ());
            } else {
                notifyComputers(newRedstoneStrength);
            }
        }
        if (newRedstoneStrength != redstoneStrength) {
            redstoneStrength = newRedstoneStrength;
            updateNeighbours();
        }
    }
}
项目:harshencastle    文件:HarshenUtils.java   
public static EntityPlayer getPlayer(Event event)
{
    if(event instanceof LivingEvent && ((LivingEvent)event).getEntity() instanceof EntityPlayer)
        return (EntityPlayer)((LivingEvent)event).getEntity();
    if(event instanceof RenderGameOverlayEvent || event instanceof RenderWorldLastEvent || event instanceof ClientTickEvent)
        return HarshenCastle.proxy.getPlayer();
    if(event instanceof PlayerTickEvent)
        return ((PlayerTickEvent)event).player;
    if(event instanceof PlayerEvent)
        return ((PlayerEvent)event).player;
    if(event instanceof net.minecraftforge.event.entity.player.PlayerEvent)
        return ((net.minecraftforge.event.entity.player.PlayerEvent)event).getEntityPlayer();
    if(event instanceof PlayerPunchedEvent)
        return ((PlayerPunchedEvent)event).attacker;
    if(event instanceof LivingDropsEvent && isSourceFromPlayer(((LivingDropsEvent)event).getSource()))
        return getPlayerFromSource(((LivingDropsEvent)event).getSource());
    return null;
}
项目:InControl    文件:ForgeEventHandlers.java   
@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++;
    }
}
项目:InControl    文件:ForgeEventHandlers.java   
@SubscribeEvent
public void onEntitySpawnEvent(LivingSpawnEvent.CheckSpawn event) {
    int i = 0;
    for (SpawnRule rule : RulesManager.rules) {
        if (rule.match(event)) {
            Event.Result result = rule.getResult();
            if (debug) {
                InControl.logger.log(Level.INFO, "Rule " + i + ": "+ result
                        + " entity: " + event.getEntity().getName()
                        + " y: " + event.getY()
                        + " biome: " + event.getWorld().getBiome(new BlockPos(event.getX(), event.getY(), event.getZ())).getBiomeName());
            }
            event.setResult(result);
            if (result != Event.Result.DENY) {
                rule.action(event);
            }
            return;
        }
        i++;
    }
}
项目:InControl    文件:ForgeEventHandlers.java   
@SubscribeEvent
public void onSummonAidEvent(ZombieEvent.SummonAidEvent event) {
    int i = 0;
    for (SummonAidRule rule : RulesManager.summonAidRules) {
        if (rule.match(event)) {
            Event.Result result = rule.getResult();
            if (debug) {
                InControl.logger.log(Level.INFO, "SummonAid " + i + ": "+ result
                        + " entity: " + event.getEntity().getName()
                        + " y: " + event.getY()
                        + " biome: " + event.getWorld().getBiome(new BlockPos(event.getX(), event.getY(), event.getZ())).getBiomeName());
            }
            event.setResult(result);
            if (result != Event.Result.DENY) {
                rule.action(event);
            }
            return;
        }
        i++;
    }

}
项目:Genesis    文件:GenesisEventHandler.java   
@SubscribeEvent
public static void onUseHoe(UseHoeEvent event) {
    EntityPlayer player = event.getEntityPlayer();
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();

    if (block == GenesisBlocks.HUMUS || block == GenesisBlocks.HUMUS_PATH) {
        world.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);

        if (!world.isRemote) {
            IBlockState farmland = GenesisBlocks.HUMUS_FARMLAND.getDefaultState();
            world.setBlockState(pos, farmland, WorldFlags.UPDATE_BLOCK_AND_CLIENT_AND_RERENDER_ON_MAIN);
        }

        event.setResult(Event.Result.ALLOW);
    }
}
项目:Proyecto-DASI    文件:AbsoluteMovementCommandsImplementation.java   
private void sendChanges()
{
    EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
    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;
    }
}
项目:Proyecto-DASI    文件:AbsoluteMovementCommandsImplementation.java   
private void sendChanges()
{
    EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
    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;
    }
}
项目:Adventurers-Toolbox    文件:HammerHandler.java   
@SubscribeEvent
public void onPlayerClickBlock(PlayerInteractEvent.RightClickBlock event) {

    if (event.getEntityPlayer() == null || !event.getEntityPlayer().isSneaking()) {
        return;
    }

    if (event.getItemStack().getItem() == ModItems.hammer && !event.getEntityPlayer().getCooldownTracker().hasCooldown(ModItems.hammer)) {

        if (!event.getWorld().isRemote) {
            BlockPos pos = event.getPos().offset(event.getFace());
            event.getWorld().createExplosion(event.getEntityPlayer(), pos.getX() + 0.5, pos.getY() + 0.5,
                    pos.getZ() + 0.5, 3, false);
        }

        event.getEntityPlayer().swingArm(event.getHand());
        event.getEntityPlayer().setActiveHand(event.getHand());
        event.getEntityPlayer().getCooldownTracker().setCooldown(ModItems.hammer, 200);
        ModItems.hammer.setDamage(event.getItemStack(), ModItems.hammer.getDamage(event.getItemStack()) - 10);

        event.setCancellationResult(EnumActionResult.SUCCESS);
        event.setResult(Event.Result.ALLOW);
        event.setCanceled(true);
    }

}
项目:refinedstorageaddons    文件:ItemNetworkBag.java   
public void onPlayerPickup(EntityItemPickupEvent e, ItemStack stack) {
    applyNetwork(stack, n -> {
        if (RSAddons.INSTANCE.config.networkBagUsesEnergy && stack.getItemDamage() != ItemNetworkBag.TYPE_CREATIVE && stack.getCapability(CapabilityEnergy.ENERGY, null).getEnergyStored() <= RSAddons.INSTANCE.config.networkBagUsage) {
            return;
        }

        if (!n.getSecurityManager().hasPermission(Permission.INSERT, e.getEntityPlayer())) {
            return;
        }

        if (n.insertItem(e.getItem().getItem(), e.getItem().getItem().getCount(), true) == null) {
            e.setResult(Event.Result.ALLOW);
            e.setCanceled(true);

            n.insertItem(e.getItem().getItem(), e.getItem().getItem().getCount(), false);

            e.getItem().setDead();

            if (RSAddons.INSTANCE.config.networkBagUsesEnergy && stack.getItemDamage() != ItemNetworkBag.TYPE_CREATIVE) {
                stack.getCapability(CapabilityEnergy.ENERGY, null).extractEnergy(RSAddons.INSTANCE.config.networkBagUsage, false);
            }
        }
    }, error -> {
        // NO OP
    });
}
项目:customstuff4    文件:EventHandler.java   
@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);
        }
    }
}
项目:customstuff4    文件:EventHandler.java   
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;
}
项目:ItsJustaCharm1.10.2Dead    文件:EventTintedTreeGenerator.java   
@SubscribeEvent(priority = EventPriority.LOWEST)
public void decorate(DecorateBiomeEvent.Decorate event) {
    World world = event.getWorld();
    Biome biome = world.getBiomeGenForCoords(event.getPos());
    Random rand = event.getRand();

    if ((biome == Biomes.PLAINS || biome == Biomes.ICE_PLAINS || biome == Biomes.MUTATED_PLAINS || biome == Biomes.EXTREME_HILLS_WITH_TREES || biome == Biomes.MUTATED_EXTREME_HILLS_WITH_TREES) && event.getType() == DecorateBiomeEvent.Decorate.EventType.TREE) {
        if (rand.nextDouble() > 0.1) return;
        int x = rand.nextInt(16) + 8;
        int y = rand.nextInt(16) + 8;

        TintedTreeGenerator gen = new TintedTreeGenerator();

        gen.generateTree(rand, world, world.getHeight(event.getPos().add(x, 0, y)));

        event.setResult(Event.Result.DENY);
    }
}
项目:InspiringWorld    文件:BlockSourceLight.java   
@SubscribeEvent
public void onCheckSpawn(LivingSpawnEvent.CheckSpawn event) {
    double distanceMin = Double.MAX_VALUE;

    for (int i = -31; i <= 32; ++i) {
        for (int j = -31; j <= 32; ++j) {
            for (int k = -31; k <= 32; ++k) {
                BlockPos pos = new BlockPos(event.getX() + i, event.getY() + j, event.getZ() + k);
                IBlockState state = event.getWorld().getBlockState(pos);
                if (state.getBlock() instanceof BlockSourceLight && state.getValue(IWTechBlocks.WORKING)) {
                    distanceMin = Math.min(distanceMin, MathHelper.sqrt_double(i * i + j * j + k * k));
                }
            }
        }
    }

    if (event.getWorld().rand.nextDouble() * 32.0D > distanceMin) {
        event.setResult(Event.Result.DENY);
    }
}
项目:malmo    文件:AbsoluteMovementCommandsImplementation.java   
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;
    }
}
项目:TorchMaster    文件:EventHandlerServer.java   
@SubscribeEvent
public void onEntityCheckSpawn(LivingSpawnEvent.CheckSpawn event)
{
    if(event.getResult() == Event.Result.ALLOW) return;
    if(TorchmasterConfig.MegaTorchAllowVanillaSpawners && event.isSpawner()) return;

    if(TorchMasterMod.MegaTorchFilterRegistry.containsEntity(event.getEntity()))
    {
        if(TorchRegistry.getMegaTorchRegistry().isInRangeOfTorch(event.getWorld(), event.getEntity().getPosition()))
        {
            event.setResult(Event.Result.DENY);
        }
    }
    else if(TorchMasterMod.DreadLampFilterRegistry.containsEntity(event.getEntity()))
    {
        if(TorchRegistry.getDreadLampRegistry().isInRangeOfTorch(event.getWorld(), event.getEntity().getPosition()))
        {
            event.setResult(Event.Result.DENY);
        }
    }
}
项目:wolfarmor    文件:PlayerEventHandler.java   
/**
 * Handles right click on cauldron block
 *
 * @param event The RightClickEvent that was handled.
 * @param stack The item stack
 */
private void handleCauldronRightClick(@Nonnull RightClickBlock event, @Nonnull ItemStack stack)
{
    EntityPlayer player = event.getEntityPlayer();
    World world = event.getWorld();

    //TODO: Water sploosh sound event
    if(!world.isRemote && !stack.isEmpty())
    {
        IBlockState blockCauldronState = event.getWorld().getBlockState(event.getPos());
        int fillLevel = blockCauldronState.getValue(BlockCauldron.LEVEL);

        if (fillLevel > 0 && stack.getItem() instanceof ItemWolfArmor) {
            ItemWolfArmor itemWolfArmor = (ItemWolfArmor) stack.getItem();

            if (itemWolfArmor.getMaterial().getCanBeDyed() && itemWolfArmor.getHasColor(stack)) {
                itemWolfArmor.removeColor(stack);
                Blocks.CAULDRON.setWaterLevel(event.getWorld(), event.getPos(), blockCauldronState, fillLevel - 1);
                player.addStat(StatList.ARMOR_CLEANED);
                event.setResult(Event.Result.ALLOW);
                event.setCanceled(true);
            }
        }
    }
}
项目:geomastery    文件:WorldGenerator.java   
/** Alters vanilla ore generation. */
@SubscribeEvent
public void oreGenMinable(OreGenEvent.GenerateMinable event) {

    OreGenEvent.GenerateMinable.EventType type = event.getType();

    // Cancel vanilla ores to be overriden
    if (type == OreGenEvent.GenerateMinable.EventType.COAL ||
            type == OreGenEvent.GenerateMinable.EventType.DIAMOND ||
            type == OreGenEvent.GenerateMinable.EventType.EMERALD ||
            type == OreGenEvent.GenerateMinable.EventType.GOLD ||
            type == OreGenEvent.GenerateMinable.EventType.IRON ||
            type == OreGenEvent.GenerateMinable.EventType.LAPIS ||
            type == OreGenEvent.GenerateMinable.EventType.REDSTONE) {

        event.setResult(Event.Result.DENY);
    }
}
项目:InfinityLib    文件:MouseClickHandler.java   
@SubscribeEvent
@SuppressWarnings("unused")
public void onLeftClick(MouseEvent event) {
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    ItemStack stack = player.getHeldItemOffhand();
    if(event.getButton() != LMB) {
        return;
    }
    leftButtonPressed = !leftButtonPressed;
    if(stack == null) {
        return;
    }
    if(stack.getItem() instanceof IDualWieldedWeapon) {
        if(leftButtonPressed) {
            boolean shift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT);
            boolean ctrl = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL);
            IDualWieldedWeapon weapon = (IDualWieldedWeapon) stack.getItem();
            attackEntity(weapon, player, stack, true, shift, ctrl, EnumHand.OFF_HAND);
            weapon.onItemUsed(stack, player, shift, ctrl, EnumHand.OFF_HAND);
            new MessageMouseButtonPressed(true, shift, ctrl).sendToServer();
            Minecraft.getMinecraft().player.swingArm(EnumHand.OFF_HAND);
        }
        event.setResult(Event.Result.DENY);
        event.setCanceled(true);
    }
}
项目:InfinityLib    文件:MouseClickHandler.java   
@SubscribeEvent
@SuppressWarnings("unused")
public void onRightClick(MouseEvent event) {
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    ItemStack stack = player.getHeldItemMainhand();
    if(event.getButton() != RMB) {
        return;
    }
    rightButtonPressed = !rightButtonPressed;
    if(stack == null) {
        return;
    }
    if(stack.getItem() instanceof IDualWieldedWeapon) {
        if(rightButtonPressed) {
            boolean shift = Minecraft.getMinecraft().gameSettings.keyBindSneak.isKeyDown();
            boolean ctrl = Minecraft.getMinecraft().gameSettings.keyBindSprint.isKeyDown();
            IDualWieldedWeapon weapon = (IDualWieldedWeapon) stack.getItem();
            attackEntity(weapon, player, stack, false, shift, ctrl, EnumHand.MAIN_HAND);
            weapon.onItemUsed(stack, player, shift, ctrl, EnumHand.MAIN_HAND);
            new MessageMouseButtonPressed(false, shift, ctrl).sendToServer();
            Minecraft.getMinecraft().player.swingArm(EnumHand.MAIN_HAND);
        }
        event.setResult(Event.Result.DENY);
        event.setCanceled(true);
    }
}
项目:LootableBodies    文件:PlayerDeathEventHandler.java   
@SubscribeEvent(priority= EventPriority.LOW)
public void entityDeathEvent(LivingDeathEvent e){
    if(e.getEntity() instanceof EntityPlayer
            && e.getResult() != Event.Result.DENY
            && !e.getEntity().getEntityWorld().isRemote) {
        final EntityPlayer player = (EntityPlayer)e.getEntity();
        if(player.isSpectator()) return;
        Map<ItemStack,EntityEquipmentSlot> cache = equipmentCache.computeIfAbsent(player,(EntityPlayer p)->new HashMap<>());
        for(EntityEquipmentSlot slot : EntityLootableBody.EQUIPMENT_SLOTS){
            cache.put(player.getItemStackFromSlot(slot),slot);
        }

        if(player.getPrimaryHand() == EnumHandSide.LEFT){
            // swap main and off hand items (easier than messing with the rendering code)
            cache.put(player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND),EntityEquipmentSlot.OFFHAND);
            cache.put(player.getItemStackFromSlot(EntityEquipmentSlot.OFFHAND),EntityEquipmentSlot.MAINHAND);
        }
    }
}
项目:CraftingHarmonics    文件:EventHandler.java   
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onPlayerInteractEvent(PlayerInteractEvent.RightClickBlock evt) {
    // Called when right clicking on a block (potentially with something...)
    if(evt.isCanceled()) return;

    // Check if we're cancelling, or if our interaction handler says we should cancel:
    if (!ItemRegistry.instance.shouldCancelUse(evt) && BlockRegistry.instance.handleInteraction(evt)) return;

    evt.setUseItem(Event.Result.DENY);
    evt.setUseBlock(Event.Result.ALLOW);
    evt.setCanceled(true);

    // The game ends up firing the RightClickItem event as well; we set this here to make sure
    // we don't end up doing all the checks/callbacks a second time in that event:
    debounceItemRightClick.set(true);
}
项目:SettlerCraft    文件:SleepHandler.java   
@SubscribeEvent
@SuppressWarnings("unused")
public void onPlayerTryToSleep(PlayerInteractEvent.RightClickBlock event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState state = world.getBlockState(pos);
    if(!(state.getBlock() instanceof BlockBed)) {
        return;
    }
    if(isBedOccupied(world, pos, state)) {
        event.setCanceled(true);
        event.setUseBlock(Event.Result.DENY);
        event.setUseItem(Event.Result.DENY);
        event.getEntityPlayer().sendMessage(new TextComponentString("Occupied"));
    }
}
项目:DrawersBits    文件:PlayerEventHandler.java   
@SubscribeEvent(priority = EventPriority.HIGH)
public void interaction(
        final PlayerInteractEvent.LeftClickBlock event )
{
    if (BitDrawers.config.debugTrace) {
        Vec3d vec = event.getHitVec();
        BDLogger.info("Left Click %s %s %f %f %f", resultToString(event.getUseItem()), resultToString(event.getUseBlock()), vec.xCoord, vec.yCoord, vec.zCoord);
    }
    if ( event.getEntityPlayer() != null && event.getUseItem() != Event.Result.DENY )
    {
        final ItemStack is = event.getItemStack();
        if ( is != null && (is.getItem() instanceof ItemChiseledBit) && event.getWorld().isRemote)
        {
            Block target = event.getWorld().getBlockState(event.getPos()).getBlock();
            if (target instanceof BlockBitDrawers) {
                target.onBlockClicked(event.getWorld(), event.getPos(), event.getEntityPlayer());
            }
            if (BitDrawers.config.debugTrace)
                BDLogger.info("Bit Left Click");
        }
    }
}
项目:orecontrol    文件:OreControlEventHandler.java   
@SubscribeEvent
public void onOreGenMinable(OreGenEvent.GenerateMinable event)
{
    Configs configs = Configs.get(event.getWorld());
    EventType type = event.getType();

    // Disable custom ores, if a mod happens to fire the event
    if (type == EventType.CUSTOM)
    {
        if (configs.minableIsDisabled(type))
        {
            event.setResult(Event.Result.DENY);
        }
    }
    // Disable ALL vanilla generation, including dirt and gravel pockets.
    else if (configs.minablesDisableAllVanillaGeneration())
    {
        event.setResult(Event.Result.DENY);
    }
    // Disable individual types
    else if (configs.minableIsDisabled(type))
    {
        event.setResult(Event.Result.DENY);
    }
}
项目:morecommands    文件:PatchManager.java   
/**
 * Fires an {@link Event} and applies all patches associated with it
 * 
 * @param event the {@link Event}
 */
@SubscribeEvent
public <T extends Event> void fireForgeEvent(T event) {
    synchronized (this.forgeEventBasedPatches) {
        Iterator<ForgeEventBasedPatch> itr = this.forgeEventBasedPatches.get(event.getClass()).iterator();

        while (itr.hasNext()) {
            ForgeEventBasedPatch patch = itr.next();
            if (!patch.needsToBeApplied(event)) continue;

            if (patch.printLogFor(event)) {
                if (!patch.applyForgeEventPatch(event))
                    handleApplyFailure(patch);
                else
                    handlyApplySuccess(patch);
            }
            else patch.applyForgeEventPatch(event);
        }
    }
}
项目:morecommands    文件:PatchNetHandlerPlayServer.java   
@Override
public <T extends Event> boolean applyForgeEventPatch(T e) {
    EntityJoinWorldEvent event = (EntityJoinWorldEvent) e;

    EntityPlayerMP player = (EntityPlayerMP) event.getEntity();
    AppliedPatches patches = PatchManager.instance().getAppliedPatchesForPlayer(player);

    if (player.connection.player == event.getEntity() && !(player.connection instanceof NetHandlerPlayServer)) {
        net.minecraft.network.NetHandlerPlayServer handler = player.connection;
        player.connection = new NetHandlerPlayServer(player.getServer(), handler.netManager, handler.player);

        if (patches != null) 
            patches.setPatchSuccessfullyApplied(this.displayName, true);
    }

    return true;
}
项目:NOVA-Core    文件:ForgeEventHandler.java   
@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());
    }
}
项目:NaturalTrees    文件:NaturalTrees.java   
@SubscribeEvent
public void onSaplingGrow(SaplingGrowTreeEvent ev)
{
    IBlockState state = ev.getWorld().getBlockState(ev.getPos());
    Block block = state.getBlock();
    if (block == Blocks.sapling)
    {
        BlockPlanks.EnumType type = state.getValue(BlockSapling.TYPE);

        switch (type)
        {
            case OAK:
                ev.setResult(Event.Result.DENY);
                new BirchTreeGenerator().generateTreeAt(ev.getWorld(), ev.getPos(), ev.getRand());
                break;
        }
    }
}
项目:ClockworkPhase2    文件:WorldGenHandler.java   
@SubscribeEvent
public void onOreGeneration(OreGenEvent.GenerateMinable event)
{
    if(ConfigValues.SPAWN_WORLD_CRATER)
    {
        if(event.getWorld().provider.getDimension() == 0)
        {
            int x = event.getPos().getX();
            int z = event.getPos().getZ();
            if(Math.sqrt((x*x) + (z*z)) < 378)
            {
                event.setResult(Event.Result.DENY);
            }
        }
    }
}
项目:ClockworkPhase2    文件:WorldGenHandler.java   
@SubscribeEvent
public void onBiomeDecoration(DecorateBiomeEvent.Decorate event)
{
    if(ConfigValues.SPAWN_WORLD_CRATER)
    {
        if(event.getWorld().provider.getDimension() == 0)
        {
            int x = event.getPos().getX();
            int z = event.getPos().getZ();
            if(Math.sqrt((x*x) + (z*z)) < 378)
            {
                event.setResult(Event.Result.DENY);
            }
        }
    }
}
项目:ClockworkPhase2    文件:WorldGenHandler.java   
@SubscribeEvent
public void onBiomePopulate(PopulateChunkEvent.Populate event)
{
    if(ConfigValues.SPAWN_WORLD_CRATER)
    {
        if(event.getWorld().provider.getDimension() == 0)
        {
            int chunkX = event.getChunkX();
            int chunkZ = event.getChunkZ();
            if(Math.sqrt(((chunkX*16)*(chunkX*16)) + ((chunkZ*16)*(chunkZ*16))) < 378)
            {
                event.setResult(Event.Result.DENY);
            }
        }
    }
}
项目:Minecraft_Mineralogy    文件:OreSpawner.java   
@Override
public void generate(Random random, int chunkX, int chunkZ, World world,
                     IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {

    random.setSeed(random.nextLong() ^ hash);
    random.nextInt();
    final float r = random.nextFloat();
    for(float f = frequency; f > r; f -= 1 ){
        int x = (chunkX << 4) + random.nextInt(16);
           int y = random.nextInt(maxY - minY) + minY;
           int z = (chunkZ << 4) + random.nextInt(16);
       //    System.out.println("Generating deposite of "+ore.getUnlocalizedName()+" at ("+x+","+y+","+z+")");
        BlockPos pos = new BlockPos(x,y,z);
        OreGenEvent oreEvent = new OreGenEvent(world,random,pos);
        net.minecraftforge.common.MinecraftForge.ORE_GEN_BUS.post(oreEvent);
        if(oreEvent.getResult() == Event.Result.DENY) {
            // canceled by other mod
            continue;
        }
        oreGen.generate(world, random, pos);
    }
}
项目:ZeroQuest    文件:FireEventHandler.java   
private void extinguishFire(EntityPlayer player, BlockPos posIn, EnumFacing face, World world, Event event, int key) {
    BlockPos pos = posIn.offset(face);

    if (world.getBlockState(pos).getBlock() == ModBlocks.nileFire) {
        if ((event instanceof MouseEvent) || (event instanceof PlayerInteractEvent)) {
            PacketHandler.sendToServer(new FireSound(player, face, pos));
            event.setCanceled(true);
        }
        else if (event instanceof KeyInputEvent) {
            player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Please contact the modder of Zero Quest if you are trying to put out a fire " + EnumChatFormatting.RED + "using a key on your keyboard as your attack key."));
        }
    }
    else if (world.getBlockState(pos).getBlock() == ModBlocks.darkFire) {
        if ((event instanceof MouseEvent) || (event instanceof PlayerInteractEvent)) {
            PacketHandler.sendToServer(new FireSound(player, face, pos));
            event.setCanceled(true);
        }
        else if (event instanceof KeyInputEvent) {
            player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Please contact the modder of Zero Quest if you are trying to put out a fire " + EnumChatFormatting.RED + "using a key on your keyboard as your attack key."));
        }
    }
}
项目:DrCyanos_Lootable-Bodies    文件:PlayerDeathEventHandler.java   
@SubscribeEvent(priority= EventPriority.LOW)
public void entityDeathEvent(LivingDeathEvent e){
    if(e.getEntity() instanceof EntityPlayer
            && e.getResult() != Event.Result.DENY
            && !e.getEntity().getEntityWorld().isRemote) {
        final EntityPlayer player = (EntityPlayer)e.getEntity();
        if(player.isSpectator()) return;
        Map<ItemStack,EntityEquipmentSlot> cache = equipmentCache.computeIfAbsent(player,(EntityPlayer p)->new HashMap<>());
        for(EntityEquipmentSlot slot : EntityLootableBody.EQUIPMENT_SLOTS){
            cache.put(player.getItemStackFromSlot(slot),slot);
        }

        if(player.getPrimaryHand() == EnumHandSide.LEFT){
            // swap main and off hand items (easier than messing with the rendering code)
            cache.put(player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND),EntityEquipmentSlot.OFFHAND);
            cache.put(player.getItemStackFromSlot(EntityEquipmentSlot.OFFHAND),EntityEquipmentSlot.MAINHAND);
        }
    }
}
项目:ThermionicsWorld    文件:ThermionicsWorld.java   
@SubscribeEvent
public void cropGrowEvent(BlockEvent.CropGrowEvent.Pre event) {
    //IBlockState cropState = event.getState();
    Block land = event.getWorld().getBlockState(event.getPos().down()).getBlock();
    if (land instanceof BlockMeat) {
        //vanilla ticks give a 1 in 10 chance. We're forcing it on a 1 in 4, with the remaining 3 potentially ALSO
        //growing at the normal 10%. So this should be pretty fast.
        int growthChance = (int)(Math.random()*4);
        if (growthChance==0) event.setResult(Event.Result.ALLOW);
    }
}
项目:pnc-repressurized    文件:PlayerEventSensor.java   
@Override
public int emitRedstoneOnEvent(Event event, TileEntity sensor, int range, String textboxText) {
    if (event instanceof PlayerEvent) {
        EntityPlayer player = ((PlayerEvent) event).getEntityPlayer();
        if (Math.abs(player.posX - sensor.getPos().getX() + 0.5D) < range + 0.5D && Math.abs(player.posY - sensor.getPos().getY() + 0.5D) < range + 0.5D && Math.abs(player.posZ - sensor.getPos().getZ() + 0.5D) < range + 0.5D) {
            return emitRedstoneOnEvent((PlayerEvent) event, sensor, range);
        }
    }
    return 0;
}
项目:pnc-repressurized    文件:BlockInteractSensor.java   
@Override
public int emitRedstoneOnEvent(Event event, TileEntity sensor, int range, Set<BlockPos> positions) {
    if (event instanceof PlayerInteractEvent) {
        PlayerInteractEvent interactEvent = (PlayerInteractEvent) event;
        return positions.contains(interactEvent.getPos()) ? 15 : 0;
    }
    return 0;
}
项目:pnc-repressurized    文件:EventHandlerUniversalSensor.java   
private void sendEventToSensors(World world, Event event) {
    if (!world.isRemote) {
        for (TileEntity te : world.loadedTileEntityList) {
            if (te instanceof TileEntityUniversalSensor) {
                ((TileEntityUniversalSensor) te).onEvent(event);
            }
        }
    }
}
项目:harshencastle    文件:HandlerHarshenInventory.java   
@SubscribeEvent
public void onEvent(Event event)
{
    event = phaseEvent(event);
    if(HarshenUtils.isPlayerInvolved(event))
    {
        EntityPlayer player = HarshenUtils.getPlayer(event);
        ArrayList<Item> loadedItems = new ArrayList<>();
        for(int i = 0; i < HarshenUtils.getHandler(player).getSlots(); i ++)
        {
            ItemStack stack = HarshenUtils.getHandler(player).getStackInSlot(i);
            if(!HarshenUtils.hasProvider(stack))
                continue; //practically impossible
            IHarshenProvider provider = HarshenUtils.getProvider(stack);
            Object object = provider.getProvider(stack);
            if(object != null && !(loadedItems.contains(stack.getItem()) && !provider.isMultiplyEvent(stack)))
                try {
                    Method method = HarshenUtils.getMethod(object.getClass(), HarshenEvent.class, event.getClass());
                    if(method != null)
                        method.invoke(object, event);
                } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    if(e instanceof InvocationTargetException)
                        ((InvocationTargetException)e).getTargetException().printStackTrace();
                    else
                        e.printStackTrace();
                }
            loadedItems.add(stack.getItem());
        }
    }

}