@@ -34,13 +34,17 @@ public class BlockPacketListener implements PacketListener {
3434
3535 private final int firstCustomId ;
3636
37+ private final int noteblockStart ;
38+ private final int noteblockEnd ; // Last valid noteblock state
3739 private final int defaultReplaceState ;
3840
3941 private final ParallelBlockRegistry registry ;
4042
4143 public BlockPacketListener (int firstCustomId ) {
4244 this .firstCustomId = firstCustomId ;
43- this .defaultReplaceState = Block .BLOCK_STATE_REGISTRY .getId (Blocks .NOTE_BLOCK .defaultBlockState ());
45+ this .noteblockStart = Block .BLOCK_STATE_REGISTRY .getId (Blocks .NOTE_BLOCK .defaultBlockState ());
46+ this .noteblockEnd = this .noteblockStart + Blocks .NOTE_BLOCK .getStateDefinition ().getPossibleStates ().size () -1 ;
47+ this .defaultReplaceState = noteblockStart ;
4448 this .registry = ParallelBlockRegistry .getInstance ();
4549 }
4650
@@ -58,70 +62,82 @@ public void onPacketSend(PacketSendEvent event) {
5862 for (int y = 0 ; y < 16 ; y ++) {
5963 for (int z = 0 ; z < 16 ; z ++) {
6064 int id = c .getBlockId (x , y , z );
65+ Integer replace_state ;
6166 if (id >= firstCustomId ) {
6267 //BlockState state = Block.BLOCK_STATE_REGISTRY.byId(id);
6368 //Logger.getGlobal().log(Level.WARNING, state.toString());
64- Integer replace_state = registry .getMappedState (id );
69+ replace_state = registry .getMappedState (id );
6570 if (replace_state == null ) {
6671 replace_state = defaultReplaceState ;
6772 Logger .getGlobal ().log (Level .WARNING , "Could not find mapping for id" + id );
6873 }
74+ } else if (id >= noteblockStart && id <= noteblockEnd ) {
75+ replace_state = noteblockStart ;
76+ } else {
77+ continue ;
78+ }
79+ c .set (x , y , z , replace_state );
6980
70- c .set (x , y , z , replace_state );
71-
72- Chunk_v1_18 chunkV118 = (Chunk_v1_18 ) c ;
81+ Chunk_v1_18 chunkV118 = (Chunk_v1_18 ) c ;
7382
74- DataPalette palette = getPrivateField ("chunkData" , Chunk_v1_18 .class , chunkV118 , DataPalette .class );
75- ListPalette lp = (ListPalette ) palette .palette ;
83+ DataPalette palette = getPrivateField ("chunkData" , Chunk_v1_18 .class , chunkV118 , DataPalette .class );
84+ ListPalette lp = (ListPalette ) palette .palette ;
7685
77- int [] palatteData = getPrivateField ("data" , ListPalette .class , lp , int [].class );
86+ int [] palatteData = getPrivateField ("data" , ListPalette .class , lp , int [].class );
7887
79- for (int i = 0 ; i < palatteData .length ; i ++) {
80- if (palatteData [i ] >= firstCustomId ) {
81- palatteData [i ] = replace_state ;
82- }
88+ for (int i = 0 ; i < palatteData .length ; i ++) {
89+ if (palatteData [i ] >= firstCustomId ) {
90+ palatteData [i ] = replace_state ;
8391 }
92+ }
8493
8594
86- event .markForReEncode (true );
87- }
95+ event .markForReEncode (true );
8896 }
8997 }
9098 }
9199 }
92-
93- int a = 0 ;
94-
95100 } else if (event .getPacketType () == PacketType .Play .Server .BLOCK_CHANGE ) {
96101 WrapperPlayServerBlockChange packet = new WrapperPlayServerBlockChange (event );
97102
98103 int id = packet .getBlockId ();
104+ Integer replace_state ;
99105 if (id >= firstCustomId ) {
100- Integer replace_state = registry .getMappedState (id );
106+ replace_state = registry .getMappedState (id );
101107 if (replace_state == null ) {
102108 replace_state = defaultReplaceState ;
103109 Logger .getGlobal ().log (Level .WARNING , "Could not find mapping for id" + id );
104110 }
105-
106- packet .setBlockID (replace_state );
107- event .markForReEncode (true );
111+ } else if (id >= noteblockStart && id <= noteblockEnd ) {
112+ replace_state = noteblockStart ;
113+ } else {
114+ return ;
108115 }
109116
117+ packet .setBlockID (replace_state );
118+ event .markForReEncode (true );
119+
110120 //Logger.getGlobal().log(Level.WARNING, String.valueOf(packet.getBlockId()));
111121 } else if (event .getPacketType () == PacketType .Play .Server .BLOCK_ACTION ) {
112122 WrapperPlayServerBlockAction packet = new WrapperPlayServerBlockAction (event );
113123
114124 int id = packet .getBlockTypeId ();
125+ Integer replace_state ;
115126 if (id >= firstCustomId ) {
116- Integer replace_state = registry .getMappedState (id );
117- if (replace_state == null ) {
118- replace_state = defaultReplaceState ;
119- Logger .getGlobal ().log (Level .WARNING , "Could not find mapping for id" + id );
120- }
127+ replace_state = registry .getMappedState (id );
128+ } else if (id >= noteblockStart && id <= noteblockEnd ) {
129+ replace_state = noteblockStart ;
130+ } else {
131+ return ;
132+ }
121133
122- packet .setBlockTypeId (replace_state );
123- event .markForReEncode (true );
134+ if (replace_state == null ) {
135+ replace_state = defaultReplaceState ;
136+ Logger .getGlobal ().log (Level .WARNING , "Could not find mapping for id" + id );
124137 }
138+
139+ packet .setBlockTypeId (replace_state );
140+ event .markForReEncode (true );
125141 } else if (event .getPacketType () == PacketType .Play .Server .DECLARE_COMMANDS ) {
126142 WrapperPlayServerDeclareCommands packet = new WrapperPlayServerDeclareCommands (event );
127143
0 commit comments