net.minecraft.world.World.playEvent()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(13.0k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中net.minecraft.world.World.playEvent()方法的一些代码示例,展示了World.playEvent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。World.playEvent()方法的具体详情如下:
包路径:net.minecraft.world.World
类名称:World
方法名:playEvent

World.playEvent介绍

暂无

代码示例

代码示例来源:origin: EngineHub/WorldEdit

  1. @Override
  2. public boolean playEffect(Vector3 position, int type, int data) {
  3. getWorld().playEvent(type, ForgeAdapter.toBlockPos(position.toBlockPoint()), data);
  4. return true;
  5. }

代码示例来源:origin: Vazkii/Botania

  1. @Override
  2. protected void playDispenseSound(IBlockSource source) {
  3. source.getWorld().playEvent(1000, source.getBlockPos(), 0);
  4. }

代码示例来源:origin: Vazkii/Botania

  1. @Override
  2. protected void playDispenseSound(IBlockSource source)
  3. {
  4. if (field_179241_b)
  5. {
  6. source.getWorld().playEvent(1000, source.getBlockPos(), 0);
  7. }
  8. else
  9. {
  10. source.getWorld().playEvent(1001, source.getBlockPos(), 0);
  11. }
  12. }
  13. }

代码示例来源:origin: Vazkii/Botania

  1. @Override
  2. protected void onImpact(@Nonnull RayTraceResult pos) {
  3. if(pos.getBlockPos() != null && !world.isRemote) {
  4. List<BlockPos> coordsList = getCoordsToPut(pos.getBlockPos());
  5. world.playEvent(2002, new BlockPos(this), 8);
  6. for(BlockPos coords : coordsList) {
  7. world.setBlockState(coords, Blocks.END_STONE.getDefaultState());
  8. if(Math.random() < 0.1)
  9. world.playEvent(2001, coords, Block.getStateId(Blocks.END_STONE.getDefaultState()));
  10. }
  11. setDead();
  12. }
  13. }

代码示例来源:origin: Vazkii/Botania

  1. @Nonnull
  2. @Override
  3. public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float par8, float par9, float par10) {
  4. ItemStack stack = player.getHeldItem(hand);
  5. if(stack.getItemDamage() == 4 || stack.getItemDamage() == 14)
  6. return EntityDoppleganger.spawn(player, stack, world, pos, stack.getItemDamage() == 14) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
  7. else if(stack.getItemDamage() == 20 && net.minecraft.item.ItemDye.applyBonemeal(stack, world, pos, player, hand)) {
  8. if(!world.isRemote)
  9. world.playEvent(2005, pos, 0);
  10. return EnumActionResult.SUCCESS;
  11. }
  12. return super.onItemUse(player, world, pos, hand, side, par8, par9, par10);
  13. }

代码示例来源:origin: Vazkii/Botania

  1. @Override
  2. public boolean onUsedByWand(EntityPlayer player, ItemStack stack, World world, BlockPos pos, EnumFacing side) {
  3. if(player == null || world.isRemote)
  4. return false;
  5. if(!player.isSneaking()) {
  6. playerPositions.put(player.getUniqueID(), new DimWithPos(world.provider.getDimension(), pos));
  7. world.playSound(null, pos, ModSounds.ding, SoundCategory.BLOCKS, 0.5F, 1F);
  8. } else {
  9. spawnAsEntity(world, pos, new ItemStack(this));
  10. world.setBlockToAir(pos);
  11. world.playEvent(2001, pos, Block.getStateId(getDefaultState()));
  12. }
  13. return true;
  14. }

