forked from PaperMC/Waterfall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0046-Provide-an-option-to-disable-entity-metadata-rewriti.patch
238 lines (225 loc) · 11.3 KB
/
0046-Provide-an-option-to-disable-entity-metadata-rewriti.patch
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
From 8bc317f3d6b8ef341fc3bd129bd78c80f371c629 Mon Sep 17 00:00:00 2001
From: Shane Freeder <[email protected]>
Date: Mon, 14 Jan 2019 03:35:21 +0000
Subject: [PATCH] Provide an option to disable entity metadata rewriting
The work here is derived from the research and guidance of
various members of the minecraft community
This patch provides the ability to disable entity remapping,
which creates various incompatability issues with mods, however,
may also create various issues with mods which do not support this,
hence why the configuration option is provided
diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
index e0baca9c..f3bced0a 100644
--- a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
+++ b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
@@ -252,4 +252,9 @@ public interface ProxyConfig
* @return should we disable the tab completion limit for 1.13+ clients
*/
boolean isDisableModernTabLimiter();
+
+ /**
+ * @return Should we disable entity metadata rewriting?
+ */
+ boolean isDisableEntityMetadataRewrite();
}
diff --git a/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java b/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
index 4ff8da6d..e860214f 100644
--- a/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
+++ b/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
@@ -42,6 +42,8 @@ public class WaterfallConfiguration extends Configuration {
private int tabThrottle = 1000;
private boolean disableModernTabLimiter = true;
+ private boolean disableEntityMetadataRewrite = false;
+
@Override
public void load() {
super.load();
@@ -53,6 +55,7 @@ public class WaterfallConfiguration extends Configuration {
// Throttling options
tabThrottle = config.getInt("throttling.tab_complete", tabThrottle);
disableModernTabLimiter = config.getBoolean("disable_modern_tab_limiter", disableModernTabLimiter);
+ disableEntityMetadataRewrite = config.getBoolean("disable_entity_metadata_rewrite", disableEntityMetadataRewrite);
}
@Override
@@ -79,4 +82,9 @@ public class WaterfallConfiguration extends Configuration {
public boolean isDisableModernTabLimiter() {
return disableModernTabLimiter;
}
+
+ @Override
+ public boolean isDisableEntityMetadataRewrite() {
+ return disableEntityMetadataRewrite;
+ }
}
diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
index 84e93b38..a5efb0af 100644
--- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
+++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
@@ -231,7 +231,7 @@ public class ServerConnector extends PacketHandler
ch.write( message );
}
- if ( user.getSettings() != null )
+ if (!user.isDisableEntityMetadataRewrite() && user.getSettings() != null )
{
ch.write( user.getSettings() );
}
@@ -284,6 +284,7 @@ public class ServerConnector extends PacketHandler
user.getTabListHandler().onServerChange();
Scoreboard serverScoreboard = user.getServerSentScoreboard();
+ if ( !user.isDisableEntityMetadataRewrite() ) { // Waterfall
for ( Objective objective : serverScoreboard.getObjectives() )
{
user.unsafe().sendPacket( new ScoreboardObjective( objective.getName(), objective.getValue(), ScoreboardObjective.HealthDisplay.fromString( objective.getType() ), (byte) 1 ) );
@@ -296,6 +297,7 @@ public class ServerConnector extends PacketHandler
{
user.unsafe().sendPacket( new net.md_5.bungee.protocol.packet.Team( team.getName() ) );
}
+ } // Waterfall
serverScoreboard.clear();
for ( UUID bossbar : user.getSentBossBars() )
@@ -314,12 +316,35 @@ public class ServerConnector extends PacketHandler
}
user.setDimensionChange( true );
- if ( login.getDimension() == user.getDimension() )
+ if ( !user.isDisableEntityMetadataRewrite() && login.getDimension() == user.getDimension() ) // Waterfall - defer
{
user.unsafe().sendPacket( new Respawn( (Integer) login.getDimension() >= 0 ? -1 : 0, login.getWorldName(), login.getSeed(), login.getDifficulty(), login.getGameMode(), login.getPreviousGameMode(), login.getLevelType(), login.isDebug(), login.isFlat(), false ) );
}
user.setServerEntityId( login.getEntityId() );
+
+ // Waterfall start
+ if ( user.isDisableEntityMetadataRewrite() ) {
+ // Ensure that we maintain consistency
+ user.setClientEntityId( login.getEntityId() );
+
+ // Only send if we are not in the same dimension
+ if ( login.getDimension() != user.getDimension() ) // Waterfall - defer
+ {
+ user.unsafe().sendPacket( new Respawn( (Integer) user.getDimension() >= 0 ? -1 : 0, login.getWorldName(), login.getSeed(), login.getDifficulty(), login.getGameMode(), login.getPreviousGameMode(), login.getLevelType(), login.isDebug(), login.isFlat(), false ) );
+ }
+
+ Login modLogin = new Login( login.getEntityId(), login.isHardcore(), login.getGameMode(), login.getPreviousGameMode(), login.getWorldNames(), login.getDimensions(), login.getDimension(), login.getWorldName(), login.getSeed(), login.getDifficulty(),
+ (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.getViewDistance(), login.isReducedDebugInfo(), login.isNormalRespawn(), login.isDebug(), login.isFlat() );
+ user.unsafe().sendPacket(modLogin);
+
+ // Only send if we're in the same dimension
+ if ( login.getDimension() == user.getDimension() ) // Waterfall - defer
+ {
+ user.unsafe().sendPacket( new Respawn( (Integer) login.getDimension() >= 0 ? -1 : 0, login.getWorldName(), login.getSeed(), login.getDifficulty(), login.getGameMode(), login.getPreviousGameMode(), login.getLevelType(), login.isDebug(), login.isFlat(), false ) );
+ }
+ }
+ // Waterfall end
user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getWorldName(), login.getSeed(), login.getDifficulty(), login.getGameMode(), login.getPreviousGameMode(), login.getLevelType(), login.isDebug(), login.isFlat(), false ) );
if ( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_14 )
{
diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
index 95dc97b9..fc98b4b1 100644
--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java
+++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
@@ -768,4 +768,10 @@ public final class UserConnection implements ProxiedPlayer
{
return serverSentScoreboard;
}
+
+ // Waterfall start
+ public boolean isDisableEntityMetadataRewrite() {
+ return entityRewrite == net.md_5.bungee.entitymap.EntityMap_Dummy.INSTANCE;
+ }
+ // Waterfall end
}
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
index 033877fc..72b6e9be 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
@@ -645,6 +645,7 @@ public class DownstreamBridge extends PacketHandler
@Override
public void handle(EntityEffect entityEffect) throws Exception
{
+ if (con.isDisableEntityMetadataRewrite()) return; // Waterfall
// Don't send any potions when switching between servers (which involves a handshake), which can trigger a race
// condition on the client.
if (this.con.getForgeClientHandler().isForgeUser() && !this.con.getForgeClientHandler().isHandshakeComplete()) {
@@ -656,6 +657,7 @@ public class DownstreamBridge extends PacketHandler
@Override
public void handle(EntityRemoveEffect removeEffect) throws Exception
{
+ if (con.isDisableEntityMetadataRewrite()) return; // Waterfall
con.getPotions().remove(rewriteEntityId(removeEffect.getEntityId()), removeEffect.getEffectId());
}
diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java
index 572e1c47..09df5a93 100644
--- a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java
+++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java
@@ -6,6 +6,7 @@ import io.netty.buffer.ByteBufInputStream;
import java.io.DataInputStream;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;
import se.llbit.nbt.NamedTag;
@@ -27,6 +28,11 @@ public abstract class EntityMap
// Returns the correct entity map for the protocol version
public static EntityMap getEntityMap(int version)
{
+ // Waterfall start
+ if (net.md_5.bungee.api.ProxyServer.getInstance().getConfig().isDisableEntityMetadataRewrite()) {
+ return EntityMap_Dummy.INSTANCE;
+ }
+ // Waterfall end
switch ( version )
{
case ProtocolConstants.MINECRAFT_1_8:
@@ -287,7 +293,13 @@ public abstract class EntityMap
DefinedPacket.readVarInt( packet );
break;
default:
- throw new IllegalArgumentException( "Unknown meta type " + type );
+ // Waterfall start - Don't lie
+ if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
+ {
+ type++;
+ }
+ throw new IllegalArgumentException( "Unknown meta type " + type + ": Using mods? refer to disable_entity_metadata_rewrite in waterfall.yml" );
+ // Waterfall end
}
}
diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_Dummy.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_Dummy.java
new file mode 100644
index 00000000..cb81d1dd
--- /dev/null
+++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_Dummy.java
@@ -0,0 +1,30 @@
+
+package net.md_5.bungee.entitymap;
+
+import io.netty.buffer.ByteBuf;
+// Waterfall start
+
+public class EntityMap_Dummy extends EntityMap {
+
+ public static final EntityMap_Dummy INSTANCE = new EntityMap_Dummy();
+
+ EntityMap_Dummy() {
+ }
+
+ @Override
+ public void rewriteServerbound(ByteBuf packet, int oldId, int newId) {
+ }
+
+ @Override
+ public void rewriteServerbound(ByteBuf packet, int oldId, int newId, int protocolVersion) {
+ }
+
+ @Override
+ public void rewriteClientbound(ByteBuf packet, int oldId, int newId) {
+ }
+
+ @Override
+ public void rewriteClientbound(ByteBuf packet, int oldId, int newId, int protocolVersion) {
+ }
+}
+// Waterfall end
\ No newline at end of file
--
2.28.0.windows.1