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

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

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

World.getCapability介绍

暂无

代码示例

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

  1. @Override
  2. public ISpatialDimension getSpatialDimension()
  3. {
  4. final int id = AppEng.instance().getStorageDimensionID();
  5. World w = DimensionManager.getWorld( id );
  6. if( w == null )
  7. {
  8. DimensionManager.initDimension( id );
  9. w = DimensionManager.getWorld( id );
  10. }
  11. if( w != null && w.hasCapability( Capabilities.SPATIAL_DIMENSION, null ) )
  12. {
  13. return w.getCapability( Capabilities.SPATIAL_DIMENSION, null );
  14. }
  15. return null;
  16. }

代码示例来源:origin: gegy1000/Terrarium

  1. public final TerrariumWorldData getWorldData(World world) {
  2. TerrariumWorldData worldData = world.getCapability(TerrariumCapabilities.worldDataCapability, null);
  3. if (worldData == null) {
  4. throw new IllegalStateException("Terrarium world capability not yet present");
  5. }
  6. return worldData;
  7. }

代码示例来源:origin: SleepyTrousers/EnderIO

  1. @Override
  2. public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
  3. return wrapped.getCapability(capability, facing);
  4. }

代码示例来源:origin: gegy1000/Terrarium

  1. public WorldCap(World world, Function<TerrariumWorldData, T> function) {
  2. super(() -> {
  3. TerrariumWorldData capability = world.getCapability(TerrariumCapabilities.worldDataCapability, null);
  4. if (capability != null) {
  5. return function.apply(capability);
  6. }
  7. throw new IllegalStateException("Tried to get world capability before it was present");
  8. });
  9. }
  10. }

代码示例来源:origin: amadornes/MCMultiPart

  1. @Override
  2. public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
  3. return getActualWorld().getCapability(capability, facing);
  4. }

代码示例来源:origin: ldtteam/minecolonies

  1. /**
  2. * Get all colonies in this world.
  3. *
  4. * @param w World.
  5. * @return a list of colonies.
  6. */
  7. @NotNull
  8. public static List<Colony> getColonies(@NotNull final World w)
  9. {
  10. final IColonyManagerCapability cap = w.getCapability(COLONY_MANAGER_CAP, null);
  11. if (cap == null)
  12. {
  13. Log.getLogger().warn(MISSING_WORLD_CAP_MESSAGE);
  14. return Collections.emptyList();
  15. }
  16. return cap.getColonies();
  17. }

代码示例来源:origin: ldtteam/minecolonies

  1. /**
  2. * Get Colony by UUID.
  3. *
  4. * @param id ID of colony.
  5. * @return Colony with given ID.
  6. */
  7. @Nullable
  8. public static Colony getColonyByWorld(final int id, final World world)
  9. {
  10. final IColonyManagerCapability cap = world.getCapability(COLONY_MANAGER_CAP, null);
  11. if (cap == null)
  12. {
  13. Log.getLogger().warn(MISSING_WORLD_CAP_MESSAGE);
  14. return null;
  15. }
  16. return cap.getColony(id);
  17. }

代码示例来源:origin: gegy1000/Terrarium

  1. public ComposableBiomeProvider(World world) {
  2. this.world = world;
  3. this.regionHandler = new Lazy<>(() -> {
  4. TerrariumWorldData capability = this.world.getCapability(TerrariumCapabilities.worldDataCapability, null);
  5. if (capability != null) {
  6. return capability.getRegionHandler();
  7. }
  8. throw new IllegalStateException("Tried to load RegionGenerationHandler before it was present");
  9. });
  10. this.compositionProcedure = new Lazy.WorldCap<>(world, TerrariumWorldData::getCompositionProcedure);
  11. }

代码示例来源:origin: ldtteam/minecolonies

  1. /**
  2. * Get all colonies in all worlds.
  3. *
  4. * @return a list of colonies.
  5. */
  6. @NotNull
  7. public static List<Colony> getAllColonies()
  8. {
  9. final List<Colony> allColonies = new ArrayList<>();
  10. for (final World world : FMLCommonHandler.instance().getMinecraftServerInstance().worlds)
  11. {
  12. final IColonyManagerCapability cap = world.getCapability(COLONY_MANAGER_CAP, null);
  13. if (cap != null)
  14. {
  15. allColonies.addAll(cap.getColonies());
  16. }
  17. }
  18. return allColonies;
  19. }

代码示例来源:origin: gegy1000/Terrarium

  1. public ComposableChunkGenerator(World world) {
  2. this.world = world;
  3. this.random = new Random(world.getWorldInfo().getSeed());
  4. this.compositionProcedure = new Lazy.WorldCap<>(world, TerrariumWorldData::getCompositionProcedure);
  5. this.regionHandler = new Lazy<>(() -> {
  6. TerrariumWorldData capability = this.world.getCapability(TerrariumCapabilities.worldDataCapability, null);
  7. if (capability != null) {
  8. return capability.getRegionHandler();
  9. }
  10. throw new IllegalStateException("Tried to load RegionGenerationHandler before it was present");
  11. });
  12. }