代码示例来源:origin: Vazkii/Botania

  1. @Nonnull
  2. @Override
  3. public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float xs, float ys, float zs) {
  4. IBlockState state = world.getBlockState(pos);
  5. if(Item.getItemFromBlock(state.getBlock()) == Items.AIR)
  6. return EnumActionResult.PASS;
  7. ItemStack blockStack = new ItemStack(state.getBlock());
  8. int[] ids = OreDictionary.getOreIDs(blockStack);
  9. for(int i : ids) {
  10. String name = OreDictionary.getOreName(i);
  11. if(name.equals("grass")) {
  12. world.playEvent(2001, pos, Block.getStateId(state));
  13. world.setBlockState(pos, ModBlocks.enchantedSoil.getDefaultState());
  14. player.getHeldItem(hand).shrink(1);
  15. return EnumActionResult.SUCCESS;
  16. }
  17. }
  18. return EnumActionResult.PASS;
  19. }

代码示例来源:origin: Vazkii/Botania

  1. @Override
  2. protected void onImpact(RayTraceResult pos) {
  3. if (world.isRemote)
  4. return;
  5. EntityLivingBase thrower = getThrower();
  6. if(pos.entityHit != null && thrower != null && pos.entityHit != thrower && !pos.entityHit.isDead) {
  7. if(thrower instanceof EntityPlayer)
  8. pos.entityHit.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) thrower), Math.random() < 0.25 ? 10 : 5);
  9. else pos.entityHit.attackEntityFrom(DamageSource.GENERIC, Math.random() < 0.25 ? 10 : 5);
  10. }
  11. if (pos.getBlockPos() != null) {
  12. IBlockState state = world.getBlockState(pos.getBlockPos());
  13. if(ConfigHandler.blockBreakParticles && !state.getBlock().isAir(state, world, pos.getBlockPos()))
  14. world.playEvent(2001, pos.getBlockPos(), Block.getStateId(state));
  15. }
  16. setDead();
  17. }

