Skip to content

Commit

Permalink
Hot-fix for flickering trees
Browse files Browse the repository at this point in the history
  • Loading branch information
olijeffers0n committed May 9, 2023
1 parent 1d3ee97 commit 09ca02f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions rustplus.proto
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ message AppCameraRays {
required bytes rayData = 3;
required float distance = 4;
repeated AppCameraRays.Entity entities = 5;
required float timeOfDay = 6;

enum EntityType {
Tree = 1;
Expand Down
2 changes: 1 addition & 1 deletion rustplus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@

__name__ = "rustplus"
__author__ = "olijeffers0n"
__version__ = "5.6.1"
__version__ = "5.6.2"
__support__ = "Discord: https://discord.gg/nQqJe8qvP8"
18 changes: 12 additions & 6 deletions rustplus/api/remote/camera/camera_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def handle_entity(
colour = (
(PLAYER_COLOUR if not entity.name.isdigit() else SCIENTIST_COLOUR)
if entity.type == 2
else MathUtils.get_slightly_random_colour(TREE_COLOUR, entity.entity_id)
else MathUtils.get_slightly_random_colour(TREE_COLOUR, entity.position)
)

MathUtils.set_polygon_with_depth(
Expand Down Expand Up @@ -658,17 +658,23 @@ def get_player_vertices(cls, size) -> np.ndarray:
return vertices

@staticmethod
def get_slightly_random_colour(colour: str, entity_id: int) -> str:
def get_slightly_random_colour(colour: str, entity_pos: Vector3) -> str:
"""
Returns a slightly randomised version of the colour passed in
Must be the same colour for the same entity id
"""

random.seed(entity_id)
r, g, b = int(colour[1:3], 16), int(colour[3:5], 16), int(colour[5:7], 16)
r = int(r * (1 + random.uniform(-0.1, 0.1)))
g = int(g * (1 + random.uniform(-0.1, 0.1)))
b = int(b * (1 + random.uniform(-0.1, 0.1)))

# Create an algorithm will slightly vary the colour based on the distance from the origin
# This is to make it easier to distinguish between entities

distance_squared = entity_pos.x**2 + entity_pos.y**2 + 2 * entity_pos.z**2

r += int(distance_squared * 0.0003) % 10
g += int(distance_squared * 0.0003) % 10
b += int(distance_squared * 0.0003) % 10

return f"#{r}{g}{b}"

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions rustplus/api/remote/rustplus_proto/rustplus.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
include_package_data=True,
long_description_content_type='text/markdown',
install_requires=requirements,
python_requires='>=3.6.0',
python_requires='>=3.8.0',
)

0 comments on commit 09ca02f

Please sign in to comment.