0.2.0
Fixed: - Issues with hills - version
This commit is contained in:
1 parent
d483571b9a
commit
0d10c30445
8 files changed
+117
-7
No files matched your search
Generated
+5
@@ -6,6 +6,11 @@
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="spigotmc-repo" />
|
||||
<option name="name" value="spigotmc-repo" />
|
||||
<option name="url" value="https://hub.spigotmc.org/nexus/content/repositories/snapshots/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="papermc-repo" />
|
||||
<option name="name" value="papermc-repo" />
|
||||
|
||||
Generated
+1
-1
@@ -8,7 +8,7 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="ms-21" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" project-jdk-name="25" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
<groupId>com.rsscripting</groupId>
|
||||
<artifactId>RS-FasterMinecarts</artifactId>
|
||||
<version>0.1.0</version>
|
||||
<version>0.2.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<maven.compiler.release>25</maven.compiler.release>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.21.10-R0.1-SNAPSHOT</version>
|
||||
<version>26.1.2.build.63-stable</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@@ -35,13 +35,20 @@
|
||||
<build>
|
||||
<finalName>RS-FasterMinecarts-0-1-0</finalName>
|
||||
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.14.1</version>
|
||||
<configuration>
|
||||
<release>21</release>
|
||||
<release>25</release>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.rsscripting.rsfasterminecarts;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Rail;
|
||||
import org.bukkit.entity.Minecart;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||
import org.bukkit.event.vehicle.VehicleMoveEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -33,7 +36,6 @@ public class MinecartListener implements Listener {
|
||||
|
||||
UUID minecartId = minecart.getUniqueId();
|
||||
|
||||
// Do not multiply an already modified minecart.
|
||||
if (originalSpeeds.containsKey(minecartId)) {
|
||||
return;
|
||||
}
|
||||
@@ -46,6 +48,102 @@ public class MinecartListener implements Listener {
|
||||
minecart.setMaxSpeed(originalSpeed * multiplier);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVehicleMove(VehicleMoveEvent event) {
|
||||
|
||||
if (!(event.getVehicle() instanceof Minecart minecart)) {
|
||||
return;
|
||||
}
|
||||
|
||||
UUID minecartId = minecart.getUniqueId();
|
||||
|
||||
Double originalSpeed = originalSpeeds.get(minecartId);
|
||||
|
||||
if (originalSpeed == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block currentBlock = event.getTo().getBlock();
|
||||
|
||||
Rail currentRail = getRail(currentBlock);
|
||||
|
||||
if (currentRail == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean onHill = isAscending(currentRail);
|
||||
|
||||
if (onHill) {
|
||||
minecart.setMaxSpeed(originalSpeed);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean approachingHill = isApproachingHill(minecart, currentBlock);
|
||||
|
||||
if (approachingHill) {
|
||||
minecart.setMaxSpeed(originalSpeed);
|
||||
return;
|
||||
}
|
||||
|
||||
double multiplier = plugin.getConfig().getDouble("max-speed", 3.0);
|
||||
|
||||
minecart.setMaxSpeed(originalSpeed * multiplier);
|
||||
}
|
||||
|
||||
private Rail getRail(Block block) {
|
||||
|
||||
if (block.getBlockData() instanceof Rail rail) {
|
||||
return rail;
|
||||
}
|
||||
|
||||
Block below = block.getRelative(0, -1, 0);
|
||||
|
||||
if (below.getBlockData() instanceof Rail rail) {
|
||||
return rail;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isAscending(Rail rail) {
|
||||
|
||||
return rail.getShape() == Rail.Shape.ASCENDING_EAST
|
||||
|| rail.getShape() == Rail.Shape.ASCENDING_WEST
|
||||
|| rail.getShape() == Rail.Shape.ASCENDING_NORTH
|
||||
|| rail.getShape() == Rail.Shape.ASCENDING_SOUTH;
|
||||
}
|
||||
|
||||
private boolean isApproachingHill(Minecart minecart, Block currentBlock) {
|
||||
|
||||
Rail currentRail = getRail(currentBlock);
|
||||
|
||||
if (currentRail == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Rail.Shape shape = currentRail.getShape();
|
||||
|
||||
if (shape != Rail.Shape.NORTH_SOUTH
|
||||
&& shape != Rail.Shape.EAST_WEST) {
|
||||
return false;
|
||||
}
|
||||
|
||||
double x = minecart.getVelocity().getX();
|
||||
double z = minecart.getVelocity().getZ();
|
||||
|
||||
Block nextBlock;
|
||||
|
||||
if (Math.abs(x) > Math.abs(z)) {
|
||||
nextBlock = currentBlock.getRelative(x > 0 ? 1 : -1, 0, 0);
|
||||
} else {
|
||||
nextBlock = currentBlock.getRelative(0, 0, z > 0 ? 1 : -1);
|
||||
}
|
||||
|
||||
Rail nextRail = getRail(nextBlock);
|
||||
|
||||
return nextRail != null && isAscending(nextRail);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVehicleExit(VehicleExitEvent event) {
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
name: RS-FasterMinecarts
|
||||
version: ${project.version}
|
||||
version: 0.1.0
|
||||
main: com.rsscripting.rsfasterminecarts.RSFasterMinecarts
|
||||
api-version: '1.21'
|
||||
description: Increases the maximum speed of player-occupied minecarts.
|
||||
|
||||
Reference in new issue
Block a user