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.rewriter ;
import com.viaversion.viaversion.api.minecraft.entities.EntityType ;
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.remapper.PacketHandlers ;
import com.viaversion.viaversion.api.type.Type ;
2023-12-18 19:34:53 +01:00
import com.viaversion.viaversion.api.type.types.version.Types1_20_5 ;
2024-01-26 15:48:10 +01:00
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundConfigurationPackets1_20_5 ;
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 ;
2023-10-16 14:30:12 +02:00
import com.viaversion.viaversion.rewriter.EntityRewriter ;
import com.viaversion.viaversion.template.protocols.Protocol1_99To_98 ;
// Replace if needed
// Types1_OLD
2023-12-18 19:34:53 +01:00
// Types1_20_5
2024-01-26 15:48:10 +01:00
public final class EntityPacketRewriter1_99 extends EntityRewriter < ClientboundPacket1_20_5 , Protocol1_99To_98 > {
2023-10-16 14:30:12 +02:00
public EntityPacketRewriter1_99 ( final Protocol1_99To_98 protocol ) {
super ( protocol ) ;
}
@Override
public void registerPackets ( ) {
// Tracks entities, applies metadata rewrites registered below, untracks entities
2024-01-17 21:04:44 +01:00
registerTrackerWithData1_19 ( ClientboundPackets1_20_5 . SPAWN_ENTITY , EntityTypes1_20_5 . FALLING_BLOCK ) ;
registerMetadataRewriter ( ClientboundPackets1_20_5 . ENTITY_METADATA , /*Types1_OLD.METADATA_LIST, */ Types1_20_5 . METADATA_LIST ) ; // Specify old and new metadata list if changed
registerRemoveEntities ( ClientboundPackets1_20_5 . REMOVE_ENTITIES ) ;
2023-10-16 14:30:12 +02:00
2024-01-26 15:48:10 +01:00
protocol . registerClientbound ( ClientboundConfigurationPackets1_20_5 . REGISTRY_DATA , new PacketHandlers ( ) {
2023-10-16 14:30:12 +02:00
@Override
protected void register ( ) {
2024-01-24 17:34:40 +01:00
map ( Type . STRING ) ; // Registry
map ( Type . REGISTRY_ENTRY_ARRAY ) ; // Data
handler ( registryDataHandler1_20_5 ( ) ) ; // Caches dimensions to access data like height later and tracks the amount of biomes sent for chunk data
2023-10-16 14:30:12 +02:00
}
} ) ;
2024-01-17 21:04:44 +01:00
protocol . registerClientbound ( ClientboundPackets1_20_5 . JOIN_GAME , new PacketHandlers ( ) {
2023-10-16 14:30:12 +02:00
@Override
public void register ( ) {
map ( Type . INT ) ; // Entity id
map ( Type . BOOLEAN ) ; // Hardcore
map ( Type . STRING_ARRAY ) ; // World List
map ( Type . VAR_INT ) ; // Max players
map ( Type . VAR_INT ) ; // View distance
map ( Type . VAR_INT ) ; // Simulation distance
map ( Type . BOOLEAN ) ; // Reduced debug info
map ( Type . BOOLEAN ) ; // Show death screen
map ( Type . BOOLEAN ) ; // Limited crafting
2024-01-24 17:34:40 +01:00
map ( Type . VAR_INT ) ; // Dimension id
2023-10-16 14:30:12 +02:00
map ( Type . STRING ) ; // World
2024-01-24 17:34:40 +01:00
handler ( worldDataTrackerHandlerByKey1_20_5 ( 3 ) ) ; // Tracks world height and name for chunk data and entity (un)tracking
2023-10-16 14:30:12 +02:00
}
} ) ;
2024-01-17 21:04:44 +01:00
protocol . registerClientbound ( ClientboundPackets1_20_5 . RESPAWN , new PacketHandlers ( ) {
2023-10-16 14:30:12 +02:00
@Override
public void register ( ) {
2024-01-24 17:34:40 +01:00
map ( Type . VAR_INT ) ; // Dimension
2023-10-16 14:30:12 +02:00
map ( Type . STRING ) ; // World
2024-01-24 17:34:40 +01:00
handler ( worldDataTrackerHandlerByKey1_20_5 ( 0 ) ) ; // Tracks world height and name for chunk data and entity (un)tracking
2023-10-16 14:30:12 +02:00
}
} ) ;
}
@Override
protected void registerRewrites ( ) {
/ * Uncomment if metatype classes changed
2024-01-09 20:43:43 +01:00
filter ( ) . mapMetaType ( typeId - > {
2024-01-12 10:30:24 +01:00
final int id = typeId ;
2023-10-16 14:30:12 +02:00
if ( id > = SomeAddedIndex ) {
id + + ;
}
2024-01-12 10:30:24 +01:00
return Types1_20_5 . META_TYPES . byId ( id ) ;
2023-10-16 14:30:12 +02:00
} ) ; * /
// Registers registry type id changes
registerMetaTypeHandler (
2024-03-14 18:25:18 +01:00
Types1_20_5 . META_TYPES . itemType ,
Types1_20_5 . META_TYPES . blockStateType ,
Types1_20_5 . META_TYPES . optionalBlockStateType ,
Types1_20_5 . META_TYPES . particleType ,
Types1_20_5 . META_TYPES . particlesType
2023-10-16 14:30:12 +02:00
) ;
// Minecarts are special
2024-01-12 10:30:24 +01:00
filter ( ) . type ( EntityTypes1_20_5 . MINECART_ABSTRACT ) . index ( 11 ) . handler ( ( event , meta ) - > {
2023-10-16 14:30:12 +02:00
final int blockState = meta . value ( ) ;
meta . setValue ( protocol . getMappingData ( ) . getNewBlockStateId ( blockState ) ) ;
} ) ;
}
@Override
public void onMappingDataLoaded ( ) {
// IF ENTITY TYPES CHANGED: Automatically map entity id changes AFTER entity ids have been loaded
2023-10-18 11:48:19 +02:00
mapTypes ( ) ;
2023-10-16 14:30:12 +02:00
}
@Override
public EntityType typeFromId ( final int type ) {
2023-12-18 19:34:53 +01:00
return EntityTypes1_20_5 . getTypeFromId ( type ) ;
2023-10-16 14:30:12 +02:00
}
}