-
Notifications
You must be signed in to change notification settings - Fork 2
Structure API revamp #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
655c684
feat: totally rework structure generation API
noone-075 e74cf88
chore: auto-format code
github-actions[bot] 3fc7dca
feat: pushed version to 1.3.1
noone-075 412a217
chore: fixed codestyle
noone-075 04e5ab2
fix: added final statements
noone-075 c5360df
chore: auto-format code
github-actions[bot] b5a17dd
Merge branch WebMCDevelopment/main
noone-075 be183ee
feat: changed a lot
noone-075 1ed7e37
chore: auto-format code
github-actions[bot] 25fe9be
chore: fix issues that i can
colbster937 251a232
Merge pull request #2 from colbster937/main
noone-075 9c24671
chore: auto-format code
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/main/java/xyz/webmc/wlib/api/structure/AbstractGenerableStructure.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * Copyright (C) 2026 Colbster937 | ||
| * | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published | ||
| * by the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * See the LICENSE file for details. | ||
| */ | ||
|
|
||
| package xyz.webmc.wlib.api.structure; | ||
|
|
||
| import xyz.webmc.wlib.api.WLIB; | ||
|
|
||
| import org.bukkit.Location; | ||
| import org.bukkit.World; | ||
|
|
||
| public abstract class AbstractGenerableStructure extends AbstractBaseStructure { | ||
| static final int SEARCH_RADIUS = 100; | ||
|
|
||
| protected AbstractGenerableStructure(final String name) { | ||
| super(name); | ||
| } | ||
|
|
||
| public abstract boolean canGenerateAt(final int chunkX, final int chunkZ, final long worldSeed); | ||
|
|
||
| public abstract long getGenerationSeed(final int chunkX, final int chunkZ, final long worldSeed); | ||
|
|
||
| public abstract PlaceableStructure build(final long seed); | ||
|
|
||
| @Override | ||
| public final PlaceableStructure build() { | ||
| return this.build(0); | ||
| } | ||
|
|
||
| public final Location locateNearest(final Location pos, final long worldSeed) { | ||
| Location ret = null; | ||
|
|
||
| if (pos != null && pos.getWorld() != null) { | ||
| final int centerChunkX = pos.getChunk().getX(); | ||
| final int centerChunkZ = pos.getChunk().getZ(); | ||
| final World world = pos.getWorld(); | ||
|
|
||
| search: | ||
| for (int radius = 0; radius <= SEARCH_RADIUS; radius++) { | ||
| final int minX = centerChunkX - radius; | ||
| final int maxX = centerChunkX + radius; | ||
| final int minZ = centerChunkZ - radius; | ||
| final int maxZ = centerChunkZ + radius; | ||
|
|
||
| for (int chunkX = minX; chunkX <= maxX; chunkX++) { | ||
| for (int chunkZ : new int[] { minZ, maxZ }) { | ||
| if (this.canGenerateAt(chunkX, chunkZ, worldSeed)) { | ||
| ret = this.createLocation(world, chunkX, chunkZ); | ||
| break search; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for (int chunkZ = minZ + 1; chunkZ < maxZ; chunkZ++) { | ||
| for (int chunkX : new int[] { minX, maxX }) { | ||
| if (this.canGenerateAt(chunkX, chunkZ, worldSeed)) { | ||
| ret = this.createLocation(world, chunkX, chunkZ); | ||
| break search; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| @Deprecated(forRemoval = true) | ||
| public final void place(final Location loc) { | ||
| WLIB.warnDeprecatedUsage(); | ||
| this.build(getGenerationSeed(loc.getChunk().getX(), loc.getChunk().getZ(), loc.getWorld().getSeed())).place(loc); | ||
| } | ||
|
noone-075 marked this conversation as resolved.
|
||
|
|
||
| private Location createLocation(final World world, final int chunkX, final int chunkZ) { | ||
| return new Location(world, chunkX * 16 + 8, 65, chunkZ * 16 + 8); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.