Building tile > Building build @ Inputhandler.java (#4241)
Was weird to see `if(player != null) tile.lastAccessed = player.name;` in there.
This commit is contained in:
committed by
GitHub
parent
0f3716b8dd
commit
3eb0857906
@@ -129,11 +129,11 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Remote(called = Loc.server, targets = Loc.both, forward = true)
|
@Remote(called = Loc.server, targets = Loc.both, forward = true)
|
||||||
public static void requestItem(Player player, Building tile, Item item, int amount){
|
public static void requestItem(Player player, Building build, Item item, int amount){
|
||||||
if(player == null || tile == null || !tile.interactable(player.team()) || !player.within(tile, buildingRange) || player.dead()) return;
|
if(player == null || build == null || !build.interactable(player.team()) || !player.within(build, buildingRange) || player.dead()) return;
|
||||||
|
|
||||||
if(net.server() && (!Units.canInteract(player, tile) ||
|
if(net.server() && (!Units.canInteract(player, build) ||
|
||||||
!netServer.admins.allowAction(player, ActionType.withdrawItem, tile.tile(), action -> {
|
!netServer.admins.allowAction(player, ActionType.withdrawItem, build.tile(), action -> {
|
||||||
action.item = item;
|
action.item = item;
|
||||||
action.itemAmount = amount;
|
action.itemAmount = amount;
|
||||||
}))){
|
}))){
|
||||||
@@ -142,20 +142,20 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
|
|
||||||
//remove item for every controlling unit
|
//remove item for every controlling unit
|
||||||
player.unit().eachGroup(unit -> {
|
player.unit().eachGroup(unit -> {
|
||||||
Call.takeItems(tile, item, unit.maxAccepted(item), unit);
|
Call.takeItems(build, item, unit.maxAccepted(item), unit);
|
||||||
|
|
||||||
if(unit == player.unit()){
|
if(unit == player.unit()){
|
||||||
Events.fire(new WithdrawEvent(tile, player, item, amount));
|
Events.fire(new WithdrawEvent(build, player, item, amount));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.both, forward = true, called = Loc.server)
|
@Remote(targets = Loc.both, forward = true, called = Loc.server)
|
||||||
public static void transferInventory(Player player, Building tile){
|
public static void transferInventory(Player player, Building build){
|
||||||
if(player == null || tile == null || !player.within(tile, buildingRange) || tile.items == null || player.dead()) return;
|
if(player == null || build == null || !player.within(build, buildingRange) || build.items == null || player.dead()) return;
|
||||||
|
|
||||||
if(net.server() && (player.unit().stack.amount <= 0 || !Units.canInteract(player, tile) ||
|
if(net.server() && (player.unit().stack.amount <= 0 || !Units.canInteract(player, build) ||
|
||||||
!netServer.admins.allowAction(player, ActionType.depositItem, tile.tile, action -> {
|
!netServer.admins.allowAction(player, ActionType.depositItem, build.tile, action -> {
|
||||||
action.itemAmount = player.unit().stack.amount;
|
action.itemAmount = player.unit().stack.amount;
|
||||||
action.item = player.unit().item();
|
action.item = player.unit().item();
|
||||||
}))){
|
}))){
|
||||||
@@ -165,12 +165,12 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
//deposit for every controlling unit
|
//deposit for every controlling unit
|
||||||
player.unit().eachGroup(unit -> {
|
player.unit().eachGroup(unit -> {
|
||||||
Item item = unit.item();
|
Item item = unit.item();
|
||||||
int accepted = tile.acceptStack(item, unit.stack.amount, unit);
|
int accepted = build.acceptStack(item, unit.stack.amount, unit);
|
||||||
|
|
||||||
Call.transferItemTo(unit, item, accepted, unit.x, unit.y, tile);
|
Call.transferItemTo(unit, item, accepted, unit.x, unit.y, build);
|
||||||
|
|
||||||
if(unit == player.unit()){
|
if(unit == player.unit()){
|
||||||
Events.fire(new DepositEvent(tile, player, item, accepted));
|
Events.fire(new DepositEvent(build, player, item, accepted));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -194,22 +194,22 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.both, called = Loc.server)
|
@Remote(targets = Loc.both, called = Loc.server)
|
||||||
public static void requestBuildPayload(Player player, Building tile){
|
public static void requestBuildPayload(Player player, Building build){
|
||||||
if(player == null) return;
|
if(player == null) return;
|
||||||
|
|
||||||
Unit unit = player.unit();
|
Unit unit = player.unit();
|
||||||
Payloadc pay = (Payloadc)unit;
|
Payloadc pay = (Payloadc)unit;
|
||||||
|
|
||||||
if(tile != null && tile.team == unit.team
|
if(build != null && build.team == unit.team
|
||||||
&& unit.within(tile, tilesize * tile.block.size * 1.2f + tilesize * 5f)){
|
&& unit.within(build, tilesize * build.block.size * 1.2f + tilesize * 5f)){
|
||||||
|
|
||||||
//pick up block's payload
|
//pick up block's payload
|
||||||
Payload current = tile.getPayload();
|
Payload current = build.getPayload();
|
||||||
if(current != null && pay.canPickupPayload(current)){
|
if(current != null && pay.canPickupPayload(current)){
|
||||||
Call.pickedBuildPayload(unit, tile, false);
|
Call.pickedBuildPayload(unit, build, false);
|
||||||
//pick up whole building directly
|
//pick up whole building directly
|
||||||
}else if(tile.block.buildVisibility != BuildVisibility.hidden && tile.canPickup() && pay.canPickup(tile)){
|
}else if(build.block.buildVisibility != BuildVisibility.hidden && build.canPickup() && pay.canPickup(build)){
|
||||||
Call.pickedBuildPayload(unit, tile, true);
|
Call.pickedBuildPayload(unit, build, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,29 +224,29 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.server, called = Loc.server)
|
@Remote(targets = Loc.server, called = Loc.server)
|
||||||
public static void pickedBuildPayload(Unit unit, Building tile, boolean onGround){
|
public static void pickedBuildPayload(Unit unit, Building build, boolean onGround){
|
||||||
if(tile != null && unit instanceof Payloadc pay){
|
if(build != null && unit instanceof Payloadc pay){
|
||||||
if(onGround){
|
if(onGround){
|
||||||
if(tile.block.buildVisibility != BuildVisibility.hidden && tile.canPickup() && pay.canPickup(tile)){
|
if(build.block.buildVisibility != BuildVisibility.hidden && build.canPickup() && pay.canPickup(build)){
|
||||||
pay.pickup(tile);
|
pay.pickup(build);
|
||||||
}else{
|
}else{
|
||||||
Fx.unitPickup.at(tile);
|
Fx.unitPickup.at(build);
|
||||||
tile.tile.remove();
|
build.tile.remove();
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
Payload current = tile.getPayload();
|
Payload current = build.getPayload();
|
||||||
if(current != null && pay.canPickupPayload(current)){
|
if(current != null && pay.canPickupPayload(current)){
|
||||||
Payload taken = tile.takePayload();
|
Payload taken = build.takePayload();
|
||||||
if(taken != null){
|
if(taken != null){
|
||||||
pay.addPayload(taken);
|
pay.addPayload(taken);
|
||||||
Fx.unitPickup.at(tile);
|
Fx.unitPickup.at(build);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}else if(tile != null && onGround){
|
}else if(build != null && onGround){
|
||||||
Fx.unitPickup.at(tile);
|
Fx.unitPickup.at(build);
|
||||||
tile.tile.remove();
|
build.tile.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,27 +293,27 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.both, called = Loc.server, forward = true, unreliable = true)
|
@Remote(targets = Loc.both, called = Loc.server, forward = true, unreliable = true)
|
||||||
public static void rotateBlock(@Nullable Player player, Building tile, boolean direction){
|
public static void rotateBlock(@Nullable Player player, Building build, boolean direction){
|
||||||
if(tile == null) return;
|
if(build == null) return;
|
||||||
|
|
||||||
if(net.server() && (!Units.canInteract(player, tile) ||
|
if(net.server() && (!Units.canInteract(player, build) ||
|
||||||
!netServer.admins.allowAction(player, ActionType.rotate, tile.tile(), action -> action.rotation = Mathf.mod(tile.rotation + Mathf.sign(direction), 4)))){
|
!netServer.admins.allowAction(player, ActionType.rotate, build.tile(), action -> action.rotation = Mathf.mod(build.rotation + Mathf.sign(direction), 4)))){
|
||||||
throw new ValidateException(player, "Player cannot rotate a block.");
|
throw new ValidateException(player, "Player cannot rotate a block.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(player != null) tile.lastAccessed = player.name;
|
if(player != null) build.lastAccessed = player.name;
|
||||||
tile.rotation = Mathf.mod(tile.rotation + Mathf.sign(direction), 4);
|
build.rotation = Mathf.mod(build.rotation + Mathf.sign(direction), 4);
|
||||||
tile.updateProximity();
|
build.updateProximity();
|
||||||
tile.noSleep();
|
build.noSleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.both, called = Loc.both, forward = true)
|
@Remote(targets = Loc.both, called = Loc.both, forward = true)
|
||||||
public static void tileConfig(@Nullable Player player, Building tile, @Nullable Object value){
|
public static void tileConfig(@Nullable Player player, Building build, @Nullable Object value){
|
||||||
if(tile == null) return;
|
if(build == null) return;
|
||||||
if(net.server() && (!Units.canInteract(player, tile) ||
|
if(net.server() && (!Units.canInteract(player, build) ||
|
||||||
!netServer.admins.allowAction(player, ActionType.configure, tile.tile, action -> action.config = value))) throw new ValidateException(player, "Player cannot configure a tile.");
|
!netServer.admins.allowAction(player, ActionType.configure, build.tile, action -> action.config = value))) throw new ValidateException(player, "Player cannot configure a tile.");
|
||||||
tile.configured(player == null || player.dead() ? null : player.unit(), value);
|
build.configured(player == null || player.dead() ? null : player.unit(), value);
|
||||||
Core.app.post(() -> Events.fire(new ConfigEvent(tile, player, value)));
|
Core.app.post(() -> Events.fire(new ConfigEvent(build, player, value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//only useful for servers or local mods, and is not replicated across clients
|
//only useful for servers or local mods, and is not replicated across clients
|
||||||
@@ -461,10 +461,10 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
if(target != null){
|
if(target != null){
|
||||||
Call.requestUnitPayload(player, target);
|
Call.requestUnitPayload(player, target);
|
||||||
}else{
|
}else{
|
||||||
Building tile = world.buildWorld(pay.x(), pay.y());
|
Building build = world.buildWorld(pay.x(), pay.y());
|
||||||
|
|
||||||
if(tile != null && tile.team == unit.team){
|
if(build != null && build.team == unit.team){
|
||||||
Call.requestBuildPayload(player, tile);
|
Call.requestBuildPayload(player, build);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -866,8 +866,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Handles tile tap events that are not platform specific. */
|
/** Handles tile tap events that are not platform specific. */
|
||||||
boolean tileTapped(@Nullable Building tile){
|
boolean tileTapped(@Nullable Building build){
|
||||||
if(tile == null){
|
if(build == null){
|
||||||
frag.inv.hide();
|
frag.inv.hide();
|
||||||
frag.config.hideConfig();
|
frag.config.hideConfig();
|
||||||
return false;
|
return false;
|
||||||
@@ -875,18 +875,18 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
boolean consumed = false, showedInventory = false;
|
boolean consumed = false, showedInventory = false;
|
||||||
|
|
||||||
//check if tapped block is configurable
|
//check if tapped block is configurable
|
||||||
if(tile.block.configurable && tile.interactable(player.team())){
|
if(build.block.configurable && build.interactable(player.team())){
|
||||||
consumed = true;
|
consumed = true;
|
||||||
if(((!frag.config.isShown() && tile.shouldShowConfigure(player)) //if the config fragment is hidden, show
|
if(((!frag.config.isShown() && build.shouldShowConfigure(player)) //if the config fragment is hidden, show
|
||||||
//alternatively, the current selected block can 'agree' to switch config tiles
|
//alternatively, the current selected block can 'agree' to switch config tiles
|
||||||
|| (frag.config.isShown() && frag.config.getSelectedTile().onConfigureTileTapped(tile)))){
|
|| (frag.config.isShown() && frag.config.getSelectedTile().onConfigureTileTapped(build)))){
|
||||||
Sounds.click.at(tile);
|
Sounds.click.at(build);
|
||||||
frag.config.showConfig(tile);
|
frag.config.showConfig(build);
|
||||||
}
|
}
|
||||||
//otherwise...
|
//otherwise...
|
||||||
}else if(!frag.config.hasConfigMouse()){ //make sure a configuration fragment isn't on the cursor
|
}else if(!frag.config.hasConfigMouse()){ //make sure a configuration fragment isn't on the cursor
|
||||||
//then, if it's shown and the current block 'agrees' to hide, hide it.
|
//then, if it's shown and the current block 'agrees' to hide, hide it.
|
||||||
if(frag.config.isShown() && frag.config.getSelectedTile().onConfigureTileTapped(tile)){
|
if(frag.config.isShown() && frag.config.getSelectedTile().onConfigureTileTapped(build)){
|
||||||
consumed = true;
|
consumed = true;
|
||||||
frag.config.hideConfig();
|
frag.config.hideConfig();
|
||||||
}
|
}
|
||||||
@@ -897,16 +897,16 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//call tapped event
|
//call tapped event
|
||||||
if(!consumed && tile.interactable(player.team())){
|
if(!consumed && build.interactable(player.team())){
|
||||||
tile.tapped();
|
build.tapped();
|
||||||
}
|
}
|
||||||
|
|
||||||
//consume tap event if necessary
|
//consume tap event if necessary
|
||||||
if(tile.interactable(player.team()) && tile.block.consumesTap){
|
if(build.interactable(player.team()) && build.block.consumesTap){
|
||||||
consumed = true;
|
consumed = true;
|
||||||
}else if(tile.interactable(player.team()) && tile.block.synthetic() && !consumed){
|
}else if(build.interactable(player.team()) && build.block.synthetic() && !consumed){
|
||||||
if(tile.block.hasItems && tile.items.total() > 0){
|
if(build.block.hasItems && build.items.total() > 0){
|
||||||
frag.inv.showFor(tile);
|
frag.inv.showFor(build);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
showedInventory = true;
|
showedInventory = true;
|
||||||
}
|
}
|
||||||
@@ -1006,8 +1006,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Building tile = world.buildWorld(Core.input.mouseWorld().x, Core.input.mouseWorld().y);
|
Building build = world.buildWorld(Core.input.mouseWorld().x, Core.input.mouseWorld().y);
|
||||||
if(tile instanceof ControlBlock cont && cont.canControl() && tile.team == player.team()){
|
if(build instanceof ControlBlock cont && cont.canControl() && build.team == player.team()){
|
||||||
return cont.unit();
|
return cont.unit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1071,7 +1071,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
return droppingItem && !canTapPlayer(Core.input.mouseWorldX(), Core.input.mouseWorldY());
|
return droppingItem && !canTapPlayer(Core.input.mouseWorldX(), Core.input.mouseWorldY());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tryDropItems(@Nullable Building tile, float x, float y){
|
public void tryDropItems(@Nullable Building build, float x, float y){
|
||||||
if(!droppingItem || player.unit().stack.amount <= 0 || canTapPlayer(x, y) || state.isPaused() ){
|
if(!droppingItem || player.unit().stack.amount <= 0 || canTapPlayer(x, y) || state.isPaused() ){
|
||||||
droppingItem = false;
|
droppingItem = false;
|
||||||
return;
|
return;
|
||||||
@@ -1081,8 +1081,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
|
|
||||||
ItemStack stack = player.unit().stack;
|
ItemStack stack = player.unit().stack;
|
||||||
|
|
||||||
if(tile != null && tile.acceptStack(stack.item, stack.amount, player.unit()) > 0 && tile.interactable(player.team()) && tile.block.hasItems && player.unit().stack().amount > 0 && tile.interactable(player.team())){
|
if(build != null && build.acceptStack(stack.item, stack.amount, player.unit()) > 0 && build.interactable(player.team()) && build.block.hasItems && player.unit().stack().amount > 0 && build.interactable(player.team())){
|
||||||
Call.transferInventory(player, tile);
|
Call.transferInventory(player, build);
|
||||||
}else{
|
}else{
|
||||||
Call.dropItem(player.angleTo(x, y));
|
Call.dropItem(player.angleTo(x, y));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user