Minecraft 1.21.4-pre1 support

This commit is contained in:
md_5 2024-11-23 12:27:38 +11:00
parent f6b40b1186
commit 373dab05ad
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
10 changed files with 127 additions and 7 deletions

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.api.chat; package net.md_5.bungee.api.chat;
import java.awt.Color;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import lombok.AccessLevel; import lombok.AccessLevel;
@ -129,6 +130,10 @@ public abstract class BaseComponent
{ {
setColor( component.getColorRaw() ); setColor( component.getColorRaw() );
} }
if ( replace || !style.hasShadowColor() )
{
setShadowColor( component.getShadowColorRaw() );
}
if ( replace || !style.hasFont() ) if ( replace || !style.hasFont() )
{ {
setFont( component.getFontRaw() ); setFont( component.getFontRaw() );
@ -175,6 +180,7 @@ public abstract class BaseComponent
if ( retention == FormatRetention.EVENTS || retention == FormatRetention.NONE ) if ( retention == FormatRetention.EVENTS || retention == FormatRetention.NONE )
{ {
setColor( null ); setColor( null );
setShadowColor( null );
setBold( null ); setBold( null );
setItalic( null ); setItalic( null );
setUnderlined( null ); setUnderlined( null );
@ -295,6 +301,46 @@ public abstract class BaseComponent
return style.getColor(); return style.getColor();
} }
/**
* Set this component's shadow color.
*
* @param color the component shadow color, or null to use the default
*/
public void setShadowColor(Color color)
{
this.style.setShadowColor( color );
}
/**
* Returns the shadow color of this component. This uses the parent's shadow color if this
* component doesn't have one. null is returned if no shadow color is found.
*
* @return the shadow color of this component
*/
public Color getShadowColor()
{
if ( !style.hasShadowColor() )
{
if ( parent == null )
{
return null;
}
return parent.getShadowColor();
}
return style.getShadowColor();
}
/**
* Returns the shadow color of this component without checking the parents
* shadow color. May return null
*
* @return the shadow color of this component
*/
public Color getShadowColorRaw()
{
return style.getShadowColor();
}
/** /**
* Set this component's font. * Set this component's font.
* *
@ -536,6 +582,10 @@ public abstract class BaseComponent
{ {
setColor( style.getColor() ); setColor( style.getColor() );
} }
if ( style.hasShadowColor() )
{
setShadowColor( style.getShadowColor() );
}
if ( style.hasFont() ) if ( style.hasFont() )
{ {
setFont( style.getFont() ); setFont( style.getFont() );

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.api.chat; package net.md_5.bungee.api.chat;
import java.awt.Color;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -23,6 +24,10 @@ public final class ComponentStyle implements Cloneable
* {@link ChatColor#color} should not be null).</b> * {@link ChatColor#color} should not be null).</b>
*/ */
private ChatColor color; private ChatColor color;
/**
* The shadow color of this style.
*/
private Color shadowColor;
/** /**
* The font of this style. * The font of this style.
*/ */
@ -68,6 +73,26 @@ public final class ComponentStyle implements Cloneable
return ( color != null ); return ( color != null );
} }
/**
* Returns the shadow color of this style. May return null.
*
* @return the shadow color of this style, or null if default color
*/
public Color getShadowColor()
{
return shadowColor;
}
/**
* Returns whether or not this style has a shadow color set.
*
* @return whether a shadow color is set
*/
public boolean hasShadowColor()
{
return ( shadowColor != null );
}
/** /**
* Returns the font of this style. May return null. * Returns the font of this style. May return null.
* *
@ -195,7 +220,7 @@ public final class ComponentStyle implements Cloneable
*/ */
public boolean isEmpty() public boolean isEmpty()
{ {
return color == null && font == null && bold == null return color == null && shadowColor == null && font == null && bold == null
&& italic == null && underlined == null && italic == null && underlined == null
&& strikethrough == null && obfuscated == null; && strikethrough == null && obfuscated == null;
} }
@ -203,7 +228,7 @@ public final class ComponentStyle implements Cloneable
@Override @Override
public ComponentStyle clone() public ComponentStyle clone()
{ {
return new ComponentStyle( color, font, bold, italic, underlined, strikethrough, obfuscated ); return new ComponentStyle( color, shadowColor, font, bold, italic, underlined, strikethrough, obfuscated );
} }
/** /**
@ -227,6 +252,7 @@ public final class ComponentStyle implements Cloneable
{ {
return new ComponentStyleBuilder() return new ComponentStyleBuilder()
.color( other.color ) .color( other.color )
.shadowColor( other.shadowColor )
.font( other.font ) .font( other.font )
.bold( other.bold ) .bold( other.bold )
.italic( other.italic ) .italic( other.italic )

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.api.chat; package net.md_5.bungee.api.chat;
import java.awt.Color;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
/** /**
@ -26,6 +27,7 @@ public final class ComponentStyleBuilder
{ {
private ChatColor color; private ChatColor color;
private Color shadowColor;
private String font; private String font;
private Boolean bold, italic, underlined, strikethrough, obfuscated; private Boolean bold, italic, underlined, strikethrough, obfuscated;
@ -41,6 +43,18 @@ public final class ComponentStyleBuilder
return this; return this;
} }
/**
* Set the style shadow color.
*
* @param shadowColor the shadow color to set, or null to use the default
* @return this ComponentStyleBuilder for chaining
*/
public ComponentStyleBuilder shadowColor(Color shadowColor)
{
this.shadowColor = shadowColor;
return this;
}
/** /**
* Set the style font. * Set the style font.
* *
@ -121,6 +135,6 @@ public final class ComponentStyleBuilder
*/ */
public ComponentStyle build() public ComponentStyle build()
{ {
return new ComponentStyle( color, font, bold, italic, underlined, strikethrough, obfuscated ); return new ComponentStyle( color, shadowColor, font, bold, italic, underlined, strikethrough, obfuscated );
} }
} }

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.chat; package net.md_5.bungee.chat;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
@ -8,6 +9,7 @@ import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer; import com.google.gson.JsonSerializer;
import java.awt.Color;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Map; import java.util.Map;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
@ -67,6 +69,10 @@ public class ComponentStyleSerializer implements JsonSerializer<ComponentStyle>,
{ {
object.addProperty( "color", style.getColor().getName() ); object.addProperty( "color", style.getColor().getName() );
} }
if ( style.hasShadowColor() )
{
object.addProperty( "shadow_color", style.getShadowColor().getRGB() );
}
if ( style.hasFont() ) if ( style.hasFont() )
{ {
object.addProperty( "font", style.getFont() ); object.addProperty( "font", style.getFont() );
@ -102,6 +108,17 @@ public class ComponentStyleSerializer implements JsonSerializer<ComponentStyle>,
case "color": case "color":
builder.color( ChatColor.of( value.getAsString() ) ); builder.color( ChatColor.of( value.getAsString() ) );
break; break;
case "shadow_color":
if ( value.isJsonArray() )
{
JsonArray array = value.getAsJsonArray();
builder.shadowColor( new Color( array.get( 0 ).getAsFloat(), array.get( 1 ).getAsFloat(), array.get( 2 ).getAsFloat(), array.get( 3 ).getAsFloat() ) );
} else if ( value.isJsonPrimitive() )
{
builder.shadowColor( new Color( value.getAsNumber().intValue(), true ) );
}
break;
case "font": case "font":
builder.font( value.getAsString() ); builder.font( value.getAsString() );
break; break;

View File

@ -499,7 +499,7 @@ public abstract class DefinedPacket
public static BitSet readFixedBitSet(int i, ByteBuf buf) public static BitSet readFixedBitSet(int i, ByteBuf buf)
{ {
byte[] bits = new byte[ ( i + 8 ) >> 3 ]; byte[] bits = new byte[ ( i + 7 ) >> 3 ];
buf.readBytes( bits ); buf.readBytes( bits );
return BitSet.valueOf( bits ); return BitSet.valueOf( bits );
@ -511,7 +511,7 @@ public abstract class DefinedPacket
{ {
throw new OverflowPacketException( "BitSet too large (expected " + size + " got " + bits.size() + ")" ); throw new OverflowPacketException( "BitSet too large (expected " + size + " got " + bits.size() + ")" );
} }
buf.writeBytes( Arrays.copyOf( bits.toByteArray(), ( size + 8 ) >> 3 ) ); buf.writeBytes( Arrays.copyOf( bits.toByteArray(), ( size + 7 ) >> 3 ) );
} }
public void read(ByteBuf buf) public void read(ByteBuf buf)

View File

@ -48,6 +48,7 @@ public class ProtocolConstants
public static final int MINECRAFT_1_20_5 = 766; public static final int MINECRAFT_1_20_5 = 766;
public static final int MINECRAFT_1_21 = 767; public static final int MINECRAFT_1_21 = 767;
public static final int MINECRAFT_1_21_2 = 768; public static final int MINECRAFT_1_21_2 = 768;
public static final int MINECRAFT_1_21_4 = 1073742047;
public static final List<String> SUPPORTED_VERSIONS; public static final List<String> SUPPORTED_VERSIONS;
public static final List<Integer> SUPPORTED_VERSION_IDS; public static final List<Integer> SUPPORTED_VERSION_IDS;
@ -116,7 +117,7 @@ public class ProtocolConstants
if ( SNAPSHOT_SUPPORT ) if ( SNAPSHOT_SUPPORT )
{ {
// supportedVersions.add( "1.21.x" ); // supportedVersions.add( "1.21.x" );
// supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_21_2 ); supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_21_4 );
} }
SUPPORTED_VERSIONS = supportedVersions.build(); SUPPORTED_VERSIONS = supportedVersions.build();

View File

@ -148,5 +148,7 @@ public class PlayerListItem extends DefinedPacket
// UPDATE_LIST_ORDER 1.21.2 // UPDATE_LIST_ORDER 1.21.2
Integer listOrder; Integer listOrder;
// UPDATE_HAT 1.21.4
Boolean showHat;
} }
} }

