Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import net.theevilreaper.aves.map.BaseMapBuilder;
import org.jetbrains.annotations.Nullable;

import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public final class GameMapBuilder extends BaseMapBuilder {

Expand All @@ -22,7 +24,11 @@ public final class GameMapBuilder extends BaseMapBuilder {
public GameMapBuilder() {
super();
this.pageFaces = new HashSet<>();
this.survivorSpawns = new HashSet<>();
this.survivorSpawns = new TreeSet<>(
Comparator.comparingInt(Pos::blockX)
.thenComparingInt(Pos::blockY)
.thenComparingInt(Pos::blockZ)
);
}

/**
Expand All @@ -33,7 +39,11 @@ public GameMapBuilder() {
public GameMapBuilder(GameMap gameMap) {
super(gameMap);
this.slenderSpawn = gameMap.getSlenderSpawn();
this.survivorSpawns = gameMap.getSurvivorSpawns();
this.survivorSpawns = new TreeSet<>(
Comparator.comparingInt(Pos::blockX)
.thenComparingInt(Pos::blockY)
.thenComparingInt(Pos::blockZ)
);
this.pageFaces = gameMap.getPageFaces();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minestom.server.MinecraftServer;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.event.EventListener;
import net.minestom.server.event.GlobalEventHandler;
import net.minestom.server.event.instance.AddEntityToInstanceEvent;
import net.minestom.server.event.instance.RemoveEntityFromInstanceEvent;
Expand All @@ -13,7 +14,6 @@
import net.minestom.server.event.player.PlayerUseItemEvent;
import net.onelitefeather.cygnus.common.ListenerHandling;
import net.minestom.server.instance.Instance;
import net.onelitefeather.cygnus.setup.command.SetupCommand;
import net.onelitefeather.cygnus.setup.event.MapSetupSaveEvent;
import net.onelitefeather.cygnus.setup.event.MapSetupSelectEvent;
import net.onelitefeather.cygnus.setup.event.PositionSetEvent;
Expand All @@ -25,6 +25,7 @@
import net.onelitefeather.cygnus.setup.listener.PageCreationListener;
import net.onelitefeather.cygnus.setup.listener.PlayerSpawnListener;
import net.onelitefeather.cygnus.setup.listener.SetupItemListener;
import net.onelitefeather.cygnus.setup.listener.SpawnCreationListener;
import net.onelitefeather.cygnus.setup.listener.dialog.DialogPayloadListener;
import net.onelitefeather.cygnus.setup.listener.dialog.DialogRequestListener;
import net.onelitefeather.cygnus.setup.listener.map.MapSetupSaveListener;
Expand Down Expand Up @@ -56,7 +57,6 @@ private void registerSetupComponents() {
var manager = MinecraftServer.getGlobalEventHandler();
var commandManager = MinecraftServer.getCommandManager();
var spawnPos = new Pos(0, 150, 0);
commandManager.register(new SetupCommand(setupData));

Supplier<Instance> instanceSupplier = this.mapProvider.getActiveInstance();
UUID instanceUUID = instanceSupplier.get().getUuid();
Expand All @@ -71,7 +71,10 @@ private void registerSetupComponents() {
this.dataService.remove(event.getPlayer().getUuid());
});
manager.addListener(PlayerBlockBreakEvent.class, new PageCreationListener(this.dataService));

manager.addListener(EventListener.builder(PlayerBlockBreakEvent.class)
.ignoreCancelled(false)
.handler(new SpawnCreationListener(this.dataService))
.build());
manager.addListener(AddEntityToInstanceEvent.class, new InstanceAddListener(instanceUUID));
manager.addListener(RemoveEntityFromInstanceEvent.class, new InstanceRemoveListener(instanceUUID));
registerCancelListener(manager);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
private final SurvivorViewInventory survivorInventory;
private GameMapBuilder gameMapBuilder;
private boolean pageMode;
private boolean survivorMode;

/**
* Constructs a new GameData instance.
Expand All @@ -42,7 +43,6 @@
throw new IllegalArgumentException("Player with UUID " + uuid + " is not online.");
}

System.out.println("After loadData: " + System.identityHashCode(this.gameMapBuilder));
this.inventory = new MapDataOverviewInventory(player, this.gameMapBuilder, InventoryMode.GAME);
this.survivorInventory = new SurvivorViewInventory(player, this.gameMapBuilder);
}
Expand All @@ -54,6 +54,8 @@
this.pageMode = !this.pageMode;
}

public void swapSurvivorMode() { this.survivorMode = !this.survivorMode; }

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -97,6 +99,17 @@
((GameMapBuilder) getMapBuilder()).setSlenderSpawn(pos);
triggerUpdate(InventoryTarget.GENERAL);
}
case SURVIVOR -> {
Pos spawnPos = new Pos(
pos.blockX(),
pos.blockY() + 1,
pos.blockZ(),
player.getPosition().yaw(),
0f
);
this.gameMapBuilder.addSurvivorSpawn(spawnPos);
triggerUpdate(InventoryTarget.SURVIVOR);
}
default -> {}
}
}
Expand All @@ -121,6 +134,24 @@
SetupItems.setGameLayout(player);
return;
}

if (5 == tagValue) {
this.swapSurvivorMode();
SetupItems.setSurvivorSpawn(player);
return;
}

if (6 == tagValue) {
this.openInventory(InventoryTarget.SURVIVOR);
return;
}

if (7 == tagValue) {
this.swapSurvivorMode();
SetupItems.setGameLayout(player);
return;
}

super.handleItemInteraction(player, tagValue);
}

Expand Down Expand Up @@ -170,7 +201,7 @@
}
// this.inventory = new LobbyViewInventory(this.gameMapBuilder);
this.instance = MinecraftServer.getInstanceManager().createInstanceContainer();
AnvilLoader anvilLoader = new AnvilLoader(this.mapEntry.getDirectoryRoot());

Check warning on line 204 in setup/src/main/java/net/onelitefeather/cygnus/setup/data/GameData.java

View workflow job for this annotation

GitHub Actions / Build Pull Request Branch (ubuntu-latest)

[removal] AnvilLoader(Path) in AnvilLoader has been deprecated and marked for removal

Check warning on line 204 in setup/src/main/java/net/onelitefeather/cygnus/setup/data/GameData.java

View workflow job for this annotation

GitHub Actions / Build Pull Request Branch (macos-latest)

[removal] AnvilLoader(Path) in AnvilLoader has been deprecated and marked for removal
this.instance.setChunkLoader(anvilLoader);
this.updateTitle();
MinecraftServer.getInstanceManager().registerInstance(this.instance);
Expand All @@ -185,6 +216,10 @@
return pageMode;
}

public boolean hasSurvivorMode() {
return this.survivorMode;
}

/**
* Returns the GameMapBuilder instance used for building the game map.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class SurvivorViewInventory extends PersonalInventoryBuilder {

private static final int[] SLOTS = LayoutCalculator.quad(InventoryType.CHEST_1_ROW.getSize() + 1, InventoryType.CHEST_5_ROW.getSize());
private static final int[] SLOTS = LayoutCalculator.quad(InventoryType.CHEST_1_ROW.getSize(), InventoryType.CHEST_5_ROW.getSize() - 1);
private final GameMapBuilder mapBuilder;

/**
Expand All @@ -35,19 +35,19 @@ public SurvivorViewInventory(Player player, GameMapBuilder mapBuilder) {
setLayout(layout);

this.setDataLayoutFunction(dataLayout -> {
dataLayout = dataLayout != null ? dataLayout : InventoryLayout.fromType(getType());

if (this.mapBuilder.getSurvivorSpawns().isEmpty()) return dataLayout;

InventoryLayout internalLayout = dataLayout != null ? dataLayout : InventoryLayout.fromType(getType());
if (this.mapBuilder.getSurvivorSpawns().isEmpty()) {
return internalLayout;
}
Iterator<Pos> iterator = mapBuilder.getSurvivorSpawns().iterator();

for (int i = 0; i < SLOTS.length && iterator.hasNext(); i++) {
Pos pos = iterator.next();
dataLayout.setItem(SLOTS[i], new PositionSlot(MapDataCategory.SPAWN, pos));
internalLayout.setItem(SLOTS[i], new PositionSlot(MapDataCategory.SURVIVOR, pos));
}
return dataLayout;
return internalLayout;
});

this.invalidateLayout();
register();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public final class SetupItems {
private static final HotBarLayout lobbySetupLayout;
private static final HotBarLayout gameSetupLayout;
private static final HotBarLayout pageLayout;
private static final HotBarLayout survivorSpawnLayout;

static {
DECORATION_PANE = ItemStack.builder(Material.BLACK_STAINED_GLASS_PANE).customName(Component.empty()).build();
Expand All @@ -48,24 +49,42 @@ public final class SetupItems {
lobbySetupLayout.set(6, saveItem);

gameSetupLayout = new HotBarLayout();
gameSetupLayout.set(2, ItemStack.builder(Material.COMPASS)
gameSetupLayout.set(1, ItemStack.builder(Material.COMPASS)
.customName(Component.text("Data", NamedTextColor.AQUA))
.set(Tags.ITEM_TAG, (byte) 0x02)
.build()
);
gameSetupLayout.set(4, ItemStack.builder(Material.PAPER)
gameSetupLayout.set(3, ItemStack.builder(Material.PAPER)
.customName(Component.text("Page", NamedTextColor.AQUA))
.set(Tags.ITEM_TAG, (byte) 0x03)
.build()
);
gameSetupLayout.set(6, saveItem);
gameSetupLayout.set(5, ItemStack.builder(Material.MINECART)
.customName(Component.text("Survivor", NamedTextColor.YELLOW))
.set(Tags.ITEM_TAG, (byte) 0x05)
.build()
);
gameSetupLayout.set(7, saveItem);

pageLayout = new HotBarLayout();
pageLayout.set(2, ItemStack.builder(Material.BARRIER)
pageLayout.set(4, ItemStack.builder(Material.BARRIER)
.customName(Component.text("Leave page mode", NamedTextColor.RED))
.set(Tags.ITEM_TAG, (byte) 0x04)
.build()
);

survivorSpawnLayout = new HotBarLayout();
survivorSpawnLayout.set(2, ItemStack.builder(Material.CHEST)
.customName(Component.text("Spawns", NamedTextColor.AQUA))
.set(Tags.ITEM_TAG, (byte) 0x06)
.build()
);
survivorSpawnLayout.set(6
, ItemStack.builder(Material.BARRIER)
.customName(Component.text("Leave mode", NamedTextColor.RED))
.set(Tags.ITEM_TAG, (byte) 0x07)
.build()
);
}

/**
Expand Down Expand Up @@ -98,6 +117,16 @@ public static void setGameLayout(Player player) {
player.setHeldItemSlot(FOURTH_INDEX);
}

/**
* Set's the {@link ItemStack} which are required for the survivor setup.
*
* @param player who should receive the items
*/
public static void setSurvivorSpawn(Player player) {
survivorSpawnLayout.apply(player);
player.setHeldItemSlot(ZERO_INDEX);
}

/**
* Set's the {@link ItemStack} which are required for the page setup.
*
Expand Down
Loading
Loading