๐
1 file
7,018 chars
๐
pasted-code-1775946637154.txt
txt
153 lines
โถ
pasted-code-1775946637154.txt
txt
153 lines
Create a Paper 1.21.11 plugin (Java) called "BetterMinecarts" that overhauls
the minecart system with the following features. Use the Paper API and
Bukkit event system.
NOTE ON VERSION: Target is Paper 1.21.11. Use Paper/Bukkit API calls
consistent with the 1.21.x branch. If any API method is uncertain,
prefer the most recent 1.21.x-compatible approach.
NOTE ON BUILD TOOL: Use Gradle. Provide build.gradle with the correct
Paper 1.21.x repository and dependency. Do NOT use Maven or pom.xml.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FEATURE 1 โ TRAIN CHAINING SYSTEM
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Players can link up to 8 minecarts into a single train by right-clicking
adjacent minecarts with a Lead (Leash).
- All linked minecarts move as one unit, maintaining fixed spacing.
- The first minecart in the chain is the "locomotive" (leader).
- Passengers in any cart of the train travel together.
- Chain must handle: curves, slopes, descents, and intersections
without breaking or desynchronizing.
- Right-clicking with Lead on an already-chained cart removes the link.
- Chain breaks if any cart is destroyed.
- Chain data stored per-entity using PersistentDataContainer.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FEATURE 2 โ INCREASED SPEED
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Default vanilla max speed: 8 blocks/sec.
- New default max speed for player-ridden minecarts: 48 blocks/sec.
- Achieved by overriding minecart velocity each tick via VehicleUpdateEvent.
- Speed scales smoothly using the Acceleration Meter (see Feature 3).
- Powered rails act as speed boosters (not required for basic movement).
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FEATURE 3 โ ACCELERATION METER (HUD)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- When a player rides a minecart, replace the XP bar with an
Acceleration Meter (same mechanic as the horse jump bar).
- Use Player#sendExperienceChange() to render the bar.
- Mechanics:
* Holding W increases speed gradually up to 48 blocks/sec.
* Releasing W locks current speed (cruise control โ
cart maintains speed automatically without holding W).
* Holding S decelerates the cart gradually.
* Holding SPACE = emergency brake (immediate stop).
- Bar represents current speed visually (0% = stopped, 100% = 48 bl/s).
- Handle player input via PlayerInputEvent (Paper 1.21.x).
If PlayerInputEvent is unavailable in this API version, fall back to
reading player movement direction from Player#getVelocity() combined
with VehicleUpdateEvent each tick to detect W/S input intent.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FEATURE 4 โ REWORKED FURNACE MINECART (overhaul of existing vanilla entity)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
This is NOT a new entity. This is a complete overhaul of the existing
vanilla Furnace Minecart (EntityType.FURNACE_MINECART) to make it
useful and functional as a locomotive.
HOW IT WORKS โ STEP BY STEP:
1. PLACEMENT & ROLE:
- The Furnace Minecart must be placed at the FRONT of the train.
- It acts as the locomotive that pulls all linked carts behind it.
- Without fuel, it does not move the train at all.
2. FUELING:
- Right-click the Furnace Minecart while sneaking + holding any
valid furnace fuel item (coal, charcoal, wood, lava bucket, etc.)
to add fuel.
- Use vanilla furnace burn time values exactly:
* Lava Bucket = 20000 ticks
* Coal / Charcoal = 1600 ticks
* Wood Plank = 300 ticks
* (apply the same values as Bukkit's furnace burn time map)
- Fuel is stored in PersistentDataContainer as remaining ticks (long).
- Empty bucket is returned to player when lava bucket is consumed
(same as vanilla furnace behavior).
3. FUEL METER (HUD):
- When a player rides or stands within 3 blocks of a fueled
Furnace Minecart, display fuel status in the action bar:
"๐ฅ Fuel: [========--] 78%"
- Update the action bar every 20 ticks (1 second).
- Show "โ No Fuel โ Train Stopped" in action bar when empty.
- Keep vanilla smoke/flame particle effects intact.
4. POWERING THE TRAIN:
- While fueled, the Furnace Minecart powers the entire train
WITHOUT needing powered rails.
- Applies velocity to the lead cart each tick based on
current target speed from the Acceleration Meter.
- Fuel drain formula:
drainRate = 1.0 * (1 + (cartCount - 1) * 0.15)
* (1 + max(0, speed - 20) / 10 * 0.10)
5. SPEED BOOST WITH POWERED RAILS:
- When the Furnace Minecart passes over a powered rail while fueled,
temporarily increase max speed to 64 blocks/sec for 3 seconds.
- After 3 seconds without a powered rail, speed cap returns to 48.
6. RUNNING OUT OF FUEL:
- When fuel hits 0, the train decelerates gradually
(reduce speed by 4 bl/s per second) until fully stopped.
- Display "โ No Fuel โ Train Stopped" in action bar.
- Furnace Minecart stays on tracks โ player refuels by
right-clicking with fuel again.
7. VANILLA COMPATIBILITY:
- Visually unchanged (smoke particles, texture intact).
- Only movement logic and fueling interaction are overridden.
- A solo Furnace Minecart (not in a chain) still works as a
basic self-propelled cart.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
TECHNICAL REQUIREMENTS
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Target: Paper 1.21.11 (io.papermc.paper API, 1.21.x branch).
- Language: Java 21.
- Build tool: Gradle. Provide build.gradle only. No Maven, no pom.xml.
- No client-side mods required โ purely server-side plugin.
- No external API keys or HTTP calls in the plugin code.
All logic is self-contained using only the Paper/Bukkit API.
- Use BukkitScheduler (runTaskTimer) for per-tick velocity updates.
- config.yml must expose:
* max_speed_default: 48
* max_speed_with_powered_rails: 64
* max_chain_length: 8
* fuel_drain_multiplier: 1.0
* powered_rail_boost_duration_seconds: 3
- All 4 features toggleable individually in config.
- Events to handle: VehicleEnterEvent, VehicleExitEvent,
VehicleUpdateEvent, PlayerInteractEntityEvent, PlayerInputEvent.
- All persistent data (chain links, fuel ticks) stored in
PersistentDataContainer โ no external databases.
- Plugin must not break vanilla minecart behavior when features
are disabled in config.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
DELIVERABLE
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Provide complete plugin source code with:
- BetterMinecarts.java (main plugin class)
- ChainManager.java (train linking logic)
- SpeedManager.java (velocity overrides per tick)
- AccelerationHUD.java (XP bar input and display)
- FurnaceMinecartManager.java (fuel, drain, powering logic)
- plugin.yml
- config.yml with all defaults listed above
- build.gradle with correct Paper 1.21.x repository and dependency
- settings.gradle
Code must be clean, modular, and well-commented.
KodariApr 11 at 10:33 pm 1,079 (v2)
BetterMinecarts
A Minecraft plugin that enhances the minecart experience with advanced features including train chaining, increased speeds, an acceleration meter HUD, and an overhauled furnace minecart locomotive system. Players can link minecarts into trains, control speed with a custom HUD, and use furnace minecarts as powerful locomotives with fuel management.
๐
2 files
8,594 chars
๐
pasted-code-1775948226785.txt
txt
103 lines
โถ
pasted-code-1775948226785.txt
txt
103 lines
Fix the following two broken features in BetterMinecarts.
Do NOT rewrite anything else.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 1 โ Speed / acceleration does not work at all
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: AccelerationHUD.java โ method: detectInput()
PROBLEM: When the minecart is stationary, velocity = (0,0,0).
Calling normalize() on a zero vector produces NaN.
The check velocityDirection.lengthSquared() > 0 then fails,
so accelerating is always set to false.
Result: the player can never accelerate from standstill by pressing W.
FIX: Replace the entire detectInput() method with this:
private void detectInput(Player player, Minecart minecart) {
UUID uuid = player.getUniqueId();
Vector cartVelocity = minecart.getVelocity();
Vector lookDir = player.getLocation().getDirection().setY(0).normalize();
if (cartVelocity.lengthSquared() < 0.001) {
// Cart is stationary โ check if player is holding W by other means.
// We cannot read key input directly, so we treat any non-zero
// look direction as "ready to accelerate" and set accelerating = true
// so the cart gets an initial push from SpeedManager.
accelerating.put(uuid, true);
braking.put(uuid, false);
} else {
Vector velocityDirection = cartVelocity.clone().normalize();
double dot = lookDir.dot(velocityDirection);
accelerating.put(uuid, dot > 0.5);
braking.put(uuid, dot < -0.5);
}
}
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 2 โ Initial push when cart is stationary
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: SpeedManager.java โ method: onVehicleUpdate()
PROBLEM: Even if AccelerationHUD sets accelerating = true,
SpeedManager only scales existing velocity. If velocity is zero,
normalize() again produces NaN and nothing happens.
The cart never gets an initial impulse to start moving.
FIX: Replace the entire onVehicleUpdate() method with this:
public void onVehicleUpdate(VehicleUpdateEvent event) {
if (!plugin.getConfig().getBoolean("feature_increased_speed")) return;
Entity entity = event.getVehicle();
if (!(entity instanceof Minecart cart)) return;
if (cart.getPassengers().isEmpty()) return;
if (!(cart.getPassengers().get(0) instanceof Player player)) return;
double targetSpeed = plugin.getAccelerationHUD().getCurrentSpeed(player) / 20.0;
double maxSpeed = plugin.getConfig().getDouble("max_speed_default") / 20.0;
double clampedTarget = Math.min(targetSpeed, maxSpeed);
Vector velocity = cart.getVelocity();
if (velocity.lengthSquared() < 0.001) {
// Cart is stationary โ apply initial impulse in player's look direction
if (clampedTarget > 0) {
Vector dir = player.getLocation().getDirection().setY(0).normalize();
cart.setVelocity(dir.multiply(0.15));
}
return;
}
// Cart is moving โ scale velocity to target speed
Vector direction = velocity.clone().normalize();
cart.setVelocity(direction.multiply(clampedTarget));
}
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 3 โ XP bar grows without input
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: AccelerationHUD.java โ method: onVehicleUpdate()
PROBLEM: currentSpeed increases every tick because accelerating
is incorrectly set to true even when player is not pressing W.
After Fix 1, accelerating will correctly reflect W being held.
But additionally the speed should NOT increase when the cart
is stationary and has not yet received its first push.
FIX: Add this check before modifying currentSpeed:
// Only change speed if cart is actually moving OR player is actively braking
Vector cartVel = ((Minecart) entity).getVelocity();
boolean cartMoving = cartVel.lengthSquared() > 0.001;
if (accelerating.getOrDefault(uuid, false) && cartMoving) {
currentSpeed = Math.min(currentSpeed + 1f, (float) maxSpeed);
} else if (braking.getOrDefault(uuid, false)) {
currentSpeed = Math.max(currentSpeed - 1f, 0f);
} else if (!cartMoving) {
// Cart stopped unexpectedly (e.g. hit a wall) โ reset speed
currentSpeed = 0f;
}
Replace the existing if/else if block for accelerating/braking with the above.
๐
pasted-code-1775948233918.txt
txt
101 lines
โถ
pasted-code-1775948233918.txt
txt
101 lines
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 4 โ CRASH: Missing passenger check in FurnaceMinecartManager
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: FurnaceMinecartManager.java โ method: onVehicleUpdate()
PROBLEM: This line runs BEFORE the passengers isEmpty() check:
double speed = plugin.getAccelerationHUD().getCurrentSpeed((Player) furnace.getPassengers().get(0));
If Furnace Minecart has no passengers โ IndexOutOfBoundsException crash.
Also no instanceof Player check before cast.
FIX: Move ALL passenger-dependent logic inside the isEmpty() check block.
Add instanceof guard:
if (furnace.getPassengers().isEmpty()) return;
if (!(furnace.getPassengers().get(0) instanceof Player player)) return;
Then use player variable for everything below.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 5 โ CRASH: Fuel bar crash when fuel > 20000
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: FurnaceMinecartManager.java โ method: updateFuelHUD()
PROBLEM: If player adds multiple fuel items, fuel > 20000.
percent > 100, then "-".repeat(10 - percent/10) gets negative
argument โ IllegalArgumentException crash.
FIX: Clamp percent before building the bar:
int percent = (int) Math.min(100, Math.max(0, (fuel * 100.0) / maxFuel));
int filled = percent / 10;
int empty = 10 - filled;
String bar = "๐ฅ Fuel: [" + "โ".repeat(filled) + "-".repeat(empty) + "] " + percent + "%";
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 6 โ CRASH: Cast to Player without instanceof in AccelerationHUD
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: AccelerationHUD.java โ methods: onVehicleEnter(), onVehicleExit()
PROBLEM: Both methods cast directly to Player without checking.
If a mob enters the minecart โ ClassCastException crash.
FIX: Add instanceof check in both methods:
if (!(event.getEntered() instanceof Player player)) return;
if (!(event.getExited() instanceof Player player)) return;
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 7 โ LAG: getWorld().getEntities() called every tick
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: ChainManager.java โ methods: getChainLength(), onVehicleUpdate()
PROBLEM: Both methods scan ALL entities in the world every tick.
At 20 ticks/sec with multiple minecarts this kills server TPS.
FIX: Add an in-memory cache to ChainManager:
private final Map> chainMembers = new HashMap<>();
Populate it in onPlayerInteractEntity() when carts are linked/unlinked.
In getChainLength() and onVehicleUpdate(), look up UUIDs from this map
and resolve them with plugin.getServer().getEntity(uuid) which is O(1).
Clean up null/invalid entities lazily when encountered.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 8 โ LAG: getOnlinePlayers() distance check every tick
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: FurnaceMinecartManager.java โ method: onVehicleUpdate()
PROBLEM: Every tick iterates all online players and calculates
distance manually. Slow at 50+ players.
FIX: Replace with:
for (Entity nearby : furnace.getNearbyEntities(3, 3, 3)) {
if (nearby instanceof Player player) {
updateFuelHUD(player, furnace);
}
}
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 9 โ CRASH RISK: Destroyed minecart not removed from chain
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: ChainManager.java + MinecartListener.java
PROBLEM: When a chained minecart is destroyed, other carts still
hold its UUID in PDC causing silent nulls and broken chain state.
FIX: Add to MinecartListener.java:
@EventHandler
public void onVehicleDestroy(VehicleDestroyEvent event) {
plugin.getChainManager().onVehicleDestroy(event);
}
Add to ChainManager.java:
public void onVehicleDestroy(VehicleDestroyEvent event) {
if (!(event.getVehicle() instanceof Minecart minecart)) return;
PersistentDataContainer pdc = minecart.getPersistentDataContainer();
if (!pdc.has(CHAIN_KEY, PersistentDataType.STRING)) return;
String chainId = pdc.get(CHAIN_KEY, PersistentDataType.STRING);
// Remove from in-memory cache (Fix 7)
Set members = chainMembers.get(chainId);
if (members != null) {
members.remove(minecart.getUniqueId());
if (members.isEmpty()) chainMembers.remove(chainId);
}
}
KodariApr 11 at 10:57 pm 1,554 (v2)
Applied all the fixes as specified. The changes address crashes from missing checks, performance issues from scanning all entities every tick, and logic bugs in acceleration and speed handling.
๐
1 file
11,324 chars
๐
pasted-code-1775985801741.txt
txt
281 lines
โถ
pasted-code-1775985801741.txt
txt
281 lines
Fix the following bugs in BetterMinecarts. Do NOT rewrite anything
else โ fix only what is listed below. Keep all existing class names,
method signatures, and config keys exactly as-is.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 1 โ CRASH: Missing instanceof Player in AccelerationHUD.onVehicleUpdate
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: AccelerationHUD.java โ method: onVehicleUpdate()
PROBLEM:
Player player = (Player) entity.getPassengers().get(0);
No instanceof check. If a mob is in the minecart โ ClassCastException crash.
FIX: Replace that line with:
if (!(entity.getPassengers().get(0) instanceof Player player)) return;
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 2 โ CRASH + BROKEN + LAG + EDGE CASE:
Complete rewrite of onPlayerInteractEntity() in ChainManager
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: ChainManager.java โ method: onPlayerInteractEntity()
PROBLEMS in current code:
A) When linking two carts, target never gets POSITION_KEY = 0.
onVehicleUpdate() searches for leader by position == 0 and never
finds it. Chain movement is completely broken.
B) Target cart UUID is never added to chainMembers cache.
getChainLength() returns 1 instead of actual chain size.
C) Unchain branch still calls minecart.getWorld().getEntities()
which scans ALL world entities โ severe lag at scale.
D) Link branch calls minecart.getWorld().getEntities() to find maxPos
instead of using the chainMembers cache.
E) No check preventing two Furnace Minecarts in one chain.
F) Lead is consumed even when chain is full (no slot available).
FIX: Replace the entire onPlayerInteractEntity() method with this:
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (!plugin.getConfig().getBoolean("feature_train_chaining")) return;
Player player = event.getPlayer();
Entity entity = event.getRightClicked();
if (!(entity instanceof Minecart minecart)) return;
ItemStack item = player.getInventory().getItemInMainHand();
if (item.getType() != Material.LEAD) return;
event.setCancelled(true);
PersistentDataContainer pdc = minecart.getPersistentDataContainer();
// --- UNLINK ---
if (pdc.has(CHAIN_KEY, PersistentDataType.STRING)) {
String chainId = pdc.get(CHAIN_KEY, PersistentDataType.STRING);
int removedPosition = pdc.get(POSITION_KEY, PersistentDataType.INTEGER);
pdc.remove(CHAIN_KEY);
pdc.remove(POSITION_KEY);
Set members = chainMembers.get(chainId);
if (members != null) {
members.remove(minecart.getUniqueId());
// Shift positions of remaining carts above removed position
for (UUID id : new HashSet<>(members)) {
Entity e = plugin.getServer().getEntity(id);
if (e instanceof Minecart m) {
PersistentDataContainer epdc = m.getPersistentDataContainer();
Integer pos = epdc.get(POSITION_KEY, PersistentDataType.INTEGER);
if (pos != null && pos > removedPosition) {
epdc.set(POSITION_KEY, PersistentDataType.INTEGER, pos - 1);
}
} else {
members.remove(id); // clean up dead UUID
}
}
if (members.isEmpty()) chainMembers.remove(chainId);
}
player.sendMessage("Minecart unlinked from chain.");
return;
}
// --- LINK ---
Minecart target = findAdjacentMinecart(minecart);
if (target == null) {
player.sendMessage("No adjacent minecart found within 2 blocks.");
return;
}
PersistentDataContainer tpdc = target.getPersistentDataContainer();
// Determine or create chain ID from target
String chainId = tpdc.has(CHAIN_KEY, PersistentDataType.STRING)
? tpdc.get(CHAIN_KEY, PersistentDataType.STRING)
: UUID.randomUUID().toString();
Set members = chainMembers.computeIfAbsent(chainId, k -> new HashSet<>());
// Check chain length limit
if (members.size() >= plugin.getConfig().getInt("max_chain_length")) {
player.sendMessage("Chain is full! Maximum "
+ plugin.getConfig().getInt("max_chain_length") + " carts.");
return;
}
// Prevent two Furnace Minecarts in one chain
if (minecart.getType() == org.bukkit.entity.EntityType.FURNACE_MINECART) {
for (UUID id : members) {
Entity e = plugin.getServer().getEntity(id);
if (e != null && e.getType() == org.bukkit.entity.EntityType.FURNACE_MINECART) {
player.sendMessage("A chain can only have one Furnace Minecart!");
return;
}
}
}
// If target is not yet in any chain, assign it as leader (position 0)
if (!tpdc.has(CHAIN_KEY, PersistentDataType.STRING)) {
tpdc.set(CHAIN_KEY, PersistentDataType.STRING, chainId);
tpdc.set(POSITION_KEY, PersistentDataType.INTEGER, 0);
members.add(target.getUniqueId());
}
// Assign clicked cart as next position
int nextPos = members.size(); // already includes target
pdc.set(CHAIN_KEY, PersistentDataType.STRING, chainId);
pdc.set(POSITION_KEY, PersistentDataType.INTEGER, nextPos);
members.add(minecart.getUniqueId());
item.setAmount(item.getAmount() - 1);
player.sendMessage("Minecarts linked! Chain length: " + members.size());
}
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 3 โ MEMORY LEAK + CRASH RISK:
Dead UUID cleanup in onVehicleUpdate() in ChainManager
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: ChainManager.java โ method: onVehicleUpdate()
PROBLEM: Current null check runs AFTER instanceof so it never fires:
Entity e = plugin.getServer().getEntity(id);
if (e instanceof Minecart m && e != minecart) {
if (e == null) { // โ never reached, instanceof already checked e
Dead UUIDs accumulate in chainMembers forever (memory leak).
Also: epdc.get(POSITION_KEY) can return null if PDC is missing the key,
and unboxing null Integer to int causes NullPointerException.
FIX: Replace the leader-finding loop with:
Minecart leader = null;
Set toRemove = new HashSet<>();
for (UUID id : members) {
Entity e = plugin.getServer().getEntity(id);
if (e == null || !e.isValid()) {
toRemove.add(id);
continue;
}
if (!(e instanceof Minecart m) || e.equals(minecart)) continue;
Integer pos = m.getPersistentDataContainer()
.get(POSITION_KEY, PersistentDataType.INTEGER);
if (pos != null && pos == 0) {
leader = m;
break;
}
}
members.removeAll(toRemove);
if (members.isEmpty()) chainMembers.remove(chainId);
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 4 โ LAG: findAdjacentMinecart scans all world entities
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: ChainManager.java โ method: findAdjacentMinecart()
PROBLEM:
for (Entity e : minecart.getWorld().getEntities()) {
Scans every entity on the entire world. Called on every link interaction.
FIX: Replace entire method with:
private Minecart findAdjacentMinecart(Minecart minecart) {
for (Entity e : minecart.getNearbyEntities(2, 2, 2)) {
if (e instanceof Minecart m && !e.equals(minecart)) {
return m;
}
}
return null;
}
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 5 โ WRONG BEHAVIOR: Cart always accelerates, no cruise control
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: AccelerationHUD.java โ method: detectInput()
PROBLEM: dot > 0.5 is true any time the player faces roughly forward,
which is always while riding normally. The cart accelerates non-stop
to max speed with no way to hold a steady speed.
FIX: Replace the moving branch with tighter thresholds:
} else {
Vector velocityDirection = cartVelocity.clone().normalize();
double dot = lookDir.dot(velocityDirection);
accelerating.put(uuid, dot > 0.85); // sharply forward = accelerate
braking.put(uuid, dot < -0.5); // facing backward = brake
// between -0.5 and 0.85 = cruise, no change
}
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 6 โ EDGE CASE: Initial impulse ignores track slope
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: SpeedManager.java โ method: onVehicleUpdate()
PROBLEM:
Vector dir = player.getLocation().getDirection().setY(0).normalize();
setY(0) removes vertical component. On sloped tracks the cart gets a
purely horizontal push and may derail on start.
FIX: Replace those two lines with:
Vector dir = player.getLocation().getDirection();
dir.setY(Math.max(dir.getY(), -0.1));
if (dir.lengthSquared() > 0) dir.normalize();
cart.setVelocity(dir.multiply(0.15));
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 7 โ FurnaceMinecartManager: velocity not applied when stationary
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: FurnaceMinecartManager.java โ method: onVehicleUpdate()
PROBLEM: Apply velocity section does:
Vector direction = furnace.getVelocity().clone().normalize();
if (direction.lengthSquared() > 0) { ...
When Furnace Minecart is stationary, velocity = (0,0,0), normalize()
gives NaN, lengthSquared() = 0, condition is false โ no velocity applied
ever. Furnace Minecart can never start moving on its own.
FIX: Replace the "Apply velocity" block with:
Vector currentVel = furnace.getVelocity();
if (currentVel.lengthSquared() < 0.001) {
// Stationary โ apply initial impulse in player's look direction
Vector dir = player.getLocation().getDirection();
dir.setY(Math.max(dir.getY(), -0.1));
if (dir.lengthSquared() > 0) dir.normalize();
furnace.setVelocity(dir.multiply(0.15));
} else {
// Moving โ scale to target speed
Vector direction = currentVel.clone().normalize();
furnace.setVelocity(direction.multiply(
Math.min(targetSpeed, maxSpeed / 20.0)));
}
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 8 โ build.gradle: wrong Paper API version
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: build.gradle
PROBLEM: Uses 1.21.1-R0.1-SNAPSHOT.
FIX: Change dependency to:
compileOnly 'io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT'
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
FIX 9 โ plugin.yml: api-version too low
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File: plugin.yml
FIX: Change:
api-version: '1.21'
To:
api-version: '1.21.11'
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
GENERAL REQUIREMENTS
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Do NOT change any method signatures, class names, or config keys.
- Do NOT introduce new dependencies or libraries.
- Do NOT touch any code not mentioned above.
- Apply all fixes to the same file simultaneously โ do not apply
them sequentially in separate passes.
- Provide the complete updated source for every file that was modified.
- Add import java.util.HashSet to ChainManager.java if not already present.
KodariApr 12 at 9:24 am 1,215 (v2)
All specified bugs have been fixed in the respective files.
Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
10 662
src/main/java/com/example/betterminecarts/BetterMinecarts.java
package com.example.betterminecarts;
import lombok.Getter;
import org.bukkit.plugin.java.JavaPlugin;
public class BetterMinecarts extends JavaPlugin {
@Getter private ChainManager chainManager;
@Getter private SpeedManager speedManager;
@Getter private AccelerationHUD accelerationHUD;
@Getter private FurnaceMinecartManager furnaceMinecartManager;
@Override
public void onEnable() {
saveDefaultConfig();
chainManager = new ChainManager(this);
speedManager = new SpeedManager(this);
accelerationHUD = new AccelerationHUD(this);
furnaceMinecartManager = new FurnaceMinecartManager(this);
getServer().getPluginManager().registerEvents(new MinecartListener(this), this);
}
@Override
public void onDisable() {
}
}