代码示例来源:origin: Vazkii/Botania

  1. @Override
  2. public void onBurstCollision(IManaBurst burst, World world, BlockPos pos) {
  3. if(!burst.isFake() && !world.isRemote) {
  4. world.playEvent(2001, pos, Block.getStateId(getDefaultState()));
  5. world.setBlockToAir(pos);
  6. EntityManaStorm storm = new EntityManaStorm(world);
  7. storm.setPosition(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
  8. world.spawnEntity(storm);
  9. }
  10. }

代码示例来源:origin: Vazkii/Botania

  1. @Override
  2. protected void onImpact(@Nonnull RayTraceResult var1) {
  3. if(!world.isRemote) {
  4. if(var1 != null) {
  5. EnumFacing dir = var1.sideHit;
  6. if(dir != null && dir.getAxis() != EnumFacing.Axis.Y) {
  7. BlockPos pos = var1.getBlockPos().offset(dir);
  8. while(pos.getY() > 0) {
  9. IBlockState state = world.getBlockState(pos);
  10. Block block = state.getBlock();
  11. if(block.isAir(state, world, pos)) {
  12. IBlockState stateSet = ModBlocks.solidVines.getDefaultState().withProperty(propMap.get(dir.getOpposite()), true);
  13. world.setBlockState(pos, stateSet, 1 | 2);
  14. world.playEvent(2001, pos, Block.getStateId(stateSet));
  15. pos = pos.down();
  16. } else break;
  17. }
  18. }
  19. }
  20. this.world.setEntityState(this, (byte)3);
  21. setDead();
  22. }
  23. }

代码示例来源:origin: Vazkii/Botania

  1. @Override
  2. public void onAvatarUpdate(IAvatarTile tile, ItemStack stack) {
  3. TileEntity te = (TileEntity) tile;
  4. World world = te.getWorld();
  5. if(!world.isRemote && tile.getCurrentMana() >= COST && tile.getElapsedFunctionalTicks() % 4 == 0 && world.rand.nextInt(8) == 0 && tile.isEnabled()) {
  6. BlockPos pos = ((TileEntity) tile).getPos().offset(tile.getAvatarFacing());
  7. IBlockState state = world.getBlockState(pos);
  8. if(state.getBlock().isAir(state, world, pos)) {
  9. world.setBlockState(pos, Blocks.DIRT.getDefaultState());
  10. world.playEvent(2001, pos, Block.getStateId(Blocks.DIRT.getDefaultState()));
  11. tile.recieveMana(-COST);
  12. }
  13. }
  14. }

代码示例来源:origin: Vazkii/Botania

  1. @Override
  2. public void onUpdate() {
  3. super.onUpdate();
  4. if(supertile.getWorld().isRemote || redstoneSignal > 0)
  5. return;
  6. if(mana >= COST && ticksExisted % 2 == 0) {
  7. BlockPos coords = getCoordsToPut();
  8. if(coords != null) {
  9. IBlockState state = getStoneToPut(coords);
  10. if(state != null) {
  11. supertile.getWorld().setBlockState(coords, state);
  12. if(ConfigHandler.blockBreakParticles)
  13. supertile.getWorld().playEvent(2001, coords, Block.getStateId(state));
  14. mana -= COST;
  15. sync();
  16. }
  17. }
  18. }
  19. }

代码示例来源:origin: Vazkii/Botania

  1. @Override
  2. public void onUpdate() {
  3. super.onUpdate();
  4. if(supertile.getWorld().isRemote)
  5. return;
  6. if(ticksExisted % 200 == 0)
  7. sync();
  8. if(ticksExisted % 6 == 0 && redstoneSignal == 0) {
  9. int range = getRange();
  10. int x = supertile.getPos().getX() + supertile.getWorld().rand.nextInt(range * 2 + 1) - range;
  11. int z = supertile.getPos().getZ() + supertile.getWorld().rand.nextInt(range * 2 + 1) - range;
  12. for(int i = 4; i > -2; i--) {
  13. int y = supertile.getPos().getY() + i;
  14. BlockPos pos = new BlockPos(x, y, z);
  15. if(supertile.getWorld().isAirBlock(pos))
  16. continue;
  17. if(isPlant(pos) && mana > 5) {
  18. Block block = supertile.getWorld().getBlockState(pos).getBlock();
  19. mana -= 5;
  20. supertile.getWorld().scheduleUpdate(pos, block, 1);
  21. if(ConfigHandler.blockBreakParticles)
  22. supertile.getWorld().playEvent(2005, pos, 6 + supertile.getWorld().rand.nextInt(4));
  23. supertile.getWorld().playSound(null, x, y, z, ModSounds.agricarnation, SoundCategory.BLOCKS, 0.01F, 0.5F + (float) Math.random() * 0.5F);
  24. break;
  25. }
  26. }
  27. }
  28. }

代码示例来源:origin: Vazkii/Botania

  1. IBlockState state = block.getStateFromMeta(meta);
  2. player.world.setBlockState(coords, state, 1 | 2);
  3. player.world.playEvent(2001, coords, Block.getStateId(state));

代码示例来源:origin: Vazkii/Botania

  1. public static void removeBlockWithDrops(EntityPlayer player, ItemStack stack, World world, BlockPos pos,
  2. Predicate<IBlockState> filter,
  3. boolean dispose, boolean particles) {
  4. if(!world.isBlockLoaded(pos))
  5. return;
  6. IBlockState state = world.getBlockState(pos);
  7. Block block = state.getBlock();
  8. if(!world.isRemote && filter.test(state)
  9. && !block.isAir(state, world, pos) && state.getPlayerRelativeBlockHardness(player, world, pos) > 0
  10. && block.canHarvestBlock(player.world, pos, player)) {
  11. int exp = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos);
  12. if(exp == -1)
  13. return;
  14. if(!player.capabilities.isCreativeMode) {
  15. TileEntity tile = world.getTileEntity(pos);
  16. if(block.removedByPlayer(state, world, pos, player, true)) {
  17. block.onPlayerDestroy(world, pos, state);
  18. if(!dispose || !ItemElementiumPick.isDisposable(block)) {
  19. block.harvestBlock(world, player, pos, state, tile, stack);
  20. block.dropXpOnBlockBreak(world, pos, exp);
  21. }
  22. }
  23. damageItem(stack, 1, player, 80);
  24. } else world.setBlockToAir(pos);
  25. if(particles && ConfigHandler.blockBreakParticles && ConfigHandler.blockBreakParticlesTool)
  26. world.playEvent(2001, pos, Block.getStateId(state));
  27. }
  28. }

