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

下面列出了怎么用net.minecraftforge.fml.common.eventhandler.Event.Result的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: AdvancedRocketry   文件: BucketHandler.java
@SubscribeEvent
public void onBucketFill(FillBucketEvent event) {
	if(event.getTarget() == null || Type.BLOCK != event.getTarget().typeOfHit)
		return;
	IBlockState state =  event.getWorld().getBlockState(new BlockPos(event.getTarget().getBlockPos()));
	Block block = state.getBlock();
	Item bucket = bucketMap.get(block);
	
	if(bucket != null && state.equals(block.getDefaultState())) {
		event.getWorld().setBlockToAir(new BlockPos(event.getTarget().getBlockPos()));
		
		event.setFilledBucket(new ItemStack(bucket));
		
		bucket.hasContainerItem(event.getFilledBucket());
		
		event.setResult(Result.ALLOW);
	}
}
 
源代码2 项目: AdvancedRocketry   文件: PlanetEventHandler.java
@SubscribeEvent
public void onWorldGen(OreGenEvent.GenerateMinable event) {

	if(event.getWorld().provider instanceof WorldProviderPlanet && 
			DimensionManager.getInstance().getDimensionProperties(event.getWorld().provider.getDimension()).getOreGenProperties(event.getWorld()) != null) {

		switch(event.getType()) {
		case COAL:
		case DIAMOND:
		case EMERALD:
		case GOLD:
		case IRON:
		case LAPIS:
		case QUARTZ:
		case REDSTONE:
		case CUSTOM:
			event.setResult(Result.DENY);
			break;
		default:
			event.setResult(Result.DEFAULT);
		}
	}
}
 
源代码3 项目: EnderZoo   文件: MobSpawnEventHandler.java
@SubscribeEvent
public void onCheckSpawn(CheckSpawn evt) {
  if (evt.getEntityLiving() == null) {
    return;
  }
  String name = EntityList.getEntityString(evt.getEntityLiving());
  if (name == null) {
    return;
  }
  for (ISpawnEntry ent : MobSpawns.instance.getEntries()) {
    if (name.equals(ent.getMobName())) {
      if (!ent.canSpawnInDimension(evt.getWorld())) {
        evt.setResult(Result.DENY);
      }
    }
  }

}
 
@SubscribeEvent(priority = EventPriority.HIGH)
public void onBucketFill(FillBucketEvent evt) {
	if (evt.getResult() != Result.DEFAULT) return;

	if (evt.getEmptyBucket().getItem() != EMPTY_BUCKET) return;

	final RayTraceResult target = evt.getTarget();
	if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK) return;

	final TileEntity te = evt.getWorld().getTileEntity(target.getBlockPos());
	if (te == null) return;

	if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit)) {
		final IFluidHandler source = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit);

		final FluidStack drained = source.drain(containedFluid, false);
		if (containedFluid.isFluidStackIdentical(drained)) {
			source.drain(containedFluid, true);
			evt.setFilledBucket(filledBucket.copy());
			evt.setResult(Result.ALLOW);
		}
	}
}
 
源代码5 项目: Sakura_mod   文件: PotionCannon.java
@SubscribeEvent
public void onAttacking(ArrowLooseEvent event) {
	EntityPlayer player = event.getEntityPlayer();
	if(player.isPotionActive(this)){
		event.setCharge(event.getCharge()+player.getActivePotionEffect(this).getAmplifier()*25);
		event.setResult(Result.ALLOW);
	}

}
 
源代码6 项目: GregTech   文件: WorldGeneratorImpl.java
@SubscribeEvent(priority = EventPriority.HIGH)
public void onOreGenerate(OreGenEvent.GenerateMinable event) {
    EventType eventType = event.getType();
    if (ConfigHolder.disableVanillaOres &&
        ORE_EVENT_TYPES.contains(eventType)) {
        event.setResult(Result.DENY);
    }
}
 
源代码7 项目: Wizardry   文件: PotionGrace.java
@SubscribeEvent
public void onCrit(CriticalHitEvent event) {
	if (event.getEntityPlayer().getActivePotionEffect(ModPotions.GRACE) != null) {
		event.setDamageModifier(1.5F);
		event.setResult(Result.ALLOW);
	}
	event.getEntityPlayer().removePotionEffect(ModPotions.GRACE);
}
 
源代码8 项目: Valkyrien-Skies   文件: EventsCommon.java
@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);
    }
}
 
源代码9 项目: Valkyrien-Skies   文件: EventsCommon.java
@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);
    }
}
 
