mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
162 lines
7.7 KiB
Diff
162 lines
7.7 KiB
Diff
From 930e24e2321f18937f9b6fe97d2bfec91a26bc96 Mon Sep 17 00:00:00 2001
|
|
From: William Blake Galbreath <blake.galbreath@gmail.com>
|
|
Date: Sat, 29 Jun 2019 02:32:40 -0500
|
|
Subject: [PATCH] Controllable Minecarts
|
|
|
|
---
|
|
.../java/net/minecraft/server/Entity.java | 1 +
|
|
.../server/EntityMinecartAbstract.java | 38 +++++++++++++++++++
|
|
.../net/minecraft/server/ItemMinecart.java | 8 ++--
|
|
.../net/pl3x/purpur/PurpurWorldConfig.java | 32 ++++++++++++++++
|
|
4 files changed, 76 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
|
index 43d73385e..4333ca032 100644
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
|
@@ -1334,6 +1334,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
|
this.inLava = true;
|
|
}
|
|
|
|
+ public boolean isInLava() { return aH(); } // Purpur - OBFHELPER
|
|
public boolean aH() {
|
|
return this.inLava;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/EntityMinecartAbstract.java b/src/main/java/net/minecraft/server/EntityMinecartAbstract.java
|
|
index 665bbe07f..1f3e5bd28 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityMinecartAbstract.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityMinecartAbstract.java
|
|
@@ -357,12 +357,50 @@ public abstract class EntityMinecartAbstract extends Entity {
|
|
|
|
public void a(int i, int j, int k, boolean flag) {}
|
|
|
|
+ // Purpur start
|
|
+ public double getControllableSpeed() {
|
|
+ BlockPosition position = new BlockPosition(this);
|
|
+ Block block = world.getType(position).getBlock();
|
|
+ if (!block.material.isSolid()) {
|
|
+ block = world.getType(position.shift(EnumDirection.DOWN)).getBlock();
|
|
+ }
|
|
+ Double speed = world.purpurConfig.controllableMinecartsBlockSpeeds.get(block);
|
|
+ if (speed == null) {
|
|
+ speed = world.purpurConfig.controllableMinecartsBaseSpeed;
|
|
+ }
|
|
+ return speed;
|
|
+ }
|
|
+ // Purpur end
|
|
+
|
|
protected void i() {
|
|
double d0 = this.getMaxSpeed();
|
|
Vec3D vec3d = this.getMot();
|
|
|
|
this.setMot(MathHelper.a(vec3d.x, -d0, d0), vec3d.y, MathHelper.a(vec3d.z, -d0, d0));
|
|
if (this.onGround) {
|
|
+ // Purpur start
|
|
+ if (world.purpurConfig.controllableMinecarts && !isInWater() && !isInLava() && !passengers.isEmpty()) {
|
|
+ Entity passenger = passengers.get(0);
|
|
+ if (passenger instanceof EntityHuman) {
|
|
+ EntityHuman entityhuman = (EntityHuman) passenger;
|
|
+ if (entityhuman.jumping) {
|
|
+ Vec3D mot = getMot();
|
|
+ setMot(mot.x, world.purpurConfig.controllableMinecartsHopBoost, mot.z);
|
|
+ }
|
|
+ if (entityhuman.getForward() != 0.0F) {
|
|
+ Vector dir = entityhuman.getBukkitEntity().getEyeLocation().getDirection().normalize().multiply(getControllableSpeed());
|
|
+ if (entityhuman.getForward() < 0.0) {
|
|
+ dir.multiply(-0.5);
|
|
+ }
|
|
+ setMot(new Vec3D(dir.getX(), getMot().y, dir.getZ()));
|
|
+ setStepHeight(world.purpurConfig.controllableMinecartsStepHeight);
|
|
+ } else {
|
|
+ setStepHeight(0.0F);
|
|
+ }
|
|
+ this.yaw = passenger.yaw - 90;
|
|
+ }
|
|
+ }
|
|
+ // Purpur end
|
|
// CraftBukkit start - replace magic numbers with our variables
|
|
this.setMot(new Vec3D(this.getMot().x * this.derailedX, this.getMot().y * this.derailedY, this.getMot().z * this.derailedZ));
|
|
// CraftBukkit end
|
|
diff --git a/src/main/java/net/minecraft/server/ItemMinecart.java b/src/main/java/net/minecraft/server/ItemMinecart.java
|
|
index b73e317fb..e1337a9c0 100644
|
|
--- a/src/main/java/net/minecraft/server/ItemMinecart.java
|
|
+++ b/src/main/java/net/minecraft/server/ItemMinecart.java
|
|
@@ -103,8 +103,10 @@ public class ItemMinecart extends Item {
|
|
IBlockData iblockdata = world.getType(blockposition);
|
|
|
|
if (!iblockdata.a(TagsBlock.RAILS)) {
|
|
- return EnumInteractionResult.FAIL;
|
|
- } else {
|
|
+ // Purpur start - place minecarts anywhere
|
|
+ if (!world.purpurConfig.controllableMinecartsPlaceAnywhere) return EnumInteractionResult.FAIL;
|
|
+ if (iblockdata.getMaterial().isSolid()) blockposition = blockposition.shift(itemactioncontext.getClickedFace());
|
|
+ } //else { // Purpur end - place minecarts anywhere
|
|
ItemStack itemstack = itemactioncontext.getItemStack();
|
|
|
|
if (!world.isClientSide) {
|
|
@@ -131,6 +133,6 @@ public class ItemMinecart extends Item {
|
|
|
|
itemstack.subtract(1);
|
|
return EnumInteractionResult.SUCCESS;
|
|
- }
|
|
+ //} // Purpur - place minecarts anywhere
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
index 85eaf1a7a..dfa631803 100644
|
|
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
@@ -1,10 +1,16 @@
|
|
package net.pl3x.purpur;
|
|
|
|
import com.destroystokyo.paper.PaperWorldConfig;
|
|
+import net.minecraft.server.Block;
|
|
+import net.minecraft.server.Blocks;
|
|
+import net.minecraft.server.IRegistry;
|
|
+import net.minecraft.server.MinecraftKey;
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
import org.spigotmc.SpigotWorldConfig;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
+import java.util.Map;
|
|
|
|
import static net.pl3x.purpur.PurpurConfig.log;
|
|
|
|
@@ -84,6 +90,32 @@ public class PurpurWorldConfig {
|
|
turtleEggsBreakFromMinecarts = getBoolean("blocks.turtle_egg.break-from-minecarts", turtleEggsBreakFromMinecarts);
|
|
}
|
|
|
|
+ public boolean controllableMinecarts = false;
|
|
+ public boolean controllableMinecartsPlaceAnywhere = false;
|
|
+ public float controllableMinecartsStepHeight = 1.0F;
|
|
+ public double controllableMinecartsHopBoost = 0.5D;
|
|
+ public double controllableMinecartsBaseSpeed = 0.1D;
|
|
+ public Map<Block, Double> controllableMinecartsBlockSpeeds = new HashMap<>();
|
|
+ private void gameplayMechanicsSettings() {
|
|
+ controllableMinecarts = getBoolean("gameplay-mechanics.controllable-minecarts.enabled", controllableMinecarts);
|
|
+ controllableMinecartsPlaceAnywhere = getBoolean("gameplay-mechanics.controllable-minecarts.place-anywhere", controllableMinecartsPlaceAnywhere);
|
|
+ controllableMinecartsStepHeight = (float) getDouble("gameplay-mechanics.controllable-minecarts.step-height", controllableMinecartsStepHeight);
|
|
+ controllableMinecartsHopBoost = getDouble("gameplay-mechanics.controllable-minecarts.hop-boost", controllableMinecartsHopBoost);
|
|
+ controllableMinecartsBaseSpeed = getDouble("gameplay-mechanics.controllable-minecarts.base-speed", controllableMinecartsBaseSpeed);
|
|
+ ConfigurationSection section = getConfigurationSection("gameplay-mechanics.controllable-minecarts.block-speed");
|
|
+ if (section != null) {
|
|
+ for (String key : section.getKeys(false)) {
|
|
+ Block block = IRegistry.BLOCK.get(new MinecraftKey(key));
|
|
+ if (block != Blocks.AIR) {
|
|
+ controllableMinecartsBlockSpeeds.put(block, section.getDouble(key, controllableMinecartsBaseSpeed));
|
|
+ }
|
|
+ }
|
|
+ } else {
|
|
+ set("gameplay-mechanics.controllable-minecarts.block-speed.grass-block", 0.3D);
|
|
+ set("gameplay-mechanics.controllable-minecarts.block-speed.stone", 0.5D);
|
|
+ }
|
|
+ }
|
|
+
|
|
public boolean batRidable = false;
|
|
public boolean batRidableInWater = false;
|
|
public boolean batRequireShiftToMount = true;
|
|
--
|
|
2.24.0
|
|
|