From 87fdba280a815b3688d8b6b59a50e1f7baa80629 Mon Sep 17 00:00:00 2001 From: Mike <76-Mike@users.noreply.git.krews.org> Date: Mon, 4 May 2020 05:53:28 +0200 Subject: [PATCH] Optimize water item update. --- .../interactions/InteractionWaterItem.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWaterItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWaterItem.java index a9840636..0332c717 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWaterItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWaterItem.java @@ -42,12 +42,15 @@ public class InteractionWaterItem extends InteractionDefault { public void update() { Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - if (room == null) + if (room == null) { return; + } - Rectangle rectangle = RoomLayout.getRectangle(this.getX(), this.getY(), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()); + Rectangle rectangle = this.getRectangle(); + // Check if every tile of the furni is in water. boolean foundWater = true; + for (short x = (short) rectangle.x; x < rectangle.getWidth() + rectangle.x && foundWater; x++) { for (short y = (short) rectangle.y; y < rectangle.getHeight() + rectangle.y && foundWater; y++) { boolean tile = false; @@ -66,16 +69,14 @@ public class InteractionWaterItem extends InteractionDefault { } } - if (foundWater) { - this.setExtradata("1"); + // Update data if changed. + String updatedData = foundWater ? "1" : "0"; + + if (!this.getExtradata().equals(updatedData)) { + this.setExtradata(updatedData); this.needsUpdate(true); room.updateItem(this); - return; } - - this.setExtradata("0"); - this.needsUpdate(true); - room.updateItem(this); } @Override