Skip to content

Commit

Permalink
only sync when something actually changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TropheusJ committed Jul 27, 2023
1 parent 861cef0 commit cb0a10f
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions src/main/java/com/fusionflux/portalcubed/util/EntityComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -64,8 +65,10 @@ public boolean getHasTeleportationHappened() {

@Override
public void setHasTeleportationHappened(boolean hasHappened) {
hasTeleportationHappened = hasHappened;
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
if (hasTeleportationHappened != hasHappened) {
hasTeleportationHappened = hasHappened;
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
}
}

@Override
Expand All @@ -75,8 +78,10 @@ public boolean getWasInfiniteFalling() {

@Override
public void setWasInfiniteFalling(boolean infFall) {
wasInfiniteFalling = infFall;
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
if (wasInfiniteFalling != infFall) {
wasInfiniteFalling = infFall;
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
}
}

@Override
Expand All @@ -86,8 +91,10 @@ public Vec3 getVelocityUpdateAfterTeleport() {

@Override
public void setVelocityUpdateAfterTeleport(Vec3 velocity) {
teleportVelocity = velocity;
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
if (!teleportVelocity.equals(velocity)) {
teleportVelocity = velocity;
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
}
}


Expand All @@ -99,8 +106,10 @@ public boolean getCanFireGel() {

@Override
public void setCanFireGel(boolean canGel) {
canFireGel = canGel;
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
if (canFireGel != canGel) {
canFireGel = canGel;
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
}
}

@Override
Expand All @@ -110,8 +119,10 @@ public Vec3 getServerVelForGel() {

@Override
public void setServerVelForGel(Vec3 velocity) {
serverVelForGel = velocity;
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
if (!serverVelForGel.equals(velocity)) {
serverVelForGel = velocity;
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
}
}

@Override
Expand All @@ -121,14 +132,16 @@ public Set<UUID> getPortals() {

@Override
public void addPortals(UUID portalUUID) {
portals.add(portalUUID);
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
if (portals.add(portalUUID)) {
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
}
}

@Override
public void removePortals(UUID portalUUID) {
portals.remove(portalUUID);
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
if (portals.remove(portalUUID)) {
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
}
}

@Nullable
Expand All @@ -139,8 +152,10 @@ public BlockPos getLauncher() {

@Override
public void setLauncher(@Nullable BlockPos launcher) {
this.launcher = launcher;
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
if (!Objects.equals(this.launcher, launcher)) {
this.launcher = launcher;
PortalCubedComponents.ENTITY_COMPONENT.sync(entity);
}
}

@Override
Expand Down

0 comments on commit cb0a10f

Please sign in to comment.