Add BlockRotateEvent (#8577)

* feat: Add BuildRotateEvent

* fix: Fix invalid argument

* fix: Goofy aaah static imports

* chore: Update ConfigEvent doc + Add forgotten annotation

* chore: Remove final keyword

* fix: Remove rotation validation in Build#beginPlace

* Already covered by client snapshots

* fix: Remove useless imports
This commit is contained in:
Phinner 2023-05-11 01:03:08 +00:00 committed by GitHub
parent 51daa82a1b
commit 0919063ca3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View file

@ -257,13 +257,13 @@ public class EventType{
}
}
/** Called when the player configures a specific building. */
/** Called when a specific building has its configuration changed. */
public static class ConfigEvent{
public final Building tile;
public final Player player;
public final @Nullable Player player;
public final Object value;
public ConfigEvent(Building tile, Player player, Object value){
public ConfigEvent(Building tile, @Nullable Player player, Object value){
this.tile = tile;
this.player = player;
this.value = value;
@ -473,6 +473,18 @@ public class EventType{
}
}
public static class BuildRotateEvent{
public final Building build;
public final @Nullable Unit unit;
public final int previous;
public BuildRotateEvent(Building build, @Nullable Unit unit, int previous){
this.build = build;
this.unit = unit;
this.previous = previous;
}
}
/**
* Called when a player or drone begins building something.
* This does not necessarily happen when a new ConstructBlock is created.

View file

@ -464,10 +464,12 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
if(player != null) build.lastAccessed = player.name;
int previous = build.rotation;
build.rotation = Mathf.mod(build.rotation + Mathf.sign(direction), 4);
build.updateProximity();
build.noSleep();
Fx.rotateBlock.at(build.x, build.y, build.block.size);
Events.fire(new BuildRotateEvent(build, player.unit(), previous));
}
@Remote(targets = Loc.both, called = Loc.both, forward = true)

View file

@ -77,10 +77,12 @@ public class Build{
//auto-rotate the block to the correct orientation and bail out
if(tile.team() == team && tile.block == result && tile.build != null && tile.block.quickRotate){
if(unit != null && unit.getControllerName() != null) tile.build.lastAccessed = unit.getControllerName();
int previous = tile.build.rotation;
tile.build.rotation = Mathf.mod(rotation, 4);
tile.build.updateProximity();
tile.build.noSleep();
Fx.rotateBlock.at(tile.build.x, tile.build.y, tile.build.block.size);
Events.fire(new BuildRotateEvent(tile.build, unit, previous));
return;
}