源代码10 项目: malmo   文件: ServerStateMachine.java
/** Called by Forge - return ALLOW, DENY or DEFAULT to control spawning in our world.*/
@SubscribeEvent
public void onCheckSpawn(CheckSpawn cs)
{
    // Decide whether or not to allow spawning.
    // We shouldn't allow spawning unless it has been specifically turned on - whether
    // a mission is running or not. (Otherwise spawning may happen in between missions.)
    boolean allowSpawning = false;
    if (currentMissionInit() != null && currentMissionInit().getMission() != null)
    {
        // There is a mission running - does it allow spawning?
        ServerSection ss = currentMissionInit().getMission().getServerSection();
        ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
        if (sic != null)
            allowSpawning = (sic.isAllowSpawning() == Boolean.TRUE);

        if (allowSpawning && sic.getAllowedMobs() != null && !sic.getAllowedMobs().isEmpty())
        {
            // Spawning is allowed, but restricted to our list.
            // Is this mob on our list?
            String mobName = EntityList.getEntityString(cs.getEntity());
            allowSpawning = false;
            for (EntityTypes mob : sic.getAllowedMobs())
            {
                if (mob.value().equals(mobName))
                {
                    allowSpawning = true;
                    break;
                }
            }
        }
    }
    if (allowSpawning)
        cs.setResult(Result.DEFAULT);
    else
        cs.setResult(Result.DENY);
}
 
源代码11 项目: AdvancedRocketry   文件: OreGenerator.java
@Override
public void generate(Random random, int chunkX, int chunkZ, World world,
		IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
	
	OreGenEvent event = new OreGenEvent.GenerateMinable(world, random, this, new BlockPos(chunkX,0,chunkZ), EventType.CUSTOM);
	MinecraftForge.ORE_GEN_BUS.post(event);
	if(event.getResult() != Result.DENY) {
		if(Configuration.generateCopper) {
			generate(world, MaterialRegistry.getMaterialFromName("Copper"), Configuration.copperPerChunk, Configuration.copperClumpSize, chunkX, chunkZ, random);
		}

		if(Configuration.generateTin) {
			generate(world, MaterialRegistry.getMaterialFromName("Tin"), Configuration.tinPerChunk, Configuration.tinClumpSize, chunkX, chunkZ, random);
		}
		if(Configuration.generateRutile) {
			generate(world, MaterialRegistry.getMaterialFromName("Rutile"), Configuration.rutilePerChunk, Configuration.rutileClumpSize, chunkX, chunkZ, random);
		}
		if(Configuration.generateAluminum) {
			generate(world, MaterialRegistry.getMaterialFromName("Aluminum"), Configuration.aluminumPerChunk, Configuration.aluminumClumpSize, chunkX, chunkZ, random);
		}
		if(Configuration.generateIridium) {
			generate(world, MaterialRegistry.getMaterialFromName("Iridium"), Configuration.IridiumPerChunk, Configuration.IridiumClumpSize, chunkX, chunkZ, random);
		}

		if(Configuration.generateDilithium) {
			int dilithiumChance = Configuration.dilithiumPerChunk;
			if(world.provider instanceof WorldProviderPlanet) {
				dilithiumChance = DimensionProperties.AtmosphereTypes.getAtmosphereTypeFromValue(DimensionManager.getInstance().getDimensionProperties(world.provider.getDimension()).getAtmosphereDensity()) == DimensionProperties.AtmosphereTypes.NONE ? Configuration.dilithiumPerChunkMoon : Configuration.dilithiumPerChunk;;
			}
			
			for(int i = 0; i < dilithiumChance; i++) {
				int coordX = 16*chunkX + random.nextInt(16);
				int coordY = random.nextInt(64);
				int coordZ = 16*chunkZ + random.nextInt(16);

				new WorldGenMinable(MaterialRegistry.getMaterialFromName("Dilithium").getBlock().getDefaultState(), Configuration.dilithiumClumpSize).generate(world, random, new BlockPos(coordX, coordY, coordZ));
			}
		}
	}
}
 
源代码12 项目: OpenModsLib   文件: ContainerBucketFillHandler.java
@SubscribeEvent
public void onBucketFill(FillBucketEvent evt) {
	if (evt.getResult() != Result.DEFAULT) return;

	if (evt.getEmptyBucket().getItem() != EMPTY_BUCKET) return;

	final RayTraceResult target = evt.getTarget();
	if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK) return;

	final TileEntity te = evt.getWorld().getTileEntity(target.getBlockPos());
	if (te == null) return;

	if (!canFill(evt.getWorld(), target.getBlockPos(), te)) { return; }

	if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit)) {
		final IFluidHandler source = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit);

		final FluidStack fluidInContainer = source.drain(Fluid.BUCKET_VOLUME, false);

		if (fluidInContainer != null) {
			final ItemStack filledBucket = getFilledBucket(fluidInContainer);
			if (!filledBucket.isEmpty()) {
				final IFluidHandlerItem container = FluidUtil.getFluidHandler(filledBucket);
				if (container != null) {
					final FluidStack fluidInBucket = container.drain(Integer.MAX_VALUE, false);
					if (fluidInBucket != null && fluidInBucket.isFluidStackIdentical(source.drain(fluidInBucket, false))) {
						source.drain(fluidInBucket, true);
						evt.setFilledBucket(filledBucket.copy());
						evt.setResult(Result.ALLOW);
					}
				}
			}
		}
	}
}
 
源代码13 项目: EnderZoo   文件: DebugUtil.java
@SubscribeEvent
public void onMonsterSpawn(LivingSpawnEvent evt) {
  if (evt.getEntityLiving() != null) { //&& !evt.entityLiving.getClass().getName().contains("enderzoo")) {
          evt.setResult(Result.DENY);
  }
}
 
 类方法
 同包方法