Skip to content

Commit

Permalink
Fix vibration particles for versions 1.20.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
adepierre committed Apr 20, 2024
1 parent 1f4118d commit 204b485
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
Expand Up @@ -24,16 +24,24 @@ namespace ProtocolCraft

#if PROTOCOL_VERSION < 759 /* < 1.19 */
const VibrationPath& GetVibrationPath() const;
#else
#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
PositionSourceType GetDestinationType() const;
#else
const Identifier& GetDestinationType() const;
#endif
const std::shared_ptr<PositionSource>& GetDestination() const;
int GetArrivalInTicks() const;
#endif

#if PROTOCOL_VERSION < 759 /* < 1.19 */
void SetVibrationPath(const VibrationPath& vibration_path_);
#else
#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
void SetDestinationType(const PositionSourceType destination_type_);
#else
void SetDestinationType(const Identifier& destination_type_);
#endif
void SetDestination(const std::shared_ptr<PositionSource>& destination_);
void SetArrivalInTicks(const int arrival_in_ticks_);
#endif
Expand All @@ -48,8 +56,12 @@ namespace ProtocolCraft
private:
#if PROTOCOL_VERSION < 759 /* < 1.19 */
VibrationPath vibration_path;
#else
#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
PositionSourceType destination_type = PositionSourceType::None;
#else
Identifier destination_type;
#endif
std::shared_ptr<PositionSource> destination;
int arrival_in_ticks = 0;
#endif
Expand Down
Expand Up @@ -8,15 +8,28 @@

namespace ProtocolCraft
{
#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
enum class PositionSourceType
{
None = -1,
Block = 0,
Entity = 1,
};
#endif

class PositionSource : public NetworkType
{
public:
virtual ~PositionSource() override
{

}


#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
static std::shared_ptr<PositionSource> CreatePositionSource(const PositionSourceType position_source_type);
#else
static std::shared_ptr<PositionSource> CreatePositionSource(const Identifier& position_source_type);
#endif
};
}
#endif
22 changes: 22 additions & 0 deletions protocolCraft/src/Types/Particles/VibrationParticle.cpp
Expand Up @@ -34,10 +34,17 @@ namespace ProtocolCraft
return destination;
}

#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
PositionSourceType VibrationParticle::GetDestinationType() const
{
return destination_type;
}
#else
const Identifier& VibrationParticle::GetDestinationType() const
{
return destination_type;
}
#endif

int VibrationParticle::GetArrivalInTicks() const
{
Expand All @@ -50,11 +57,18 @@ namespace ProtocolCraft
{
vibration_path = vibration_path_;
}
#else
#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
void VibrationParticle::SetDestinationType(const PositionSourceType destination_type_)
{
destination_type = destination_type_;
}
#else
void VibrationParticle::SetDestinationType(const Identifier& destination_type_)
{
destination_type = destination_type_;
}
#endif

void VibrationParticle::SetDestination(const std::shared_ptr<PositionSource>& destination_)
{
Expand All @@ -71,8 +85,12 @@ namespace ProtocolCraft
{
#if PROTOCOL_VERSION < 759 /* < 1.19 */
vibration_path = ReadData<VibrationPath>(iter, length);
#else
#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
destination_type = static_cast<PositionSourceType>(static_cast<int>(ReadData<VarInt>(iter, length)));
#else
destination_type = ReadData<Identifier>(iter, length);
#endif
destination = PositionSource::CreatePositionSource(destination_type);
destination->Read(iter, length);
arrival_in_ticks = ReadData<VarInt>(iter, length);
Expand All @@ -83,8 +101,12 @@ namespace ProtocolCraft
{
#if PROTOCOL_VERSION < 759 /* < 1.19 */
WriteData<VibrationPath>(vibration_path, container);
#else
#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
WriteData<VarInt>(static_cast<int>(destination_type), container);
#else
WriteData<Identifier>(destination_type, container);
#endif
destination->Write(container);
WriteData<VarInt>(arrival_in_ticks, container);
#endif
Expand Down
15 changes: 15 additions & 0 deletions protocolCraft/src/Types/Vibrations/PositionSource.cpp
Expand Up @@ -8,6 +8,20 @@

namespace ProtocolCraft
{
#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
std::shared_ptr<PositionSource> PositionSource::CreatePositionSource(const PositionSourceType position_source_type)
{
switch (position_source_type)
{
case PositionSourceType::Block:
return std::make_shared<BlockPositionSource>();
case PositionSourceType::Entity:
return std::make_shared<EntityPositionSource>();
default:
throw std::runtime_error("Unable to create position source with type: " + static_cast<int>(position_source_type));
}
}
#else
std::shared_ptr<PositionSource> PositionSource::CreatePositionSource(const Identifier& position_source_type)
{
if (position_source_type.GetName() == "block")
Expand All @@ -23,5 +37,6 @@ namespace ProtocolCraft
throw std::runtime_error("Unable to create position source with type: " + position_source_type.GetFull());
}
}
#endif
}
#endif

0 comments on commit 204b485

Please sign in to comment.