-
-
Notifications
You must be signed in to change notification settings - Fork 479
Expand file tree
/
Copy path0040-Minecart-settings-and-WASD-controls.patch
More file actions
223 lines (208 loc) · 12.7 KB
/
Copy path0040-Minecart-settings-and-WASD-controls.patch
File metadata and controls
223 lines (208 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
From 0000000000000000000000000000000000000000 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] Minecart settings and WASD controls
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 387e2423d820e4df1d226ce6159a361d6a808fd9..e2e25a4ac86156f0915a0b9886a6f62b2812920b 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -1111,6 +1111,7 @@ public class ServerPlayer extends Player {
if (this.isInvulnerableTo(source)) {
return false;
} else {
+ if (source.is(DamageTypeTags.IS_FALL) && getRootVehicle() instanceof net.minecraft.world.entity.vehicle.AbstractMinecart && level().purpurConfig.minecartControllable && !level().purpurConfig.minecartControllableFallDamage) return false; // Purpur
boolean flag = this.server.isDedicatedServer() && this.isPvpAllowed() && source.is(DamageTypeTags.IS_FALL);
if (!flag && this.spawnInvulnerableTime > 0 && !source.is(DamageTypeTags.BYPASSES_INVULNERABILITY)) {
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
index c906ca07509939a06b9aaf2da0dafb172830a638..d5e2797b392527de4027b20f29c73a16eb0d6af9 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
@@ -105,12 +105,14 @@ public abstract class AbstractMinecart extends VehicleEntity {
private double flyingY = 0.95;
private double flyingZ = 0.95;
public double maxSpeed = 0.4D;
+ public double storedMaxSpeed; // Purpur
// CraftBukkit end
protected AbstractMinecart(EntityType<?> type, Level world) {
super(type, world);
this.targetDeltaMovement = Vec3.ZERO;
this.blocksBuilding = true;
+ if (world != null) maxSpeed = storedMaxSpeed = world.purpurConfig.minecartMaxSpeed; // Purpur
}
protected AbstractMinecart(EntityType<?> type, Level world, double x, double y, double z) {
@@ -294,6 +296,12 @@ public abstract class AbstractMinecart extends VehicleEntity {
@Override
public void tick() {
+ // Purpur start
+ if (storedMaxSpeed != level().purpurConfig.minecartMaxSpeed) {
+ maxSpeed = storedMaxSpeed = level().purpurConfig.minecartMaxSpeed;
+ }
+ // Purpur end
+
// CraftBukkit start
double prevX = this.getX();
double prevY = this.getY();
@@ -451,16 +459,62 @@ public abstract class AbstractMinecart extends VehicleEntity {
public void activateMinecart(int x, int y, int z, boolean powered) {}
+ // Purpur start
+ private Double lastSpeed;
+
+ public double getControllableSpeed() {
+ BlockState blockState = level().getBlockState(this.blockPosition());
+ if (!blockState.isSolid()) {
+ blockState = level().getBlockState(this.blockPosition().relative(Direction.DOWN));
+ }
+ Double speed = level().purpurConfig.minecartControllableBlockSpeeds.get(blockState.getBlock());
+ if (!blockState.isSolid()) {
+ speed = lastSpeed;
+ }
+ if (speed == null) {
+ speed = level().purpurConfig.minecartControllableBaseSpeed;
+ }
+ return lastSpeed = speed;
+ }
+ // Purpur end
+
protected void comeOffTrack() {
double d0 = this.getMaxSpeed();
Vec3 vec3d = this.getDeltaMovement();
this.setDeltaMovement(Mth.clamp(vec3d.x, -d0, d0), vec3d.y, Mth.clamp(vec3d.z, -d0, d0));
+
+ // Purpur start
+ if (level().purpurConfig.minecartControllable && !isInWater() && !isInLava() && !passengers.isEmpty()) {
+ Entity passenger = passengers.get(0);
+ if (passenger instanceof Player) {
+ Player player = (Player) passenger;
+ if (player.jumping && this.onGround) {
+ setDeltaMovement(new Vec3(getDeltaMovement().x, level().purpurConfig.minecartControllableHopBoost, getDeltaMovement().z));
+ }
+ if (player.zza != 0.0F) {
+ Vector velocity = player.getBukkitEntity().getEyeLocation().getDirection().normalize().multiply(getControllableSpeed());
+ if (player.zza < 0.0) {
+ velocity.multiply(-0.5);
+ }
+ setDeltaMovement(new Vec3(velocity.getX(), getDeltaMovement().y, velocity.getZ()));
+ }
+ this.setYRot(passenger.getYRot() - 90);
+ maxUpStep = level().purpurConfig.minecartControllableStepHeight;
+ } else {
+ maxUpStep = 0.0F;
+ }
+ } else {
+ maxUpStep = 0.0F;
+ }
+ // Purpur end
+
if (this.onGround()) {
// CraftBukkit start - replace magic numbers with our variables
this.setDeltaMovement(new Vec3(this.getDeltaMovement().x * this.derailedX, this.getDeltaMovement().y * this.derailedY, this.getDeltaMovement().z * this.derailedZ));
// CraftBukkit end
}
+ else if (level().purpurConfig.minecartControllable) setDeltaMovement(new Vec3(getDeltaMovement().x * derailedX, getDeltaMovement().y, getDeltaMovement().z * derailedZ)); // Purpur
this.move(MoverType.SELF, this.getDeltaMovement());
if (!this.onGround()) {
diff --git a/src/main/java/net/minecraft/world/item/MinecartItem.java b/src/main/java/net/minecraft/world/item/MinecartItem.java
index 3aa73cd44aa8c86b78c35bc1788e4f83018c49ed..66a8b28275619079e3bcbcc460146976d533d54e 100644
--- a/src/main/java/net/minecraft/world/item/MinecartItem.java
+++ b/src/main/java/net/minecraft/world/item/MinecartItem.java
@@ -119,8 +119,9 @@ public class MinecartItem extends Item {
BlockState iblockdata = world.getBlockState(blockposition);
if (!iblockdata.is(BlockTags.RAILS)) {
- return InteractionResult.FAIL;
- } else {
+ if (!world.purpurConfig.minecartPlaceAnywhere) return InteractionResult.FAIL;
+ if (iblockdata.isSolid()) blockposition = blockposition.relative(context.getClickedFace());
+ } // else { // Purpur - place minecarts anywhere
ItemStack itemstack = context.getItemInHand();
if (world instanceof ServerLevel) {
@@ -145,6 +146,6 @@ public class MinecartItem extends Item {
itemstack.shrink(1);
return InteractionResult.sidedSuccess(world.isClientSide);
- }
+ // } // Purpur - place minecarts anywhere
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
index 3ab8b99837b1d1faea722c598b0228b2780be8b1..06b07927aba82084bd2996be92b9e340a9bf2ad2 100644
--- a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
@@ -93,7 +93,7 @@ public abstract class BlockBehaviour implements FeatureElement {
protected final float jumpFactor;
protected final boolean dynamicShape;
protected final FeatureFlagSet requiredFeatures;
- protected final BlockBehaviour.Properties properties;
+ public final BlockBehaviour.Properties properties; // Purpur - protected -> public
@Nullable
protected ResourceLocation drops;
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
index ae393a6c34e79ea3ac0f4a17792f296f18c3f06b..269fa073b53b5434d19d6705eb2fb2d0550ba0ac 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
@@ -95,6 +95,68 @@ public class PurpurWorldConfig {
armorstandStepHeight = (float) getDouble("gameplay-mechanics.armorstand.step-height", armorstandStepHeight);
}
+ public double minecartMaxSpeed = 0.4D;
+ public boolean minecartPlaceAnywhere = false;
+ public boolean minecartControllable = false;
+ public float minecartControllableStepHeight = 1.0F;
+ public double minecartControllableHopBoost = 0.5D;
+ public boolean minecartControllableFallDamage = true;
+ public double minecartControllableBaseSpeed = 0.1D;
+ public Map<Block, Double> minecartControllableBlockSpeeds = new HashMap<>();
+ private void minecartSettings() {
+ if (PurpurConfig.version < 12) {
+ boolean oldBool = getBoolean("gameplay-mechanics.controllable-minecarts.place-anywhere", minecartPlaceAnywhere);
+ set("gameplay-mechanics.controllable-minecarts.place-anywhere", null);
+ set("gameplay-mechanics.minecart.place-anywhere", oldBool);
+ oldBool = getBoolean("gameplay-mechanics.controllable-minecarts.enabled", minecartControllable);
+ set("gameplay-mechanics.controllable-minecarts.enabled", null);
+ set("gameplay-mechanics.minecart.controllable.enabled", oldBool);
+ double oldDouble = getDouble("gameplay-mechanics.controllable-minecarts.step-height", minecartControllableStepHeight);
+ set("gameplay-mechanics.controllable-minecarts.step-height", null);
+ set("gameplay-mechanics.minecart.controllable.step-height", oldDouble);
+ oldDouble = getDouble("gameplay-mechanics.controllable-minecarts.hop-boost", minecartControllableHopBoost);
+ set("gameplay-mechanics.controllable-minecarts.hop-boost", null);
+ set("gameplay-mechanics.minecart.controllable.hop-boost", oldDouble);
+ oldBool = getBoolean("gameplay-mechanics.controllable-minecarts.fall-damage", minecartControllableFallDamage);
+ set("gameplay-mechanics.controllable-minecarts.fall-damage", null);
+ set("gameplay-mechanics.minecart.controllable.fall-damage", oldBool);
+ oldDouble = getDouble("gameplay-mechanics.controllable-minecarts.base-speed", minecartControllableBaseSpeed);
+ set("gameplay-mechanics.controllable-minecarts.base-speed", null);
+ set("gameplay-mechanics.minecart.controllable.base-speed", oldDouble);
+ ConfigurationSection section = getConfigurationSection("gameplay-mechanics.controllable-minecarts.block-speed");
+ if (section != null) {
+ for (String key : section.getKeys(false)) {
+ if ("grass-block".equals(key)) key = "grass_block"; // oopsie
+ oldDouble = section.getDouble(key, minecartControllableBaseSpeed);
+ set("gameplay-mechanics.controllable-minecarts.block-speed." + key, null);
+ set("gameplay-mechanics.minecart.controllable.block-speed." + key, oldDouble);
+ }
+ set("gameplay-mechanics.controllable-minecarts.block-speed", null);
+ }
+ set("gameplay-mechanics.controllable-minecarts", null);
+ }
+
+ minecartMaxSpeed = getDouble("gameplay-mechanics.minecart.max-speed", minecartMaxSpeed);
+ minecartPlaceAnywhere = getBoolean("gameplay-mechanics.minecart.place-anywhere", minecartPlaceAnywhere);
+ minecartControllable = getBoolean("gameplay-mechanics.minecart.controllable.enabled", minecartControllable);
+ minecartControllableStepHeight = (float) getDouble("gameplay-mechanics.minecart.controllable.step-height", minecartControllableStepHeight);
+ minecartControllableHopBoost = getDouble("gameplay-mechanics.minecart.controllable.hop-boost", minecartControllableHopBoost);
+ minecartControllableFallDamage = getBoolean("gameplay-mechanics.minecart.controllable.fall-damage", minecartControllableFallDamage);
+ minecartControllableBaseSpeed = getDouble("gameplay-mechanics.minecart.controllable.base-speed", minecartControllableBaseSpeed);
+ ConfigurationSection section = getConfigurationSection("gameplay-mechanics.minecart.controllable.block-speed");
+ if (section != null) {
+ for (String key : section.getKeys(false)) {
+ Block block = BuiltInRegistries.BLOCK.get(new ResourceLocation(key));
+ if (block != Blocks.AIR) {
+ minecartControllableBlockSpeeds.put(block, section.getDouble(key, minecartControllableBaseSpeed));
+ }
+ }
+ } else {
+ set("gameplay-mechanics.minecart.controllable.block-speed.grass_block", 0.3D);
+ set("gameplay-mechanics.minecart.controllable.block-speed.stone", 0.5D);
+ }
+ }
+
public boolean idleTimeoutKick = true;
public boolean idleTimeoutTickNearbyEntities = true;
public boolean idleTimeoutCountAsSleeping = false;