-
Notifications
You must be signed in to change notification settings - Fork 5
Add initial rail generator implementation #86
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
Open
Jasupa
wants to merge
39
commits into
main
Choose a base branch
from
rail-generator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
c80e7b5
feature: added a rail generator command including a custom undo and redo
Jasupa a9766e3
feature: added a first version for the cuboid and poly rail generator
Jasupa 9ca55bf
feature:
Jasupa 7e340ef
feature:
Jasupa f014b16
refactor:
Jasupa 385f8ee
refactor:
Jasupa 2bac069
fix:
Jasupa 693f3fd
fix:
Jasupa 47704c9
refractor:
Jasupa 873526b
refractor:
Jasupa 9a9380a
refractor:
Jasupa 6a6a97e
style(generator): restore single-line guard statements for railscripts
Jasupa e6894d5
refactor(rail): remove custom rail point commands
Jasupa 7e3cbb1
fix(generator): address review feedback
Jasupa a032d46
fix(generator): address rail review feedback
Jasupa d41eb32
fix(generator): address command execution review feedback
Jasupa 5bc7da4
fix(rail): address rail review feedback
Jasupa 7ea760f
fix(generator): improve rail placement and shared block updates
Jasupa 92bd78c
fix(generator): resolve qodana warnings
Jasupa dfc5118
fix(generator): resolve merge issues
Jasupa 1ac7434
fix(generator): avoid deprecated rail type icon parsing
Jasupa f131c80
fix(generator): add rail generation safeguards
Jasupa a067abb
fix(generator): resolve remaining qodana warnings
Jasupa 4c52322
fix(rail): make generation limits configurable
Jasupa 918d88e
fix(generator): resolve main rebase conflicts
Jasupa 48c48c2
fix(generator): resolve qodana warnings
Jasupa 8c6a1b4
fix(generator): added future support logic for multiple lanes using G…
Jasupa 0bca3bb
fix(generator): smooth weighted progress updates
Jasupa a0640e0
fix(generator): keep rail progress continuous until completion
Jasupa 6fad864
Merge branch 'main' into rail-generator
Jasupa 203c744
fix(generator): address config and menu review feedback
Jasupa 4f5d45f
Merge remote-tracking branch 'origin/rail-generator' into rail-generator
Jasupa d6b7362
fix(rail): address generation feedback handling
Jasupa 6124667
fix(rail): resolve underground placement issues
Jasupa c2b5e10
fix(rail): improve height resolution stability
Jasupa 4ddee65
fix(generator): address component and rail menu feedback
Jasupa 1c13c78
fix(generator): align component messaging style
Jasupa 0f24037
fix(generator): address history and utility cleanup
Jasupa 4c3e283
fix(generator): make help wiki links clickable
Jasupa 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
22 changes: 22 additions & 0 deletions
22
.../java/net/buildtheearth/buildteamtools/modules/generator/components/rail/PositionKey.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,22 @@ | ||
| package net.buildtheearth.buildteamtools.modules.generator.components.rail; | ||
|
|
||
| import org.bukkit.util.Vector; | ||
|
|
||
| record PositionKey(int x, int y, int z) { | ||
|
|
||
| static PositionKey from(Vector vector) { | ||
| return new PositionKey( | ||
| vector.getBlockX(), | ||
| vector.getBlockY(), | ||
| vector.getBlockZ() | ||
| ); | ||
| } | ||
|
|
||
| static PositionKey of(int x, int y, int z) { | ||
| return new PositionKey(x, y, z); | ||
| } | ||
|
|
||
| Vector toVector() { | ||
| return new Vector(x, y, z); | ||
| } | ||
| } |
63 changes: 56 additions & 7 deletions
63
src/main/java/net/buildtheearth/buildteamtools/modules/generator/components/rail/Rail.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 |
|---|---|---|
| @@ -1,27 +1,76 @@ | ||
| package net.buildtheearth.buildteamtools.modules.generator.components.rail; | ||
|
|
||
| import com.alpsbte.alpslib.utils.ChatHelper; | ||
| import com.alpsbte.alpslib.utils.GeneratorUtils; | ||
| import com.sk89q.worldedit.regions.ConvexPolyhedralRegion; | ||
| import com.sk89q.worldedit.regions.CuboidRegion; | ||
| import com.sk89q.worldedit.regions.Polygonal2DRegion; | ||
| import com.sk89q.worldedit.regions.Region; | ||
| import net.buildtheearth.buildteamtools.modules.generator.GeneratorModule; | ||
| import net.buildtheearth.buildteamtools.modules.generator.model.GeneratorComponent; | ||
| import net.buildtheearth.buildteamtools.modules.generator.model.GeneratorType; | ||
| import net.kyori.adventure.text.Component; | ||
| import net.kyori.adventure.text.format.NamedTextColor; | ||
| import org.bukkit.Sound; | ||
| import org.bukkit.entity.Player; | ||
|
|
||
| import java.util.Set; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| public class Rail extends GeneratorComponent { | ||
|
|
||
| private final Set<UUID> preparingPlayers = ConcurrentHashMap.newKeySet(); | ||
|
|
||
| public Rail() { | ||
| super(GeneratorType.RAILWAY); | ||
| super(GeneratorType.RAIL); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean checkForPlayer(Player p) { | ||
| return !GeneratorUtils.checkForNoWorldEditSelection(p); | ||
| public boolean checkForPlayer(Player player) { | ||
| if (GeneratorUtils.checkForNoWorldEditSelection(player)) | ||
| return false; | ||
|
|
||
| Region region = GeneratorUtils.getWorldEditSelection(player); | ||
|
|
||
| if (isSupportedRailSelection(region)) | ||
| return true; | ||
|
|
||
| player.sendMessage(ChatHelper.PREFIX_COMPONENT.append(Component.text( | ||
| "Rail Generator supports cuboid, polygonal and convex WorldEdit selections.", | ||
| NamedTextColor.RED | ||
| ))); | ||
| player.closeInventory(); | ||
| player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0F, 1.0F); | ||
| return false; | ||
| } | ||
|
|
||
| private boolean isSupportedRailSelection(Region region) { | ||
| return region instanceof CuboidRegion | ||
| || region instanceof Polygonal2DRegion | ||
| || region instanceof ConvexPolyhedralRegion; | ||
| } | ||
|
|
||
| @Override | ||
| public void generate(Player p) { | ||
| if (!GeneratorModule.getInstance().getRail().checkForPlayer(p)) | ||
| public void generate(Player player) { | ||
| if (GeneratorModule.getInstance().isGenerating(player) || !preparingPlayers.add(player.getUniqueId())) { | ||
| sendAlreadyGeneratingMessage(player); | ||
| return; | ||
| } | ||
|
|
||
| if (!GeneratorModule.getInstance().getRail().checkForPlayer(player)) { | ||
| preparingPlayers.remove(player.getUniqueId()); | ||
| return; | ||
| } | ||
|
|
||
| new RailScripts(player, this, () -> preparingPlayers.remove(player.getUniqueId())); | ||
| } | ||
|
|
||
| new RailScripts(p, this); | ||
| private void sendAlreadyGeneratingMessage(Player player) { | ||
| player.sendMessage(ChatHelper.PREFIX_COMPONENT.append(Component.text( | ||
| "Rail Generator is already running. Please wait until the current generation is finished.", | ||
| NamedTextColor.RED | ||
| ))); | ||
| player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0F, 1.0F); | ||
| } | ||
| } | ||
| } |
23 changes: 10 additions & 13 deletions
23
...ain/java/net/buildtheearth/buildteamtools/modules/generator/components/rail/RailFlag.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
50 changes: 50 additions & 0 deletions
50
...n/java/net/buildtheearth/buildteamtools/modules/generator/components/rail/RailLimits.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,50 @@ | ||
| package net.buildtheearth.buildteamtools.modules.generator.components.rail; | ||
|
|
||
| import net.buildtheearth.buildteamtools.BuildTeamTools; | ||
| import net.buildtheearth.buildteamtools.utils.io.ConfigPaths; | ||
| import net.buildtheearth.buildteamtools.utils.io.ConfigUtil; | ||
| import org.bukkit.configuration.file.FileConfiguration; | ||
|
|
||
| record RailLimits( | ||
| int maxControlPoints, | ||
| int maxPathPoints, | ||
| int maxBlockPlacements, | ||
| long maxPreparedRegionVolume, | ||
| int maxPreparedRegionAxisLength, | ||
| int blockPlacementBatchSize | ||
| ) { | ||
|
|
||
| private static final int DEFAULT_MAX_CONTROL_POINTS = 500; | ||
| private static final int DEFAULT_MAX_PATH_POINTS = 12_000; | ||
| private static final int DEFAULT_MAX_BLOCK_PLACEMENTS = 75_000; | ||
| private static final long DEFAULT_MAX_PREPARED_REGION_VOLUME = 750_000L; | ||
| private static final int DEFAULT_MAX_PREPARED_REGION_AXIS_LENGTH = 768; | ||
| private static final int DEFAULT_BLOCK_PLACEMENT_BATCH_SIZE = 500; | ||
| private static final int MAX_CONTROL_POINTS = 500; | ||
| private static final int MAX_PATH_POINTS = 25_000; | ||
| private static final int MAX_BLOCK_PLACEMENTS = 100_000; | ||
| private static final long MAX_PREPARED_REGION_VOLUME = 2_000_000L; | ||
| private static final int MAX_PREPARED_REGION_AXIS_LENGTH = 1_024; | ||
| private static final int MAX_BLOCK_PLACEMENT_BATCH_SIZE = 1_000; | ||
|
|
||
| static RailLimits fromConfig() { | ||
| FileConfiguration config = BuildTeamTools.getInstance().getConfig(ConfigUtil.GENERATOR); | ||
|
|
||
| return new RailLimits( | ||
| getBoundedInt(config, ConfigPaths.Generator.Rail.MAX_CONTROL_POINTS, DEFAULT_MAX_CONTROL_POINTS, 2, MAX_CONTROL_POINTS), | ||
| getBoundedInt(config, ConfigPaths.Generator.Rail.MAX_PATH_POINTS, DEFAULT_MAX_PATH_POINTS, 2, MAX_PATH_POINTS), | ||
| getBoundedInt(config, ConfigPaths.Generator.Rail.MAX_BLOCK_PLACEMENTS, DEFAULT_MAX_BLOCK_PLACEMENTS, 1, MAX_BLOCK_PLACEMENTS), | ||
| getBoundedLong(config, ConfigPaths.Generator.Rail.MAX_PREPARED_REGION_VOLUME, DEFAULT_MAX_PREPARED_REGION_VOLUME, 1L, MAX_PREPARED_REGION_VOLUME), | ||
| getBoundedInt(config, ConfigPaths.Generator.Rail.MAX_PREPARED_REGION_AXIS_LENGTH, DEFAULT_MAX_PREPARED_REGION_AXIS_LENGTH, 1, MAX_PREPARED_REGION_AXIS_LENGTH), | ||
| getBoundedInt(config, ConfigPaths.Generator.Rail.BLOCK_PLACEMENT_BATCH_SIZE, DEFAULT_BLOCK_PLACEMENT_BATCH_SIZE, 1, MAX_BLOCK_PLACEMENT_BATCH_SIZE) | ||
| ); | ||
| } | ||
|
|
||
| private static int getBoundedInt(FileConfiguration config, String path, int fallback, int minimum, int maximum) { | ||
| return Math.max(minimum, Math.min(maximum, config.getInt(path, fallback))); | ||
| } | ||
|
|
||
| private static long getBoundedLong(FileConfiguration config, String path, long fallback, long minimum, long maximum) { | ||
| return Math.max(minimum, Math.min(maximum, config.getLong(path, fallback))); | ||
| } | ||
| } |
Oops, something went wrong.
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.