2023-10-16 14:30:12 +02:00
/ *
* This file is part of ViaVersion - https : //github.com/ViaVersion/ViaVersion
2024-01-01 12:39:45 +01:00
* Copyright ( C ) 2016 - 2024 ViaVersion and contributors
2023-10-16 14:30:12 +02:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
package com.viaversion.viaversion.template.protocols ;
import com.viaversion.viaversion.api.connection.UserConnection ;
import com.viaversion.viaversion.api.data.MappingData ;
import com.viaversion.viaversion.api.data.MappingDataBase ;
2023-12-18 19:34:53 +01:00
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5 ;
2023-10-16 14:30:12 +02:00
import com.viaversion.viaversion.api.protocol.AbstractProtocol ;
import com.viaversion.viaversion.data.entity.EntityTrackerBase ;
2024-01-17 21:04:44 +01:00
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundConfigurationPackets1_20_5 ;
2024-01-26 15:48:10 +01:00
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPacket1_20_5 ;
2024-01-17 21:04:44 +01:00
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPackets1_20_5 ;
2024-01-26 15:48:10 +01:00
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ServerboundPacket1_20_5 ;
2024-02-12 09:51:47 +01:00
import com.viaversion.viaversion.rewriter.AttributeRewriter ;
2023-10-16 14:30:12 +02:00
import com.viaversion.viaversion.rewriter.SoundRewriter ;
import com.viaversion.viaversion.rewriter.StatisticsRewriter ;
import com.viaversion.viaversion.rewriter.TagRewriter ;
import com.viaversion.viaversion.template.protocols.rewriter.BlockItemPacketRewriter1_99 ;
2023-11-09 06:35:07 +01:00
import com.viaversion.viaversion.template.protocols.rewriter.EntityPacketRewriter1_99 ;
2023-10-16 14:30:12 +02:00
// Placeholders to replace (in the entire package):
// Protocol1_99To_98, EntityPacketRewriter1_99, BlockItemPacketRewriter1_99
2024-01-26 15:48:10 +01:00
// ClientboundPacket1_20_5
// ServerboundPacket1_20_5
2024-02-29 18:23:46 +01:00
// EntityTypes1_20_5 (MAPPED type)
2023-10-16 14:30:12 +02:00
// 1.99, 1.98
2024-01-26 15:48:10 +01:00
public final class Protocol1_99To_98 extends AbstractProtocol < ClientboundPacket1_20_5 , ClientboundPacket1_20_5 , ServerboundPacket1_20_5 , ServerboundPacket1_20_5 > {
2023-10-16 14:30:12 +02:00
2023-10-18 05:26:09 +02:00
public static final MappingData MAPPINGS = new MappingDataBase ( " 1.98 " , " 1.99 " ) ;
2023-10-16 14:30:12 +02:00
private final EntityPacketRewriter1_99 entityRewriter = new EntityPacketRewriter1_99 ( this ) ;
private final BlockItemPacketRewriter1_99 itemRewriter = new BlockItemPacketRewriter1_99 ( this ) ;
public Protocol1_99To_98 ( ) {
// Passing the class types into the super constructor is needed for automatic packet type id remapping, but can otherwise be omitted
2024-01-26 15:48:10 +01:00
super ( ClientboundPacket1_20_5 . class , ClientboundPacket1_20_5 . class , ServerboundPacket1_20_5 . class , ServerboundPacket1_20_5 . class ) ;
2023-10-16 14:30:12 +02:00
}
@Override
protected void registerPackets ( ) {
super . registerPackets ( ) ;
2024-01-26 15:48:10 +01:00
final TagRewriter < ClientboundPacket1_20_5 > tagRewriter = new TagRewriter < > ( this ) ;
2024-01-17 21:04:44 +01:00
tagRewriter . registerGeneric ( ClientboundPackets1_20_5 . TAGS ) ;
2024-01-26 15:48:10 +01:00
tagRewriter . registerGeneric ( ClientboundConfigurationPackets1_20_5 . UPDATE_TAGS ) ;
2023-10-16 14:30:12 +02:00
2024-01-26 15:48:10 +01:00
final SoundRewriter < ClientboundPacket1_20_5 > soundRewriter = new SoundRewriter < > ( this ) ;
2024-01-17 21:04:44 +01:00
soundRewriter . register1_19_3Sound ( ClientboundPackets1_20_5 . SOUND ) ;
soundRewriter . register1_19_3Sound ( ClientboundPackets1_20_5 . ENTITY_SOUND ) ;
2023-10-16 14:30:12 +02:00
2024-01-17 21:04:44 +01:00
new StatisticsRewriter < > ( this ) . register ( ClientboundPackets1_20_5 . STATISTICS ) ;
2024-02-12 09:51:47 +01:00
new AttributeRewriter < > ( this ) . register1_20_5 ( ClientboundPackets1_20_5 . ENTITY_PROPERTIES ) ;
2023-10-16 14:30:12 +02:00
// Uncomment if an existing type changed serialization format. Mappings for argument type keys can also be defined in mapping files
2024-01-17 21:04:44 +01:00
/ * final CommandRewriter1_19_4 < ClientboundPackets1_20_5 > commandRewriter = new CommandRewriter1_19_4 < ClientboundPackets1_20_5 > ( this ) {
2023-10-16 14:30:12 +02:00
@Override
public void handleArgument ( final PacketWrapper wrapper , final String argumentType ) throws Exception {
if ( argumentType . equals ( " minecraft:abc " ) ) {
// New argument
wrapper . write ( Type . INT , 0 ) ;
} else {
super . handleArgument ( wrapper , argumentType ) ;
}
}
2024-01-17 21:04:44 +01:00
} . registerDeclareCommands1_19 ( ClientboundPackets1_20_5 . DECLARE_COMMANDS ) ; * /
2023-12-18 15:28:58 +01:00
2024-03-14 18:25:18 +01:00
// TODO Rewrite structured data ids and items within them
2023-10-16 14:30:12 +02:00
}
@Override
protected void onMappingDataLoaded ( ) {
super . onMappingDataLoaded ( ) ; // Calls load methods on rewriters
2024-04-17 22:39:08 +02:00
// Uncomment this if the entity types enum has been newly added specifically for this Protocol
2023-12-18 19:34:53 +01:00
// EntityTypes1_20_5.initialize(this);
2023-10-16 14:30:12 +02:00
// Uncomment if a new particle was added = ids shifted; requires a new Types_ class copied from the last
2023-12-18 19:34:53 +01:00
/ * Types1_20_5 . PARTICLE . filler ( this )
2023-10-16 14:30:12 +02:00
. reader ( " block " , ParticleType . Readers . BLOCK )
. reader ( " block_marker " , ParticleType . Readers . BLOCK )
. reader ( " dust " , ParticleType . Readers . DUST )
. reader ( " falling_dust " , ParticleType . Readers . BLOCK )
. reader ( " dust_color_transition " , ParticleType . Readers . DUST_TRANSITION )
2023-11-09 06:35:07 +01:00
. reader ( " item " , ParticleType . Readers . ITEM1_20_2 )
. reader ( " vibration " , ParticleType . Readers . VIBRATION1_20_3 )
2023-10-16 14:30:12 +02:00
. reader ( " sculk_charge " , ParticleType . Readers . SCULK_CHARGE )
. reader ( " shriek " , ParticleType . Readers . SHRIEK ) ; * /
}
@Override
2023-10-18 11:48:19 +02:00
public void init ( final UserConnection connection ) {
2023-10-16 14:30:12 +02:00
// Register the entity tracker - used for entity id/metadata rewriting AND for tracking world data sent to the client (then used for chunk data rewriting)
2023-12-18 19:34:53 +01:00
addEntityTracker ( connection , new EntityTrackerBase ( connection , EntityTypes1_20_5 . PLAYER ) ) ;
2023-10-16 14:30:12 +02:00
}
// Overriding these three methods is important as they are relied on various rewriter classes
@Override
public MappingData getMappingData ( ) {
return MAPPINGS ;
}
@Override
public EntityPacketRewriter1_99 getEntityRewriter ( ) {
return entityRewriter ;
}
@Override
public BlockItemPacketRewriter1_99 getItemRewriter ( ) {
return itemRewriter ;
}
}