代码示例来源:origin: Vazkii/Botania

  1. @Override
  2. public void onUpdate() {
  3. super.onUpdate();
  4. if(supertile.getWorld().isRemote || redstoneSignal > 0)
  5. return;
  6. if(ticksExisted % 30 == 0 && mana >= COST) {
  7. BlockPos pos = new BlockPos(
  8. supertile.getPos().getX() - RANGE + supertile.getWorld().rand.nextInt(RANGE * 2 + 1),
  9. supertile.getPos().getY() + RANGE,
  10. supertile.getPos().getZ() - RANGE + supertile.getWorld().rand.nextInt(RANGE * 2 + 1)
  11. );
  12. BlockPos up = pos.up();
  13. for(int i = 0; i < RANGE * 2; i++) {
  14. IBlockState stateAbove = supertile.getWorld().getBlockState(up);
  15. Block blockAbove = stateAbove.getBlock();
  16. if((supertile.getWorld().isAirBlock(up) || blockAbove.isReplaceable(supertile.getWorld(), up)) && stateAbove.getMaterial() != Material.WATER && ModBlocks.flower.canPlaceBlockAt(supertile.getWorld(), up)) {
  17. EnumDyeColor color = EnumDyeColor.byMetadata(supertile.getWorld().rand.nextInt(16));
  18. IBlockState state = ModBlocks.flower.getDefaultState().withProperty(BotaniaStateProps.COLOR, color);
  19. if(ConfigHandler.blockBreakParticles)
  20. supertile.getWorld().playEvent(2001, up, Block.getStateId(state));
  21. supertile.getWorld().setBlockState(up, state, 1 | 2);
  22. mana -= COST;
  23. sync();
  24. break;
  25. }
  26. up = pos;
  27. pos = pos.down();
  28. }
  29. }
  30. }

代码示例来源:origin: Vazkii/Botania

  1. @Override
  2. public void onUpdate() {
  3. super.onUpdate();
  4. if (supertile.getWorld().isRemote)
  5. return;
  6. int mana = 1800;
  7. if(getMaxMana() - this.mana >= mana && !supertile.getWorld().isRemote && ticksExisted % 80 == 0) {
  8. for(int i = 0; i < RANGE * 2 + 1; i++)
  9. for(int j = 0; j < RANGE * 2 + 1; j++)
  10. for(int k = 0; k < RANGE * 2 + 1; k++) {
  11. BlockPos pos = supertile.getPos().add(i - RANGE, j - RANGE, k - RANGE);
  12. IBlockState state = supertile.getWorld().getBlockState(pos);
  13. Block block = state.getBlock();
  14. if(block instanceof BlockCake) {
  15. int nextSlicesEaten = state.getValue(BlockCake.BITES) + 1;
  16. if(nextSlicesEaten > 6)
  17. supertile.getWorld().setBlockToAir(pos);
  18. else supertile.getWorld().setBlockState(pos, state.withProperty(BlockCake.BITES, nextSlicesEaten), 1 | 2);
  19. supertile.getWorld().playEvent(2001, pos, Block.getStateId(state));
  20. supertile.getWorld().playSound(null, supertile.getPos(), SoundEvents.ENTITY_GENERIC_EAT, SoundCategory.BLOCKS, 1F, 0.5F + (float) Math.random() * 0.5F);
  21. this.mana += mana;
  22. sync();
  23. return;
  24. }
  25. }
  26. }
  27. }

