Add CArea, RInteractionCallback

Add DynamicRegionEditor, DynamicRegionVisualizer
This commit is contained in:
2026-03-28 21:36:34 +01:00
parent 1b3b563fd3
commit 4c8b55167c
24 changed files with 606 additions and 347 deletions
@@ -0,0 +1,83 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.entity;
import org.bukkit.Location;
import org.bukkit.block.data.BlockData;
import org.bukkit.util.Vector;
import java.util.List;
public class CArea extends CEntity {
public static final float DEFAULT_WIDTH = 1 / 16f;
private Location pos1;
private Location pos2;
private float width = DEFAULT_WIDTH;
public CArea(REntityServer server) {
super(server);
for (int i = 0; i < 4; i++) {
entities.add(new CLine(server));
}
}
public CArea setPos1And2(Location pos1, Location pos2) {
if (pos1.getY() != pos2.getY()) return this;
this.pos1 = pos1;
this.pos2 = pos2;
updateAndSpawnLines();
return this;
}
public CArea setWidth(float width) {
this.width = width;
updateAndSpawnLines();
getEntitiesByType(CLine.class).forEach(haaLine -> {
haaLine.setWidth(width);
});
return this;
}
public CArea setBlock(BlockData blockData) {
getEntitiesByType(CLine.class).forEach(haaLine -> {
haaLine.setBlock(blockData);
});
return this;
}
private void updateAndSpawnLines() {
List<CLine> lines = getEntitiesByType(CLine.class);
if (pos1 == null || pos2 == null) {
lines.forEach(line -> line.setFromAndTo(null, null));
return;
}
Vector min = Vector.getMinimum(pos1.toVector(), pos2.toVector());
Vector max = Vector.getMaximum(pos1.toVector(), pos2.toVector())
.add(new Vector(1 - width, 0, 1 - width));
lines.get(0).setFromAndTo(new Location(null, min.getX(), min.getY(), min.getZ()), new Location(null, max.getX() + width, min.getY(), min.getZ()));
lines.get(1).setFromAndTo(new Location(null, min.getX(), min.getY(), max.getZ()), new Location(null, max.getX() + width, min.getY(), max.getZ()));
lines.get(2).setFromAndTo(new Location(null, min.getX(), min.getY(), min.getZ()), new Location(null, min.getX(), min.getY(), max.getZ() + width));
lines.get(3).setFromAndTo(new Location(null, max.getX(), min.getY(), min.getZ()), new Location(null, max.getX(), min.getY(), max.getZ() + width));
}
}
@@ -22,7 +22,6 @@ package de.steamwar.entity;
import de.steamwar.core.BountifulWrapper;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@@ -40,9 +39,8 @@ public class RInteraction extends REntity {
protected final Consumer<Object> updatePacketSink = o -> server.updateEntity(this, o);
@Setter
@Getter(AccessLevel.PRIVATE)
protected BiConsumer<Player, REntityServer.EntityAction> interaction;
protected RInteractionCallback callback;
private float interactionWidth = 1.0f;
private float interactionHeight = 1.0f;
@@ -116,4 +114,12 @@ public class RInteraction extends REntity {
dataSink.accept(responsiveWatcher, responsive);
}
}
public void setCallback(RInteractionCallback callback) {
this.callback = callback;
}
public void setCallback(BiConsumer<Player, REntityServer.EntityAction> callback) {
this.callback = (player, interaction, entityAction) -> callback.accept(player, entityAction);
}
}
@@ -0,0 +1,26 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.entity;
import org.bukkit.entity.Player;
public interface RInteractionCallback {
void call(Player player, RInteraction interaction, REntityServer.EntityAction entityAction);
}