代码示例来源:origin: gegy1000/Terrarium

  1. @Nullable
  2. @Override
  3. public State update(World world, EntityPlayer player) {
  4. EarthCapability earthData = world.getCapability(TerrariumEarth.earthCap, null);
  5. if (earthData != null) {
  6. double blockX = earthData.getX(this.latitude, this.longitude);
  7. double blockZ = earthData.getZ(this.latitude, this.longitude);
  8. double deltaX = player.posX - blockX;
  9. double deltaZ = player.posZ - blockZ;
  10. if (deltaX * deltaX + deltaZ * deltaZ < IMMERSION_MIN_DISTANCE) {
  11. return new Immersed(this.id, blockX, player.posY, blockZ);
  12. }
  13. return this;
  14. }
  15. return null;
  16. }
  17. }

代码示例来源:origin: TeamWizardry/Wizardry

  1. public static WizardryWorld get(World world) {
  2. WizardryWorld cap = world.getCapability(capability(), null);
  3. if (cap == null) {
  4. throw new IllegalStateException("Missing capability: " + world.getWorldInfo().getWorldName() + "/" + world.provider.getDimensionType().getName());
  5. }
  6. return cap;
  7. }

代码示例来源:origin: ldtteam/minecolonies

  1. /**
  2. * Get Colony by UUID.
  3. *
  4. * @param id ID of colony.
  5. * @return Colony with given ID.
  6. */
  7. @Nullable
  8. public static Colony getColonyByDimension(final int id, final int dimension)
  9. {
  10. final World world = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(dimension);
  11. final IColonyManagerCapability cap = world.getCapability(COLONY_MANAGER_CAP, null);
  12. if (cap == null)
  13. {
  14. Log.getLogger().warn(MISSING_WORLD_CAP_MESSAGE);
  15. return null;
  16. }
  17. return cap.getColony(id);
  18. }

代码示例来源:origin: ldtteam/minecolonies

  1. /**
  2. * check if a position is too close to another colony.
  3. *
  4. * @param w World.
  5. * @param pos coordinates.
  6. * @return true if so.
  7. */
  8. public static boolean isTooCloseToColony(@NotNull final World w, @NotNull final BlockPos pos)
  9. {
  10. final IChunkmanagerCapability worldCapability = w.getCapability(CHUNK_STORAGE_UPDATE_CAP, null);
  11. if (worldCapability == null)
  12. {
  13. return true;
  14. }
  15. final Chunk centralChunk = w.getChunk(pos);
  16. final IColonyTagCapability colonyCap = centralChunk.getCapability(CLOSE_COLONY_CAP, null);
  17. if (colonyCap == null)
  18. {
  19. return true;
  20. }
  21. final ChunkLoadStorage storage = worldCapability.getChunkStorage(centralChunk.x, centralChunk.z);
  22. if (storage != null)
  23. {
  24. storage.applyToCap(colonyCap);
  25. }
  26. return !colonyCap.getAllCloseColonies().isEmpty();
  27. }

代码示例来源:origin: ldtteam/minecolonies

  1. /**
  2. * Load the colony info for a certain chunk.
  3. * @param chunk the chunk.
  4. * @param world the worldg to.
  5. */
  6. public static void loadChunk(final Chunk chunk, final World world)
  7. {
  8. final IColonyManagerCapability cap = world.getCapability(COLONY_MANAGER_CAP, null);
  9. if (cap == null)
  10. {
  11. return;
  12. }
  13. //todo get world cap to get chunksToLoad and decrease it!
  14. if(cap.getMissingChunksToLoad() > 0)
  15. {
  16. final IChunkmanagerCapability chunkManager = world.getCapability(CHUNK_STORAGE_UPDATE_CAP, null);
  17. if (chunkManager == null)
  18. {
  19. Log.getLogger().error(UNABLE_TO_FIND_WORLD_CAP_TEXT);
  20. return;
  21. }
  22. final ChunkLoadStorage existingStorage = chunkManager.getChunkStorage(chunk.x, chunk.z);
  23. if(existingStorage != null)
  24. {
  25. addStorageToChunk(chunk, existingStorage);
  26. cap.setMissingChunksToLoad(cap.getMissingChunksToLoad()-1);
  27. }
  28. }
  29. }

代码示例来源:origin: ldtteam/minecolonies

  1. /**
  2. * Get the top colony id of all colonies.
  3. *
  4. * @return the top id.
  5. */
  6. public static int getTopColonyId()
  7. {
  8. int top = 0;
  9. for (final World world : FMLCommonHandler.instance().getMinecraftServerInstance().worlds)
  10. {
  11. final IColonyManagerCapability cap = world.getCapability(COLONY_MANAGER_CAP, null);
  12. if (cap != null)
  13. {
  14. final int tempTop = cap.getTopID();
  15. if (tempTop > top)
  16. {
  17. top = tempTop;
  18. }
  19. }
  20. }
  21. return top;
  22. }
  23. }

