-
Notifications
You must be signed in to change notification settings - Fork 5
Rail generator v1 #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
6
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
6 commits
Select commit
Hold shift + click to select a range
535d06d
feature: added a rail generator command including a custom undo and redo
Jasupa c0c98ce
feature: added a first version for the cuboid and poly rail generator
Jasupa 738a7f5
feature:
Jasupa 003504c
feature:
Jasupa 6bd8615
refactor:
Jasupa f3315c4
refactor:
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
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
163 changes: 69 additions & 94 deletions
163
.../java/net/buildtheearth/buildteamtools/modules/generator/components/rail/RailScripts.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,127 +1,102 @@ | ||
| package net.buildtheearth.buildteamtools.modules.generator.components.rail; | ||
|
|
||
| import com.alpsbte.alpslib.utils.GeneratorUtils; | ||
| import net.buildtheearth.buildteamtools.BuildTeamTools; | ||
| import net.buildtheearth.buildteamtools.modules.generator.GeneratorModule; | ||
| import net.buildtheearth.buildteamtools.modules.generator.components.rail.path.RailPath; | ||
| import net.buildtheearth.buildteamtools.modules.generator.components.rail.path.RailPathBuilder; | ||
| import net.buildtheearth.buildteamtools.modules.generator.components.rail.placement.RailBlockPlacement; | ||
| import net.buildtheearth.buildteamtools.modules.generator.components.rail.placement.RailPlacementBuilder; | ||
| import net.buildtheearth.buildteamtools.modules.generator.components.rail.placement.RailWorldEditPlacer; | ||
| import net.buildtheearth.buildteamtools.modules.generator.components.rail.selection.RailSelectionPointReader; | ||
| import net.buildtheearth.buildteamtools.modules.generator.components.rail.types.RailType; | ||
| import net.buildtheearth.buildteamtools.modules.generator.components.rail.types.SampleRailType; | ||
| import net.buildtheearth.buildteamtools.modules.generator.model.GeneratorComponent; | ||
| import net.buildtheearth.buildteamtools.modules.generator.model.GeneratorType; | ||
| import net.buildtheearth.buildteamtools.modules.generator.model.History; | ||
| import net.buildtheearth.buildteamtools.modules.generator.model.Script; | ||
| import org.bukkit.block.Block; | ||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.util.Vector; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.logging.Level; | ||
|
|
||
| public class RailScripts extends Script { | ||
|
|
||
| private final RailPathBuilder pathBuilder = new RailPathBuilder(); | ||
| private final RailPlacementBuilder placementBuilder = new RailPlacementBuilder(); | ||
| private final RailWorldEditPlacer placer = new RailWorldEditPlacer(); | ||
|
|
||
| private final RailType railType = new SampleRailType(); | ||
|
|
||
| public RailScripts(Player player, GeneratorComponent generatorComponent) { | ||
| super(player, generatorComponent); | ||
|
|
||
| throw new UnsupportedOperationException("RailScripts is currently broken."); | ||
| //getPlayer().chat("/clearhistory"); | ||
| //Bukkit.getScheduler().runTaskAsynchronously(BuildTeamTools.getInstance(), this::railScript_v_1_3); | ||
| Thread thread = new Thread(this::generateRail); | ||
| thread.start(); | ||
| } | ||
|
|
||
| public void railScript_v_1_3() { | ||
| List<String> commands = new ArrayList<>(); | ||
| //HashMap<Flag, String > flags = rail.getPlayerSettings().get(p.getUniqueId()).getValues(); | ||
|
|
||
| int xPos = getPlayer().getLocation().getBlockX(); | ||
| int zPos = getPlayer().getLocation().getBlockZ(); | ||
|
|
||
| int operations = 0; | ||
|
|
||
| int railWidth = 5; | ||
|
|
||
|
|
||
| // TODO START TEMP | ||
|
|
||
| Block[][][] regionBlocks = GeneratorUtils.analyzeRegion(getPlayer(), getPlayer().getWorld()); | ||
| List<Vector> points = GeneratorUtils.getSelectionPointsFromRegion(getRegion()); | ||
| createCuboidSelection(points.get(0), points.get(1)); | ||
| createCommand("//set redstone_block"); | ||
| createBreakPoint(); | ||
| createCommand("//set gold_block"); | ||
|
|
||
| finish(regionBlocks, points); | ||
|
|
||
|
|
||
| // TODO END TEMP | ||
| private void generateRail() { | ||
| try { | ||
| List<Vector> controlPoints = getControlPoints(); | ||
|
|
||
| /* | ||
| // Get the points of the region | ||
| List<Vector> points = GeneratorUtils.getSelectionPointsFromRegion(getRegion()); | ||
| points = GeneratorUtils.populatePoints(points, 5); | ||
| if (controlPoints.size() < 2) { | ||
| getPlayer().sendMessage("§cRail Generator needs at least two usable points in the selection."); | ||
| return; | ||
| } | ||
|
|
||
| // ----------- PREPARATION 01 ---------- | ||
| // Replace all unnecessary blocks with air | ||
| RailPath railPath = pathBuilder.build(controlPoints); | ||
|
|
||
| List<Vector> polyRegionLine = new ArrayList<>(points); | ||
| polyRegionLine = GeneratorUtils.extendPolyLine(polyRegionLine); | ||
| List<Vector> polyRegionPoints = GeneratorUtils.shiftPoints(polyRegionLine, railWidth + 2, true); | ||
| if (!railPath.isValid()) { | ||
| getPlayer().sendMessage("§cRail Generator could not derive a valid path from this selection."); | ||
| return; | ||
| } | ||
|
|
||
| // Create a region from the points | ||
| GeneratorUtils.createPolySelection(getPlayer(), polyRegionPoints, null); | ||
| List<RailBlockPlacement> placements = placementBuilder.buildPlacements(railPath); | ||
|
|
||
| getPlayer().chat("//expand 30 up"); | ||
| getPlayer().chat("//expand 10 down"); | ||
| if (placements.isEmpty()) { | ||
| getPlayer().sendMessage("§cRail Generator did not create any block placements."); | ||
| return; | ||
| } | ||
|
|
||
| // Remove non-solid blocks | ||
| getPlayer().chat("//gmask !#solid"); | ||
| getPlayer().chat("//replace 0"); | ||
| operations++; | ||
| Bukkit.getScheduler().runTask(BuildTeamTools.getInstance(), () -> placeRail(placements)); | ||
| } catch (Exception exception) { | ||
| getPlayer().sendMessage("§cRail Generator failed while generating from the WorldEdit selection."); | ||
|
|
||
| // Remove all trees and pumpkins | ||
| getPlayer().chat("//gmask"); | ||
| getPlayer().chat("//replace leaves,log,pumpkin 0"); | ||
| operations++; | ||
|
|
||
| getPlayer().chat("//gmask"); | ||
|
|
||
|
|
||
| Block[][][] regionBlocks = GeneratorUtils.analyzeRegion(getPlayer(), getPlayer().getWorld()); | ||
| GeneratorUtils.adjustHeight(points, regionBlocks); | ||
|
|
||
|
|
||
| // ----------- RAILWAY ---------- | ||
|
|
||
| // Draw the railway curve | ||
|
|
||
| GeneratorUtils.createConvexSelection(commands, points); | ||
| commands.add("//gmask !solid"); | ||
| commands.add("//curve 42"); | ||
| operations++; | ||
| commands.add("//gmask"); | ||
| BuildTeamTools.getInstance().getLogger().log( | ||
| Level.SEVERE, | ||
| "Rail Generator failed while generating from the WorldEdit selection.", | ||
| exception | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| private List<Vector> getControlPoints() { | ||
| RailSelectionPointReader reader = new RailSelectionPointReader(getPlayer(), getRegion()); | ||
| return reader.readControlPoints(); | ||
| } | ||
|
|
||
| // Create the railway | ||
| GeneratorUtils.createPolySelection(commands, polyRegionPoints); | ||
| private void placeRail(List<RailBlockPlacement> placements) { | ||
| boolean placedWithWorldEdit = placer.placeWithWorldEdit(this, placements, railType); | ||
|
|
||
| commands.add("//replace \"0 !>42 =queryRel(0,-1,-1,42,-1)||queryRel(0,-1,1,42,-1)\" 145:1"); | ||
| operations++; | ||
| commands.add("//replace \"0 !>42 =queryRel(-1,-1,0,42,-1)||queryRel(1,-1,0,42,-1)\" 145:0"); | ||
| operations++; | ||
| if (!placedWithWorldEdit) { | ||
| getPlayer().sendMessage("§eWorldEdit history is unavailable. Falling back to Bukkit placement."); | ||
| getPlayer().sendMessage("§eUse §6/gen undo§e instead of §6//undo§e for this generation."); | ||
|
|
||
| commands.add("//gmask =(sqrt((x-(" + xPos + "))^2+(z-(" + zPos + "))^2)%3)-2"); | ||
| commands.add("//replace \"0 =queryRel(0,0,1,145,-1)||queryRel(0,0,-1,145,-1)||queryRel(1,0,0,145,-1)||queryRel(-1,0,0,145,-1)\" 44:0"); | ||
| operations++; | ||
| commands.add("//replace \"!145 !0 <145\" 43:0"); | ||
| operations++; | ||
| commands.add("//gmask"); | ||
| commands.add("//replace 42 2"); | ||
| operations++; | ||
| List<History.BlockChange> changes = placer.placeWithBukkitFallback(this, placements, railType); | ||
|
|
||
| commands.add("//gmask"); | ||
| GeneratorModule.getInstance() | ||
| .getPlayerHistory(getPlayer()) | ||
| .addHistoryEntry(new History.HistoryEntry(GeneratorType.RAILWAY, this, changes)); | ||
|
|
||
| // Depending on the selection type, the selection needs to be restored correctly | ||
| if(getRegion() instanceof Polygonal2DRegion || getRegion() instanceof ConvexPolyhedralRegion) | ||
| GeneratorUtils.createConvexSelection(commands, points); | ||
| else if(getRegion() instanceof CuboidRegion){ | ||
| CuboidRegion cuboidRegion = (CuboidRegion) getRegion(); | ||
| Vector pos1 = new Vector(cuboidRegion.getPos1().getX(), cuboidRegion.getPos1().getY(), cuboidRegion.getPos1().getZ()); | ||
| Vector pos2 = new Vector(cuboidRegion.getPos2().getX(), cuboidRegion.getPos2().getY(), cuboidRegion.getPos2().getZ()); | ||
| GeneratorUtils.createCuboidSelection(commands, pos1, pos2); | ||
| getGeneratorComponent().sendSuccessMessage(getPlayer()); | ||
| return; | ||
| } | ||
|
|
||
| GeneratorModule.getInstance().getGeneratorCommands().add(new Command(getPlayer(), getGeneratorComponent(), commands, operations, regionBlocks)); | ||
| GeneratorModule.getInstance().getPlayerHistory(getPlayer()).addHistoryEntry(new History.HistoryEntry(GeneratorType.RAILWAY, operations));*/ | ||
| GeneratorModule.getInstance() | ||
| .getPlayerHistory(getPlayer()) | ||
| .addHistoryEntry(new History.HistoryEntry(GeneratorType.RAILWAY, this, 1)); | ||
|
|
||
| getGeneratorComponent().sendSuccessMessage(getPlayer()); | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
...ava/net/buildtheearth/buildteamtools/modules/generator/components/rail/path/RailPath.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,28 @@ | ||
| package net.buildtheearth.buildteamtools.modules.generator.components.rail.path; | ||
|
|
||
| import org.bukkit.util.Vector; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class RailPath { | ||
|
|
||
| private final List<Vector> centerPath; | ||
|
|
||
| public RailPath(List<Vector> centerPath) { | ||
| this.centerPath = new ArrayList<>(centerPath); | ||
| } | ||
|
|
||
| public List<Vector> getCenterPath() { | ||
| return Collections.unmodifiableList(centerPath); | ||
| } | ||
|
|
||
| public int size() { | ||
| return centerPath.size(); | ||
| } | ||
|
|
||
| public boolean isValid() { | ||
| return centerPath.size() >= 2; | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method name doesnt really correspond to what is checked inside