View File

@ -64,6 +64,9 @@ public class PlayerListItemUpdate extends DefinedPacket
case UPDATE_LIST_ORDER: case UPDATE_LIST_ORDER:
item.listOrder = DefinedPacket.readVarInt( buf ); item.listOrder = DefinedPacket.readVarInt( buf );
break; break;
case UPDATE_HAT:
item.showHat = buf.readBoolean();
break;
} }
} }
} }
@ -115,6 +118,9 @@ public class PlayerListItemUpdate extends DefinedPacket
case UPDATE_LIST_ORDER: case UPDATE_LIST_ORDER:
DefinedPacket.writeVarInt( item.listOrder, buf ); DefinedPacket.writeVarInt( item.listOrder, buf );
break; break;
case UPDATE_HAT:
buf.writeBoolean( item.showHat );
break;
} }
} }
} }
@ -135,6 +141,7 @@ public class PlayerListItemUpdate extends DefinedPacket
UPDATE_LISTED, UPDATE_LISTED,
UPDATE_LATENCY, UPDATE_LATENCY,
UPDATE_DISPLAY_NAME, UPDATE_DISPLAY_NAME,
UPDATE_LIST_ORDER; UPDATE_LIST_ORDER,
UPDATE_HAT;
} }
} }

View File

@ -91,6 +91,8 @@ public abstract class EntityMap
return EntityMap_1_16_2.INSTANCE_1_20_5; return EntityMap_1_16_2.INSTANCE_1_20_5;
case ProtocolConstants.MINECRAFT_1_21_2: case ProtocolConstants.MINECRAFT_1_21_2:
return EntityMap_1_16_2.INSTANCE_1_21_2; return EntityMap_1_16_2.INSTANCE_1_21_2;
case ProtocolConstants.MINECRAFT_1_21_4:
return EntityMap_1_16_2.INSTANCE_1_21_4;
} }
throw new RuntimeException( "Version " + version + " has no entity map" ); throw new RuntimeException( "Version " + version + " has no entity map" );
} }

View File

@ -24,6 +24,7 @@ class EntityMap_1_16_2 extends EntityMap
static final EntityMap_1_16_2 INSTANCE_1_20_3 = new EntityMap_1_16_2( -1, 0x34 ); static final EntityMap_1_16_2 INSTANCE_1_20_3 = new EntityMap_1_16_2( -1, 0x34 );
static final EntityMap_1_16_2 INSTANCE_1_20_5 = new EntityMap_1_16_2( -1, 0x37 ); static final EntityMap_1_16_2 INSTANCE_1_20_5 = new EntityMap_1_16_2( -1, 0x37 );
static final EntityMap_1_16_2 INSTANCE_1_21_2 = new EntityMap_1_16_2( -1, 0x39 ); static final EntityMap_1_16_2 INSTANCE_1_21_2 = new EntityMap_1_16_2( -1, 0x39 );
static final EntityMap_1_16_2 INSTANCE_1_21_4 = new EntityMap_1_16_2( -1, 0x3B );
// //
private final int spawnPlayerId; private final int spawnPlayerId;
private final int spectateId; private final int spectateId;