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

The following examples show how to use net.minecraftforge.fml.common.eventhandler.Event.Result. 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: BucketHandler.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@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);
	}
}
 
Example #2
Source File: PlanetEventHandler.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@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);
		}
	}
}
 
Example #3
Source File: MobSpawnEventHandler.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
@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);
      }
    }
  }

}
 
Example #4
Source File: SingleFluidBucketFillHandler.java    From OpenModsLib with MIT License 6 votes vote down vote up
@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);
		}
	}
}
 
Example #5
Source File: PotionCannon.java    From Sakura_mod with MIT License 5 votes vote down vote up
@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);
	}

}
 
Example #6
Source File: WorldGeneratorImpl.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example #7
Source File: PotionGrace.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #8
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 #9
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 #10
Source File: ServerStateMachine.java    From malmo with MIT License 5 votes vote down vote up
/** 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);
}
 
Example #11
Source File: OreGenerator.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@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));
			}
		}
	}
}
 
Example #12
Source File: ContainerBucketFillHandler.java    From OpenModsLib with MIT License 5 votes vote down vote up
@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);
					}
				}
			}
		}
	}
}
 
Example #13
Source File: DebugUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@SubscribeEvent
public void onMonsterSpawn(LivingSpawnEvent evt) {
  if (evt.getEntityLiving() != null) { //&& !evt.entityLiving.getClass().getName().contains("enderzoo")) {
          evt.setResult(Result.DENY);
  }
}