Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #114 from SpigotMC/master
Browse files Browse the repository at this point in the history
Implement basic entity metadata mapping to remap fireworks for boosting.
  • Loading branch information
sleiss authored Dec 23, 2016
2 parents dda70db + 6104354 commit 5a1da1f
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
6 changes: 6 additions & 0 deletions proxy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
<description>Proxy component of the Elastic Portal Suite</description>

<dependencies>
<dependency>
<groupId>com.flowpowered</groupId>
<artifactId>flow-nbt</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
Expand Down
89 changes: 89 additions & 0 deletions proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package net.md_5.bungee.entitymap;

import com.flowpowered.nbt.stream.NBTInputStream;
import com.google.common.base.Throwables;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import java.io.IOException;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import net.md_5.bungee.protocol.DefinedPacket;
Expand Down Expand Up @@ -105,6 +109,91 @@ protected static void rewriteVarInt(ByteBuf packet, int oldId, int newId, int of
}
}

protected static void rewriteMetaVarInt(ByteBuf packet, int oldId, int newId, int metaIndex)
{
int readerIndex = packet.readerIndex();

short index;
while ( ( index = packet.readUnsignedByte() ) != 0xFF )
{
int type = DefinedPacket.readVarInt( packet );

switch ( type )
{
case 0:
packet.skipBytes( 1 ); // byte
break;
case 1:
if ( index == metaIndex )
{
int position = packet.readerIndex();
rewriteVarInt( packet, oldId, newId, position );
packet.readerIndex( position );
}
DefinedPacket.readVarInt( packet );
break;
case 2:
packet.skipBytes( 4 ); // float
break;
case 3:
case 4:
DefinedPacket.readString( packet );
break;
case 5:
if ( packet.readShort() != -1 )
{
packet.skipBytes( 3 ); // byte, short

int position = packet.readerIndex();
if ( packet.readByte() != 0 )
{
packet.readerIndex( position );

try
{
new NBTInputStream( new ByteBufInputStream( packet ), false ).readTag();
} catch ( IOException ex )
{
throw Throwables.propagate( ex );
}
}
}
break;
case 6:
packet.skipBytes( 1 ); // boolean
break;
case 7:
packet.skipBytes( 12 ); // float, float, float
break;
case 8:
packet.readLong();
break;
case 9:
if ( packet.readBoolean() )
{
packet.skipBytes( 8 ); // long
}
break;
case 10:
DefinedPacket.readVarInt( packet );
break;
case 11:
if ( packet.readBoolean() )
{
packet.skipBytes( 16 ); // long, long
}
break;
case 12:
DefinedPacket.readVarInt( packet );
break;
default:
throw new IllegalArgumentException( "Unknown meta type " + type );
}
}

packet.readerIndex( readerIndex );
}

// Handles simple packets
private static void rewrite(ByteBuf packet, int oldId, int newId, boolean[] ints, boolean[] varints)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public void rewriteClientbound(ByteBuf packet, int oldId, int newId)
rewriteInt( packet, oldId, newId, packet.readerIndex() );
}
break;
case 0x39 /* EntityMetadata : PacketPlayOutEntityMetadata */:
DefinedPacket.readVarInt( packet ); // Entity ID
rewriteMetaVarInt( packet, oldId, newId, 7 ); // fireworks (et al)
break;
}
packet.readerIndex( readerIndex );
}
Expand Down

0 comments on commit 5a1da1f

Please sign in to comment.