@SubscribeEvent public void onFillBucket(FillBucketEvent event) { RayTraceResult rtr = event.getTarget(); if (rtr != null) { Block b = event.getWorld().getBlockState(rtr.getBlockPos()).getBlock(); if (b instanceof IFluidBlock) { Fluid fluid = ((IFluidBlock) b).getFluid(); ItemStack filled = FluidUtil.getFilledBucket(new FluidStack(fluid, 1000)); if (!filled.isEmpty()) { event.setFilledBucket(FluidUtil.getFilledBucket(new FluidStack(fluid, 1000))); event.getWorld().setBlockToAir(rtr.getBlockPos()); event.setResult(Result.ALLOW); if (TileEntityRefinery.isInputFluidValid(fluid, 4) && event.getEntityPlayer() instanceof EntityPlayerMP) { AdvancementTriggers.OIL_BUCKET.trigger((EntityPlayerMP) event.getEntityPlayer()); } } } } }
@SubscribeEvent(priority=EventPriority.HIGH) public void placeKiln(PlayerInteractEvent.RightClickBlock event){ if(event.getWorld().getBlockState(event.getPos()).getBlock()==BlocksRegistry.potteryKiln){ event.setUseBlock(Result.ALLOW); }else if(!event.isCanceled()&&event.getEntityPlayer().isSneaking()&&PotteryKilnRecipe.isValidInput(event.getItemStack())){ if(event.getFace()==EnumFacing.UP&&event.getWorld().getBlockState(event.getPos()).isSideSolid(event.getWorld(), event.getPos(), EnumFacing.UP)&& event.getWorld().getBlockState(event.getPos().offset(EnumFacing.UP)).getBlock().isReplaceable(event.getWorld(), event.getPos().offset(EnumFacing.UP))){ if(!event.getWorld().isRemote){ event.getWorld().setBlockState(event.getPos().offset(EnumFacing.UP), BlocksRegistry.potteryKiln.getDefaultState()); TilePotteryKiln tile=((TilePotteryKiln)event.getWorld().getTileEntity(event.getPos().offset(EnumFacing.UP))); event.getEntityPlayer().setHeldItem(event.getHand(), tile.pottery.insertItem(0, event.getItemStack(), false)); event.getWorld().playSound(null, event.getPos(), SoundEvents.BLOCK_GRAVEL_PLACE, SoundCategory.BLOCKS, 1F, 1F); event.getWorld().notifyBlockUpdate(event.getPos().offset(EnumFacing.UP), BlocksRegistry.potteryKiln.getDefaultState(), BlocksRegistry.potteryKiln.getDefaultState(), 2); } event.setUseBlock(Result.DENY); event.setUseItem(Result.DENY); } } }
/** * Checks spawning */ @SubscribeEvent public void onSpawn(CheckSpawn event) { //If the entity is not a mob or above the forced-spawn-y-level, stop if (!(event.getEntity() instanceof EntityMob && event.getY() < underground)) return; EntityMob mob = (EntityMob) event.getEntity(); String name = EntityList.getEntityString(mob); //If whitelist and list contains mob, or blacklist and list does not contain mob if ((spawnWhitelist && mobsToSpawn.contains(name)) || (!(spawnWhitelist && mobsToSpawn.contains(name)))){ //If the chance is within allowed mob-spawn-under-y-level range, and the game is not on Peaceful if (rand.nextFloat() < undergroundChance && event.getWorld().getDifficulty() != EnumDifficulty.PEACEFUL){ //If there are no other entities in this area, and there are no collisions, and there is not a liquid if (event.getWorld().checkNoEntityCollision(mob.getEntityBoundingBox()) && event.getWorld().getCollisionBoxes(mob, mob.getEntityBoundingBox()).isEmpty() && !event.getWorld().containsAnyLiquid(mob.getEntityBoundingBox())){ //Allow the spawn event.setResult(Result.ALLOW); } } } }
public static ActionResult<ItemStack> onBucketUse(EntityPlayer player, World world, ItemStack stack, RayTraceResult target) { FillBucketEvent event = new FillBucketEvent(player, stack, world, target); if (MinecraftForge.EVENT_BUS.post(event)) return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack); if (event.getResult() == Result.ALLOW) { if (player.capabilities.isCreativeMode) return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack); if (--stack.stackSize <= 0) return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, event.getFilledBucket()); if (!player.inventory.addItemStackToInventory(event.getFilledBucket())) player.dropItem(event.getFilledBucket(), false); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack); } return null; }
@Override public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { if (world.isRemote) { //If its client side we have to return pass so this method is called on server, where we need to perform the op return EnumActionResult.PASS; } final IBlockState blockState = world.getBlockState(pos); IBlockState bs = blockState; Block block = bs.getBlock(); boolean ret = false; if (block != null) { RightClickBlock e = new RightClickBlock(player, hand, pos,side, new Vec3d(hitX, hitY, hitZ)); if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.getUseBlock() == Result.DENY || e.getUseItem() == Result.DENY) { return EnumActionResult.PASS; } if (!player.isSneaking() && block.rotateBlock(world, pos, side)) { ret = true; } } if (ret) { player.swingArm(hand); } return (ret && !world.isRemote) ? EnumActionResult.SUCCESS : EnumActionResult.PASS; }
@SubscribeEvent(priority = EventPriority.LOWEST) public void fogRenderEvent(final EntityViewRenderEvent.RenderFogEvent event) { if (!doFog() || event.getResult() != Result.DEFAULT) return; final float planeDistance = this.scanner.getPlaneDistance(event.getFarPlaneDistance()); if (event.getFogMode() < 0) { GlStateManager.setFogStart(0F); GlStateManager.setFogEnd(planeDistance); } else { GlStateManager.setFogStart(planeDistance * this.scanner.getPlaneDistanceScale()); GlStateManager.setFogEnd(planeDistance); } event.setResult(Result.ALLOW); }
/** Alters vanilla chunk populating. */ @SubscribeEvent public void populate(PopulateChunkEvent.Populate event) { Random rand = event.getRand(); // Chance of generating rice lake if (event.getType() == PopulateChunkEvent.Populate.EventType.LAKE && rand.nextFloat() <= 0.1) { event.setResult(Result.DENY); new PopulateChunkRicelake(event.getWorld(), rand) .generateChunk(event.getChunkX(), event.getChunkZ()); return; } }
/** 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); } }
/** Reduces animal spawns by half. */ @SubscribeEvent public void checkSpawn(CheckSpawn event) { EntityLivingBase entity = event.getEntityLiving(); boolean canSpawn = true; if (entity instanceof EntityAnimal) { if (entity.world.rand.nextInt(2) == 0) { canSpawn = false; } } event.setResult(canSpawn ? Result.DEFAULT : Result.DENY); }
@SubscribeEvent public void genDisabler(OreGenEvent.GenerateMinable event) { EventType type = event.type; if (type == EventType.COAL || type == EventType.DIAMOND || type == EventType.GOLD || type == EventType.IRON || type == EventType.LAPIS || type == EventType.QUARTZ || type == EventType.REDSTONE || type == EventType.EMERALD) { if(ConfigOptions.disableVanillaOres) { event.setResult(Result.DENY); } } else if (type == EventType.ANDESITE || type == EventType.DIORITE || type == EventType.GRANITE || type == EventType.GRAVEL || type == EventType.DIRT) { if(ConfigOptions.disableVanillaOthers) { event.setResult(Result.DENY); } } }
@SubscribeEvent public void spawnHandler(LivingSpawnEvent.CheckSpawn event) { if((!(event.getEntity() instanceof EntityPlayer))&&(!(event.getWorld().isRemote))) { if(ScarecrowTracking.get(event.getWorld()).inRange(event.getEntity())) { if(event.getWorld().getBlockState(event.getEntity().getPosition()).getBlock()==Blocks.FARMLAND) { event.setResult(Result.DENY); } if(event.getEntity() instanceof EntityBat) { event.setResult(Result.DENY); // I hate bats } } } }
public void func_180517_a(int p_180517_1_, int p_180517_2_, ChunkPrimer p_180517_3_, BiomeGenBase[] p_180517_4_) { ChunkProviderEvent.ReplaceBiomeBlocks event = new ChunkProviderEvent.ReplaceBiomeBlocks(this, p_180517_1_, p_180517_2_, p_180517_3_, this.worldObj); MinecraftForge.EVENT_BUS.post(event); if (event.getResult() == Result.DENY) return; double d0 = 0.03125D; this.stoneNoise = this.field_147430_m.func_151599_a(this.stoneNoise, (double) (p_180517_1_ * 16), (double) (p_180517_2_ * 16), 16, 16, d0 * 2.0D, d0 * 2.0D, 1.0D); for (int k = 0; k < 16; ++k) { for (int l = 0; l < 16; ++l) { BiomeGenBase biomegenbase = p_180517_4_[l + k * 16]; biomegenbase.genTerrainBlocks(this.worldObj, this.rand, p_180517_3_, p_180517_1_ * 16 + k, p_180517_2_ * 16 + l, this.stoneNoise[l + k * 16]); } } }
@SubscribeEvent public void onBonemealClick(BonemealEvent event) { World world = event.world; if (event.block.equals(mod_Rediscovered.CherrySapling)) { if (!world.isRemote) { double chance = 0.45D; if (world.rand.nextFloat() < chance) { //grow tree event.setResult(Result.ALLOW); ((BlockCherrySapling)mod_Rediscovered.CherrySapling).generateTree(event.world, event.pos, event.world.getBlockState(event.pos), event.world.rand); } } } }
@Override public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) { if (stack.getItemDamage() == ItemMeta.book.ordinal() || stack.getItemDamage() == ItemMeta.edit.ordinal()) { int guiid = player.isSneaking() ? GuiIDs.GROUP : GuiIDs.EDITOR; if (world.isRemote) { if (stack.getItemDamage() == ItemMeta.edit.ordinal()) MCClientHelper.FORCE_EDIT = true; else MCClientHelper.FORCE_EDIT = false; } player.openGui(Progression.instance, guiid, null, 0, 0, 0); return new ActionResult(EnumActionResult.SUCCESS, stack); } else if (!world.isRemote) { ICriteria criteria = getCriteriaFromStack(stack, world.isRemote); if (criteria != null) { Result completed = PlayerTracker.getServerPlayer(PlayerHelper.getUUIDForPlayer(player)).getMappings().forceComplete(criteria); if (!player.capabilities.isCreativeMode && completed == Result.ALLOW) { stack.stackSize--; return new ActionResult(EnumActionResult.SUCCESS, stack); } } } return new ActionResult(EnumActionResult.PASS, stack); }
@Override public void hoeUsed(UseHoeEvent event) { EnumFertility fertility = getFertility(event.world, event.pos); IBlockState newState = BlocksVC.farmland.getDefaultState().withProperty(BlockFarmlandVC.fertility, fertility); event.world.playSoundEffect((double)((float)event.entityPlayer.posX + 0.5F), (double)((float)event.entityPlayer.posY + 0.5F), (double)((float)event.entityPlayer.posZ + 0.5F), newState.getBlock().stepSound.getStepSound(), (newState.getBlock().stepSound.getVolume() + 1.0F) / 2.0F, newState.getBlock().stepSound.getFrequency() * 0.8F); event.world.setBlockState(event.pos, newState); TEFarmland tileentity = (TEFarmland)event.world.getTileEntity(event.pos); if (tileentity != null) { tileentity.setFertility(fertility.getAsNumber()); } else { System.out.println("tileentity was not created?"); } event.setResult(Result.ALLOW); event.entityPlayer.addExhaustion(0.1f); super.hoeUsed(event); }
public void func_180517_a(int p_180517_1_, int p_180517_2_, ChunkPrimer p_180517_3_, BiomeGenBase[] p_180517_4_) { ChunkProviderEvent.ReplaceBiomeBlocks event = new ChunkProviderEvent.ReplaceBiomeBlocks(this, p_180517_1_, p_180517_2_, p_180517_3_, this.worldObj); MinecraftForge.EVENT_BUS.post(event); if (event.getResult() == Result.DENY) return; double d0 = 0.03125D; this.stoneNoise = this.field_147430_m.func_151599_a(this.stoneNoise, (double)(p_180517_1_ * 16), (double)(p_180517_2_ * 16), 16, 16, d0 * 2.0D, d0 * 2.0D, 1.0D); for (int k = 0; k < 16; ++k) { for (int l = 0; l < 16; ++l) { BiomeGenBase biomegenbase = p_180517_4_[l + k * 16]; biomegenbase.genTerrainBlocks(this.worldObj, this.rand, p_180517_3_, p_180517_1_ * 16 + k, p_180517_2_ * 16 + l, this.stoneNoise[l + k * 16]); } } }
/** * Returns true if any nearby {@link IEntityBombEater} consumes this bomb */ private boolean wasBombEaten() { List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, getEntityBoundingBox().expand(0.5D, 0.5D, 0.5D)); for (EntityLivingBase entity : entities) { if (!entity.isEntityAlive()) { continue; } Result result = (entity instanceof IEntityBombEater ? ((IEntityBombEater) entity).ingestBomb(this) : Result.DENY); if (result == Result.ALLOW) { return true; } else if (result == Result.DEFAULT && ZSSEntityInfo.get(entity).onBombIngested(this)) { return true; } } return false; }
/** * Returns true if the hookshot can destroy the material type */ protected boolean canDestroyBlock(Block block, BlockPos pos, EnumFacing face) { Result result = Result.DEFAULT; if (block instanceof IHookable) { result = ((IHookable) block).canDestroyBlock(getType(), worldObj, pos, face); } else if (Config.allowHookableOnly()) { return false; } switch (result) { case DEFAULT: boolean isBreakable = block.getBlockHardness(worldObj, pos) >= 0.0F; boolean canPlayerEdit = false; if (getThrower() instanceof EntityPlayer) { canPlayerEdit = ((EntityPlayer) getThrower()).capabilities.allowEdit && Config.canHookshotBreakBlocks(); } Material m = block.getMaterial(); return (isBreakable && canPlayerEdit && (m == Material.glass || (m == Material.wood && getType().ordinal() / 2 == (HookshotType.CLAW_SHOT.ordinal() / 2)))); default: return result == Result.ALLOW; } }
@Override public Result shouldSwing(EntityWhip whip, World world, BlockPos pos, int ticksInGround) { if (ticksInGround > 30 && world.getBlockState(pos).getValue(AGE).intValue() == 7) { EntityLivingBase thrower = whip.getThrower(); EntityItem bomb = new EntityItem(world, whip.posX, whip.posY + 1, whip.posZ, new ItemStack(ZSSItems.bomb, 1, BombType.BOMB_FLOWER.ordinal())); double dx = thrower.posX - bomb.posX; double dy = (thrower.posY + thrower.getEyeHeight()) - (bomb.posY - 1); double dz = thrower.posZ - bomb.posZ; TargetUtils.setEntityHeading(bomb, dx, dy + 0.5D, dz, 1.0F, 0.0F, true); if (!world.isRemote) { world.spawnEntityInWorld(bomb); } world.setBlockToAir(pos); whip.setDead(); } return Result.DENY; }
@Override public Result shouldSwing(EntityWhip whip, World world, BlockPos pos, int ticksInGround) { if (ticksInGround > 30) { EntityLivingBase thrower = whip.getThrower(); EntityCeramicJar jar = new EntityCeramicJar(world, whip.posX, whip.posY + 1, whip.posZ); double dx = thrower.posX - jar.posX; double dy = (thrower.posY + thrower.getEyeHeight()) - (jar.posY - 1); double dz = thrower.posZ - jar.posZ; TargetUtils.setEntityHeading(jar, dx, dy + 0.5D, dz, 1.0F, 0.0F, true); TileEntity te = world.getTileEntity(pos); if (te instanceof IInventory) { ItemStack stack = ((IInventory) te).getStackInSlot(0); if (stack != null) { jar.setStack(stack); } } if (!world.isRemote) { world.spawnEntityInWorld(jar); } keepInventory = true; // don't drop items from breakBlock world.setBlockToAir(pos); keepInventory = false; whip.setDead(); } return Result.DENY; }
/** * LEFT_CLICK_BLOCK is only called on the server * RIGHT_CLICK_BLOCK is called on both sides... weird. */ @SubscribeEvent public void onInteract(PlayerInteractEvent event) { ItemStack stack = event.entityPlayer.getHeldItem(); switch(event.action) { case LEFT_CLICK_BLOCK: if (stack != null && stack.getItem() instanceof ISmashBlock && ZSSPlayerInfo.get(event.entityPlayer).getAttackTime() == 0) { if (blockWasSmashed(event.entityPlayer.worldObj, event.entityPlayer, stack, event.pos, event.face)) { if (event.entityPlayer instanceof EntityPlayerMP) { ZSSCombatEvents.setPlayerAttackTime(event.entityPlayer); PacketDispatcher.sendTo(new UnpressKeyPacket(UnpressKeyPacket.LMB), (EntityPlayerMP) event.entityPlayer); } event.useBlock = Result.DENY; } } break; case RIGHT_CLICK_BLOCK: if (stack != null && stack.getItem() instanceof ILiftBlock) { if (blockWasLifted(event.entityPlayer.worldObj, event.entityPlayer, stack, event.pos, event.face)) { event.useBlock = Result.DENY; } } break; default: } }
@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 public void onBowUse(ArrowNockEvent event){ // change to use Result: DENY (cannot fire), DEFAULT (attempt standard nocking algorithm), ALLOW (nock without further checks) Result canDrawBow = Result.DEFAULT; // insert special bow check here: if (event.getBow().getItem() instanceof ISpecialBow) { canDrawBow = ((ISpecialBow) event.getBow().getItem()).canDrawBow(event.getBow(), event.getEntityPlayer()); } // Special bow did not determine a result, so use standard algorithms instead: if (canDrawBow == Result.DEFAULT && (event.hasAmmo() || event.getEntityPlayer().capabilities.isCreativeMode)) { canDrawBow = Result.ALLOW; } if (canDrawBow == Result.DEFAULT) { ItemStack quiver = QuiverArrowRegistry.getArrowContainer(event.getBow(), event.getEntityPlayer()); if (!quiver.isEmpty() && ((IArrowContainer2)quiver.getItem()). hasArrowFor(quiver, event.getBow(), event.getEntityPlayer(), ((IArrowContainer2) quiver.getItem()).getSelectedSlot(quiver))) { canDrawBow = Result.ALLOW; } } // only nock if allowed if (canDrawBow == Result.ALLOW) { event.getEntityPlayer().setActiveHand(event.getHand()); event.setAction(ActionResult.newResult(EnumActionResult.SUCCESS, event.getBow())); } }
@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); } } }
@SubscribeEvent public void onEntitySpawn(LivingSpawnEvent.CheckSpawn evt) { if (evt.getResult() == Result.DENY) { return; } if(Config.spawnGuardStopAllSlimesDebug && evt.getEntity() instanceof EntitySlime) { evt.setResult(Result.DENY); return; } if(Config.spawnGuardStopAllSquidSpawning && evt.getEntity().getClass() == EntitySquid.class) { evt.setResult(Result.DENY); return; } Map<BlockPos, ISpawnCallback> guards = getGuardsForWorld(evt.getWorld()); for (ISpawnCallback guard : guards.values()) { ISpawnCallback.Result result = guard.isSpawnPrevented(evt.getEntityLiving()); if (result == ISpawnCallback.Result.DENY) { evt.setResult(Result.DENY); return; } else if (result == ISpawnCallback.Result.DONE) { return; } } }
/** * Inject the new values and save to the config file when the config has * been changed from the GUI. * * @param event * The event */ @SubscribeEvent public static void onConfigChanged(final ConfigChangedEvent.OnConfigChangedEvent event) { if (event.getModID().equals(HardVox.MODID)) { if (!validateConfig()) { event.setResult(Result.DENY); return; } ConfigManager.sync(HardVox.MODID, Config.Type.INSTANCE); } }
/** 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.classToStringMapping.get(cs.entity.getClass()).toString(); 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); }
@SubscribeEvent public void checkHarvestedCrops(BlockEvent.HarvestDropsEvent event) { Block crop = event.getState().getBlock(); if (event.getHarvester() != null && event.getHarvester().capabilities.isCreativeMode) return; if (crop == UCBlocks.cropInvisibilia) { if (event.getHarvester() == null) { event.getDrops().clear(); event.setResult(Result.DEFAULT); } } if (crop == UCBlocks.cropFeroxia && ((Feroxia)crop).isFullyGrown(event.getWorld(), event.getPos(), event.getState())) { if (event.getHarvester() != null && !(event.getHarvester() instanceof FakePlayer)) GrowthSteps.generateSteps(event.getHarvester()); else event.getDrops().clear(); event.setResult(Result.DEFAULT); } if (crop == UCBlocks.cropDyeius && !event.getDrops().isEmpty()) { for (ItemStack stack : event.getDrops()) { if (stack.getItem() == Items.DYE) { long time = event.getWorld().getWorldTime() % 24000L; int meta = (int)(time / 1500); LocalDateTime current = LocalDateTime.now(); if (current.getDayOfWeek() == DayOfWeek.FRIDAY) stack.setItemDamage(EnumDyeColor.byMetadata(meta).getMetadata()); else stack.setItemDamage(EnumDyeColor.byMetadata(meta).getDyeDamage()); } } } }
public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z) { if (entity == null) return Result.DEFAULT; LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z); MinecraftForge.EVENT_BUS.post(event); return event.getResult(); }
public static boolean canEntitySpawnSpawner(EntityLiving entity, World world, float x, float y, float z) { Result result = canEntitySpawn(entity, world, x, y, z); if (result == Result.DEFAULT) { return entity.getCanSpawnHere() && entity.isNotColliding(); // vanilla logic } else { return result == Result.ALLOW; } }
public static int onHoeUse(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos) { UseHoeEvent event = new UseHoeEvent(player, stack, worldIn, pos); if (MinecraftForge.EVENT_BUS.post(event)) return -1; if (event.getResult() == Result.ALLOW) { stack.damageItem(1, player); return 1; } return 0; }
public static int onApplyBonemeal(EntityPlayer player, World world, BlockPos pos, IBlockState state, ItemStack stack) { BonemealEvent event = new BonemealEvent(player, world, pos, state); if (MinecraftForge.EVENT_BUS.post(event)) return -1; if (event.getResult() == Result.ALLOW) { if (!world.isRemote) stack.stackSize--; return 1; } return 0; }
public static boolean fireSleepingLocationCheck(EntityPlayer player, BlockPos sleepingLocation) { SleepingLocationCheckEvent evt = new SleepingLocationCheckEvent(player, sleepingLocation); MinecraftForge.EVENT_BUS.post(evt); Result canContinueSleep = evt.getResult(); if (canContinueSleep == Result.DEFAULT) { IBlockState state = player.worldObj.getBlockState(player.bedLocation); return state.getBlock().isBed(state, player.worldObj, player.bedLocation, player); } else return canContinueSleep == Result.ALLOW; }
public static boolean canCreateFluidSource(World world, BlockPos pos, IBlockState state, boolean def) { CreateFluidSourceEvent evt = new CreateFluidSourceEvent(world, pos, state); MinecraftForge.EVENT_BUS.post(evt); Result result = evt.getResult(); return result == Result.DEFAULT ? def : result == Result.ALLOW; }
@SubscribeEvent public void onPopulate(PopulateChunkEvent.Populate event) { if (event.getWorld().getWorldType() != ExPMisc.worldTypeExP) { return; } if (event.getType() == EventType.LAKE || event.getType() == EventType.LAVA) { event.setResult(Result.DENY); } }
@SubscribeEvent public void cancelLeftClick(final PlayerInteractEvent.LeftClickBlock event) { if (EventHandler.blockClickEvent) { EventHandler.blockClickEvent = false; event.setUseBlock(Event.Result.DENY); } }
/** 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); }