代码示例来源:origin: gegy1000/Terrarium

  1. public static void provideSettings(World world, GenerationSettings settings) {
  2. providedSettings = settings;
  3. if (world == null || !(world.getWorldType() instanceof TerrariumWorldType)) {
  4. return;
  5. }
  6. TerrariumExternalCapProvider external = world.getCapability(TerrariumCapabilities.externalProviderCapability, null);
  7. if (external == null) {
  8. return;
  9. }
  10. TerrariumWorldType worldType = (TerrariumWorldType) world.getWorldType();
  11. Collection<ICapabilityProvider> capabilities = worldType.createCapabilities(world, providedSettings);
  12. for (ICapabilityProvider provider : capabilities) {
  13. external.addExternal(provider);
  14. }
  15. }

代码示例来源:origin: gegy1000/Terrarium

  1. @Override
  2. public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
  3. Entity entity = getTeleportedEntity(server, sender, args);
  4. EarthCapability earthData = entity.world.getCapability(TerrariumEarth.earthCap, null);
  5. if (earthData != null) {
  6. String argument = String.join(" ", args).replace(',', ' ');
  7. String[] locationInput = argument.split("\\s+");
  8. Thread thread = new Thread(() -> {
  9. try {
  10. CommandLocation location = this.parseLocation(sender, locationInput);
  11. this.teleport(entity, location.getCoordinate(sender, earthData));
  12. } catch (CommandException e) {
  13. TextComponentTranslation message = new TextComponentTranslation(e.getMessage(), e.getErrorObjects());
  14. message.getStyle().setColor(TextFormatting.RED);
  15. sender.sendMessage(message);
  16. }
  17. });
  18. thread.setDaemon(true);
  19. thread.start();
  20. } else {
  21. throw DeferredTranslator.createException(entity, "commands.earth.wrong_world");
  22. }
  23. }

代码示例来源:origin: gegy1000/Terrarium

  1. @Override
  2. public void displayPanorama() {
  3. Minecraft mc = Minecraft.getMinecraft();
  4. World world = mc.world;
  5. EarthCapability earthData = world.getCapability(TerrariumEarth.earthCap, null);
  6. if (earthData != null) {
  7. EntityPlayer player = mc.player;
  8. player.sendStatusMessage(new TextComponentTranslation("status.earth.panorama.searching"), true);
  9. double latitude = earthData.getLatitude(player.posX, player.posZ);
  10. double longitude = earthData.getLongitude(player.posX, player.posZ);
  11. Thread thread = new Thread(() -> {
  12. try {
  13. PanoramaLookupHandler.Result result = PanoramaLookupHandler.queryPanorama(latitude, longitude);
  14. if (result != null) {
  15. Minecraft.getMinecraft().addScheduledTask(() -> this.setPanoramaState(earthData, player, result));
  16. } else {
  17. player.sendStatusMessage(new TextComponentTranslation("status.earth.panorama.none_found"), true);
  18. }
  19. } catch (Exception e) {
  20. TerrariumEarth.LOGGER.error("Failed to lookup panorama", e);
  21. player.sendStatusMessage(new TextComponentTranslation("status.earth.panorama.error"), true);
  22. }
  23. });
  24. thread.setDaemon(true);
  25. thread.setName("Panorama Lookup");
  26. thread.start();
  27. }
  28. }

代码示例来源:origin: gegy1000/Terrarium

  1. @Override
  2. public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
  3. EntityPlayerMP player = CommandBase.getCommandSenderAsPlayer(sender);
  4. EarthCapability earthData = player.world.getCapability(TerrariumEarth.earthCap, null);
  5. if (earthData != null) {
  6. ContainerUi.Builder builder = ContainerUi.builder(player)
  7. .withTitle(DeferredTranslator.translate(player, new TextComponentTranslation("container.earth.geotool.name")))
  8. .withElement(Items.COMPASS, TextFormatting.BOLD + "Where am I?", () -> this.handleLocate(player, earthData));
  9. if (TerrariumHandshakeTracker.isFriendly(player)) {
  10. builder = builder
  11. .withElement(Items.ENDER_PEARL, TextFormatting.BOLD + "Go to place", () -> this.handleTeleport(player, earthData))
  12. .withElement(Items.PAINTING, TextFormatting.BOLD + "Display Panorama", () -> this.handlePanorama(player));
  13. }
  14. ContainerUi ui = builder.build();
  15. player.displayGUIChest(ui.createInventory());
  16. } else {
  17. throw DeferredTranslator.createException(player, "commands.earth.wrong_world");
  18. }
  19. }

相关文章

World类方法