diff options
-rw-r--r-- | src/main/java/los/numeros/EPHS/Constants.java | 15 | ||||
-rw-r--r-- | src/main/java/los/numeros/EPHS/Main.java | 79 | ||||
-rw-r--r-- | src/main/java/los/numeros/EPHS/modules/DeathWatcherModule.java | 17 | ||||
-rw-r--r-- | src/main/java/los/numeros/EPHS/modules/GameClockModule.java | 116 | ||||
-rw-r--r-- | src/main/java/los/numeros/EPHS/modules/MainModule.java | 105 |
5 files changed, 332 insertions, 0 deletions
diff --git a/src/main/java/los/numeros/EPHS/Constants.java b/src/main/java/los/numeros/EPHS/Constants.java new file mode 100644 index 0000000..0c96400 --- /dev/null +++ b/src/main/java/los/numeros/EPHS/Constants.java @@ -0,0 +1,15 @@ +package los.numeros.EPHS; + +public class Constants { + public static double spawnX = 0; + public static double spawnY = 0; + public static double spawnZ = 0; + + public static double seekerSpawnX = 0; + public static double seekerSpawnY = 0; + public static double seekerSpawnZ = 0; + + public static double hidersSpawnX = 0; + public static double hidersSpawnY = 0; + public static double hidersSpawnZ = 0; +} diff --git a/src/main/java/los/numeros/EPHS/Main.java b/src/main/java/los/numeros/EPHS/Main.java new file mode 100644 index 0000000..530bc20 --- /dev/null +++ b/src/main/java/los/numeros/EPHS/Main.java @@ -0,0 +1,79 @@ +package los.numeros.EPHS; + +import java.util.Random; +import java.util.UUID; +import java.util.Collection; +import java.util.Date; +import java.util.function.BooleanSupplier; + +import los.numeros.GameEngine.Engine; +import los.numeros.GameEngine.Module; +import net.fabricmc.fabric.api.networking.v1.PlayerLookup; +import net.minecraft.network.MessageType; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import los.numeros.HidersAndDiggers.modules.*; + +public class Main implements Engine { + BooleanSupplier running = () -> { return true; }; + Module modules[] = new Module[10]; + + public Main(ServerCommandSource source, int numDiggers) { + int i; + MinecraftServer server = source.getMinecraftServer(); + ServerPlayerEntity[] players, diggers, hiders; + Random r = new Random(new Date().getTime()); + + /* get all the players on the server */ + Collection<ServerPlayerEntity> playerCollection = PlayerLookup.all(server); + players = playerCollection.toArray(new ServerPlayerEntity[playerCollection.size()]); + + /* create the hiders and diggers array of appropriate sizes */ + diggers = new ServerPlayerEntity[numDiggers]; + hiders = new ServerPlayerEntity[players.length - numDiggers]; + + /* too few players to start the game */ + if (players.length <= 2) { + /* send a message letting everyone know there aren't enough players to start the game */ + server.getPlayerManager().broadcastChatMessage( + new LiteralText("Not enough players to start the game"), + MessageType.SYSTEM, + new UUID(0, 0) + ); + return; + } + + /* creates an array of diggers */ + for (i = 0; numDiggers > 0; numDiggers--, i++) { + /* TODO: make sure the same person isn't picked to be all of the diggers */ + diggers[i] = players[r.nextInt(players.length)]; + } + + /* creates an array of hiders */ + i = 0; + for (ServerPlayerEntity p : players) { + /* add all players who arent diggers to the hiders array */ + if (!hasPlayer(diggers, p)) { + hiders[i++] = p; + } + } + + /* populate the modules */ + modules[0] = new MainModule(diggers, hiders, players, source); + modules[1] = new GameClockModule(diggers, hiders, players, server); + + /* start the game */ + Engine.StartEngine(running, modules); + } + + private boolean hasPlayer(ServerPlayerEntity[] array, ServerPlayerEntity player) + { + for (ServerPlayerEntity p : array) { + if (p == player) + return true; + } + return false; + } +} diff --git a/src/main/java/los/numeros/EPHS/modules/DeathWatcherModule.java b/src/main/java/los/numeros/EPHS/modules/DeathWatcherModule.java new file mode 100644 index 0000000..86c7b41 --- /dev/null +++ b/src/main/java/los/numeros/EPHS/modules/DeathWatcherModule.java @@ -0,0 +1,17 @@ +package los.numeros.EPHS.modules; + +import los.numeros.GameEngine.Module; + +public class DeathWatcherModule implements Module { + @Override + public int init() + { + return 0; + } + + @Override + public int end() + { + return 0; + } +} diff --git a/src/main/java/los/numeros/EPHS/modules/GameClockModule.java b/src/main/java/los/numeros/EPHS/modules/GameClockModule.java new file mode 100644 index 0000000..9c64a88 --- /dev/null +++ b/src/main/java/los/numeros/EPHS/modules/GameClockModule.java @@ -0,0 +1,116 @@ +package los.numeros.EPHS.modules; + +import java.util.UUID; + +import los.numeros.GameEngine.Module; +import los.numeros.utils.MinecraftTick; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.network.MessageType; +import net.minecraft.network.packet.s2c.play.TitleS2CPacket; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.sound.SoundEvents; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; +import net.minecraft.text.TextColor; + +public class GameClockModule implements Module { + private ServerPlayerEntity[] diggers, hiders, players; + private MinecraftServer server; + private MinecraftTick minecraftTick = new MinecraftTick(); + private int i, j; + private LiteralText diggersString; + + private long tickCounter; + private boolean hidersVisible = false; + + public GameClockModule(ServerPlayerEntity diggers[], ServerPlayerEntity hiders[], ServerPlayerEntity[] players, MinecraftServer server) { + this.diggers = diggers; + this.hiders = hiders; + this.players = players; + this.server = server; + } + + private void playCountdownClick() { + for (ServerPlayerEntity p : players) { + p.playSound(SoundEvents.BLOCK_NOTE_BLOCK_HAT, 0.75f, 0.1f); + } + } + + private void preGameClock() { + server.getPlayerManager().broadcastChatMessage( + new LiteralText("20s").setStyle(Style.EMPTY.withColor(TextColor.parse("light_green"))), + MessageType.SYSTEM, + new UUID(0, 0) + ); + playCountdownClick(); + + minecraftTick.delayCallback(MinecraftTick.secondToTick(10), (tickDelay) -> { + server.getPlayerManager().broadcastChatMessage( + new LiteralText("10s").setStyle(Style.EMPTY.withColor(TextColor.parse("light_green"))), + MessageType.SYSTEM, + new UUID(0, 0) + ); + playCountdownClick(); + }); + + /* countdown 5 -> 1 */ + for (i = 15, j = 5; j > 0; i++, j--) { + minecraftTick.delayCallback(MinecraftTick.secondToTick(i), (tickDelay) -> { + final int countdown = Math.abs(MinecraftTick.tickToSecond(tickDelay) - 20); + final String color = countdown <= 3 ? "red" : "yellow"; + + playCountdownClick(); + server.getPlayerManager().broadcastChatMessage( + new LiteralText(String.valueOf(countdown + "s")) + .setStyle(Style.EMPTY.withColor(TextColor.parse(color))), + MessageType.SYSTEM, + new UUID(0, 0) + ); + }); + } + + /* wait 20 seconds */ + minecraftTick.delayCallback(MinecraftTick.secondToTick(20), (tickDelay) -> { + /* make title screen adhere to gammar */ + if (diggers.length > 1) { + diggersString = new LiteralText("The Diggers are Digging"); + } else { + diggersString = new LiteralText("The Digger is Digging"); + } + + /* style text */ + diggersString.setStyle(Style.EMPTY.withColor(TextColor.parse("red"))); + + /* send chat message */ + server.getPlayerManager().broadcastChatMessage( + diggersString, + MessageType.SYSTEM, + new UUID(0, 0) + ); + + /* set title screen */ + server.getPlayerManager().sendToAll( + new TitleS2CPacket(TitleS2CPacket.Action.TITLE, diggersString) + ); + + for (ServerPlayerEntity p : players) { + p.playSound(SoundEvents.BLOCK_NOTE_BLOCK_BASEDRUM, 1f, 0.5f); + } + }); + } + + + @Override + public int init() { + preGameClock(); + return 0; + } + + @Override + public int end() { + return 0; + } +} diff --git a/src/main/java/los/numeros/EPHS/modules/MainModule.java b/src/main/java/los/numeros/EPHS/modules/MainModule.java new file mode 100644 index 0000000..ea7a923 --- /dev/null +++ b/src/main/java/los/numeros/EPHS/modules/MainModule.java @@ -0,0 +1,105 @@ +package los.numeros.EPHS.modules; + +import los.numeros.GameEngine.Module; +import los.numeros.utils.GiveItem; +import net.minecraft.enchantment.Enchantments; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.GameMode; +import los.numeros.EPHS.Constants; + +public class MainModule implements Module { + ServerPlayerEntity[] diggers, hidders, players; + ServerCommandSource source; + + public MainModule(ServerPlayerEntity[] diggers, ServerPlayerEntity[] hidders, ServerPlayerEntity[] players, ServerCommandSource source) { + this.diggers = diggers; + this.hidders = hidders; + this.players = players; + this.source = source; + } + + public void giveSeekerItems(ServerPlayerEntity[] diggers) { + for (ServerPlayerEntity p : diggers) { + // give armor + GiveItem.givePlayerItem(p, "diamond_helmet", GiveItem.ARMOR_HEAD); + GiveItem.givePlayerItem(p, "diamond_leggings", GiveItem.ARMOR_LEGS); + GiveItem.givePlayerItem(p, "diamond_chestplate", GiveItem.ARMOR_CHEST); + GiveItem.givePlayerItem(p, "diamond_boots", GiveItem.ARMOR_BOOTS); + + ItemStack sword = GiveItem.getItem("iron_sword"); + sword.addEnchantment(Enchantments.SHARPNESS, 1); + + // make sword unbreakable + NbtCompound sTag = sword.getTag(); + sTag.putBoolean("Unbreakable", true); + sword.setTag(sTag); + p.equip(0, sword); + + // teleport to the seeker box + p.teleport(Constants.seekerSpawnX, Constants.seekerSpawnY, Constants.seekerSpawnZ); + } + } + + public void giveHidersItems(ServerPlayerEntity[] hiders) { + // get pick with silk touch + ItemStack pickaxe = GiveItem.getItem("diamond_pickaxe"); + pickaxe.addEnchantment(Enchantments.SILK_TOUCH, 1); + + // put unbreakable attribute into NBT tag + NbtCompound pTag = pickaxe.getTag(); + pTag.putBoolean("Unbreakable", true); + pickaxe.setTag(pTag); + + for (ServerPlayerEntity p : hiders) { + // equip picaxe on each player + p.equip(0, pickaxe); + // give stone x10 + GiveItem.giveMultipleItem(p, "minecraft:stone", null, 10); + p.teleport(Constants.hidersSpawnX, Constants.hidersSpawnY, Constants.hidersSpawnZ); + } + } + + @Override + public int init() + { + // Give items and status effects to everyone playing game + for (ServerPlayerEntity p : players) { + // Put everyone to full health and hunger and give them night vision on haste until game ends + p.inventory.clear(); + p.addStatusEffect(new StatusEffectInstance(StatusEffects.NIGHT_VISION, 200000000, 3, false, false)); + p.addStatusEffect(new StatusEffectInstance(StatusEffects.HASTE, 200000000, 1, false, false)); + p.addStatusEffect(new StatusEffectInstance(StatusEffects.SATURATION, 300, 100, false, false)); + p.heal(20); + + // give steak x64 + GiveItem.giveMultipleItem(p, "cooked_beef", 2, 64); + + p.setGameMode(GameMode.SURVIVAL); + } + giveSeekerItems(diggers); + giveHidersItems(hidders); + + ServerWorld world = source.getWorld(); + + // TODO: FILL AND TP PLAYERS AND CLEAR ALL ITEMS + return 0; + } + + @Override + public int end() + { + for (ServerPlayerEntity p : players) { + p.teleport(Constants.spawnX, Constants.spawnY, Constants.spawnZ); + p.clearStatusEffects(); + p.setGameMode(GameMode.CREATIVE); + p.inventory.clear(); + } + return 0; + } +}
\ No newline at end of file |