代码示例来源:origin: Vazkii/Botania

  1. @Override
  2. public void onUpdate() {
  3. super.onUpdate();
  4. if(!supertile.getWorld().isRemote && ticksExisted % 5 == 0) {
  5. if(mana >= COST) {
  6. BlockPos coords = getCoordsToPut();
  7. if(coords != null) {
  8. supertile.getWorld().setBlockToAir(coords);
  9. if(ConfigHandler.blockBreakParticles)
  10. supertile.getWorld().playEvent(2001, coords, Block.getStateId(Blocks.SAND.getDefaultState()));
  11. EntityItem item = new EntityItem(supertile.getWorld(), coords.getX() + 0.5, coords.getY() + 0.5, coords.getZ() + 0.5, new ItemStack(Items.CLAY_BALL));
  12. supertile.getWorld().spawnEntity(item);
  13. mana -= COST;
  14. }
  15. }
  16. }
  17. }

代码示例来源:origin: Vazkii/Botania

  1. @Override
  2. public void onUpdate() {
  3. super.onUpdate();
  4. if(supertile.getWorld().isRemote || redstoneSignal > 0 || !canOperate())
  5. return;
  6. int cost = getCost();
  7. if(mana >= cost && ticksExisted % getDelay() == 0) {
  8. BlockPos coords = getCoordsToPut();
  9. if(coords != null) {
  10. ItemStack stack = getOreToPut();
  11. if(!stack.isEmpty()) {
  12. Block block = Block.getBlockFromItem(stack.getItem());
  13. int meta = stack.getItemDamage();
  14. supertile.getWorld().setBlockState(coords, block.getStateFromMeta(meta), 1 | 2);
  15. if(ConfigHandler.blockBreakParticles)
  16. supertile.getWorld().playEvent(2001, coords, Block.getIdFromBlock(block) + (meta << 12));
  17. supertile.getWorld().playSound(null, supertile.getPos(), ModSounds.orechid, SoundCategory.BLOCKS, 2F, 1F);
  18. mana -= cost;
  19. sync();
  20. }
  21. }
  22. }
  23. }

代码示例来源:origin: Vazkii/Botania

  1. @SubscribeEvent
  2. public static void onMinecartUpdate(MinecartUpdateEvent event) {
  3. BlockPos entPos = new BlockPos(event.getEntity());
  4. IBlockState state = event.getEntity().world.getBlockState(entPos);
  5. Block block = state.getBlock();
  6. boolean air = block.isAir(state, event.getEntity().world, entPos);
  7. int floatTicks = event.getEntity().getEntityData().getInteger(TAG_FLOAT_TICKS);
  8. if(block == ModBlocks.ghostRail)
  9. event.getEntity().getEntityData().setInteger(TAG_FLOAT_TICKS, 20);
  10. else if(block instanceof BlockRailBase || block == ModBlocks.dreamwood) {
  11. event.getEntity().getEntityData().setInteger(TAG_FLOAT_TICKS, 0);
  12. if(floatTicks > 0)
  13. event.getEntity().world.playEvent(2003, entPos, 0);
  14. }
  15. floatTicks = event.getEntity().getEntityData().getInteger(TAG_FLOAT_TICKS);
  16. if(floatTicks > 0) {
  17. IBlockState stateBelow = event.getEntity().world.getBlockState(entPos.down());
  18. Block blockBelow = stateBelow.getBlock();
  19. boolean airBelow = blockBelow.isAir(stateBelow, event.getEntity().world, entPos.down());
  20. if(air && airBelow || !air && !airBelow)
  21. event.getEntity().noClip = true;
  22. event.getEntity().motionY = 0.2;
  23. event.getEntity().motionX *= 1.4;
  24. event.getEntity().motionZ *= 1.4;
  25. event.getEntity().getEntityData().setInteger(TAG_FLOAT_TICKS, floatTicks - 1);
  26. event.getEntity().world.playEvent(2000, entPos, 0);
  27. } else event.getEntity().noClip = false;
  28. }

相关文章

World类方法