diff --git a/output/production/snake.main/assets/dp_snake/icon.png b/output/production/snake.main/assets/dp_snake/icon.png deleted file mode 100644 index 6128a65..0000000 Binary files a/output/production/snake.main/assets/dp_snake/icon.png and /dev/null differ diff --git a/output/production/snake.main/assets/dp_snake/lang/en_us.json b/output/production/snake.main/assets/dp_snake/lang/en_us.json deleted file mode 100644 index 5b70fe9..0000000 --- a/output/production/snake.main/assets/dp_snake/lang/en_us.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "item.dp_snake.snake_north": "North", - "item.dp_snake.snake_east": "East", - "item.dp_snake.snake_south": "South", - "item.dp_snake.snake_west": "West", - "command.dp_snake.snake.stop.failed": "You're not currently playing a game of snake!" -} \ No newline at end of file diff --git a/output/production/snake.main/assets/dp_snake/models/item/snake_east.json b/output/production/snake.main/assets/dp_snake/models/item/snake_east.json deleted file mode 100644 index f72833a..0000000 --- a/output/production/snake.main/assets/dp_snake/models/item/snake_east.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "item/generated", - "textures": { - "layer0": "dp_snake:item/snake_east" - } -} \ No newline at end of file diff --git a/output/production/snake.main/assets/dp_snake/models/item/snake_north.json b/output/production/snake.main/assets/dp_snake/models/item/snake_north.json deleted file mode 100644 index 1308dee..0000000 --- a/output/production/snake.main/assets/dp_snake/models/item/snake_north.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "item/generated", - "textures": { - "layer0": "dp_snake:item/snake_north" - } -} \ No newline at end of file diff --git a/output/production/snake.main/assets/dp_snake/models/item/snake_south.json b/output/production/snake.main/assets/dp_snake/models/item/snake_south.json deleted file mode 100644 index 821445f..0000000 --- a/output/production/snake.main/assets/dp_snake/models/item/snake_south.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "item/generated", - "textures": { - "layer0": "dp_snake:item/snake_south" - } -} \ No newline at end of file diff --git a/output/production/snake.main/assets/dp_snake/models/item/snake_west.json b/output/production/snake.main/assets/dp_snake/models/item/snake_west.json deleted file mode 100644 index b289d67..0000000 --- a/output/production/snake.main/assets/dp_snake/models/item/snake_west.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "item/generated", - "textures": { - "layer0": "dp_snake:item/snake_west" - } -} \ No newline at end of file diff --git a/output/production/snake.main/assets/dp_snake/textures/item/snake_east.png b/output/production/snake.main/assets/dp_snake/textures/item/snake_east.png deleted file mode 100644 index c06e1ba..0000000 Binary files a/output/production/snake.main/assets/dp_snake/textures/item/snake_east.png and /dev/null differ diff --git a/output/production/snake.main/assets/dp_snake/textures/item/snake_north.png b/output/production/snake.main/assets/dp_snake/textures/item/snake_north.png deleted file mode 100644 index a50f27f..0000000 Binary files a/output/production/snake.main/assets/dp_snake/textures/item/snake_north.png and /dev/null differ diff --git a/output/production/snake.main/assets/dp_snake/textures/item/snake_south.png b/output/production/snake.main/assets/dp_snake/textures/item/snake_south.png deleted file mode 100644 index 3032c48..0000000 Binary files a/output/production/snake.main/assets/dp_snake/textures/item/snake_south.png and /dev/null differ diff --git a/output/production/snake.main/assets/dp_snake/textures/item/snake_west.png b/output/production/snake.main/assets/dp_snake/textures/item/snake_west.png deleted file mode 100644 index 4b20932..0000000 Binary files a/output/production/snake.main/assets/dp_snake/textures/item/snake_west.png and /dev/null differ diff --git a/output/production/snake.main/com/gmail/s154095g/dp_snake/SnakeMod.class b/output/production/snake.main/com/gmail/s154095g/dp_snake/SnakeMod.class deleted file mode 100644 index 4eeabc9..0000000 Binary files a/output/production/snake.main/com/gmail/s154095g/dp_snake/SnakeMod.class and /dev/null differ diff --git a/output/production/snake.main/com/gmail/s154095g/dp_snake/Utils.class b/output/production/snake.main/com/gmail/s154095g/dp_snake/Utils.class deleted file mode 100644 index f797c48..0000000 Binary files a/output/production/snake.main/com/gmail/s154095g/dp_snake/Utils.class and /dev/null differ diff --git a/output/production/snake.main/com/gmail/s154095g/dp_snake/command/SnakeCommand.class b/output/production/snake.main/com/gmail/s154095g/dp_snake/command/SnakeCommand.class deleted file mode 100644 index 656dc62..0000000 Binary files a/output/production/snake.main/com/gmail/s154095g/dp_snake/command/SnakeCommand.class and /dev/null differ diff --git a/output/production/snake.main/com/gmail/s154095g/dp_snake/item/SnakeController.class b/output/production/snake.main/com/gmail/s154095g/dp_snake/item/SnakeController.class deleted file mode 100644 index e909296..0000000 Binary files a/output/production/snake.main/com/gmail/s154095g/dp_snake/item/SnakeController.class and /dev/null differ diff --git a/output/production/snake.main/com/gmail/s154095g/dp_snake/mixin/AntiDropMixin.class b/output/production/snake.main/com/gmail/s154095g/dp_snake/mixin/AntiDropMixin.class deleted file mode 100644 index a4ef946..0000000 Binary files a/output/production/snake.main/com/gmail/s154095g/dp_snake/mixin/AntiDropMixin.class and /dev/null differ diff --git a/output/production/snake.main/com/gmail/s154095g/dp_snake/mixin/EndGameOnDeathMixin.class b/output/production/snake.main/com/gmail/s154095g/dp_snake/mixin/EndGameOnDeathMixin.class deleted file mode 100644 index fedb07c..0000000 Binary files a/output/production/snake.main/com/gmail/s154095g/dp_snake/mixin/EndGameOnDeathMixin.class and /dev/null differ diff --git a/output/production/snake.main/com/gmail/s154095g/dp_snake/snake/SnakeGame$1.class b/output/production/snake.main/com/gmail/s154095g/dp_snake/snake/SnakeGame$1.class deleted file mode 100644 index 126870c..0000000 Binary files a/output/production/snake.main/com/gmail/s154095g/dp_snake/snake/SnakeGame$1.class and /dev/null differ diff --git a/output/production/snake.main/com/gmail/s154095g/dp_snake/snake/SnakeGame$ItemPos.class b/output/production/snake.main/com/gmail/s154095g/dp_snake/snake/SnakeGame$ItemPos.class deleted file mode 100644 index 5e62343..0000000 Binary files a/output/production/snake.main/com/gmail/s154095g/dp_snake/snake/SnakeGame$ItemPos.class and /dev/null differ diff --git a/output/production/snake.main/com/gmail/s154095g/dp_snake/snake/SnakeGame.class b/output/production/snake.main/com/gmail/s154095g/dp_snake/snake/SnakeGame.class deleted file mode 100644 index 9b5a738..0000000 Binary files a/output/production/snake.main/com/gmail/s154095g/dp_snake/snake/SnakeGame.class and /dev/null differ diff --git a/output/production/snake.main/dp_snake.mixins.json b/output/production/snake.main/dp_snake.mixins.json deleted file mode 100644 index d44bf86..0000000 --- a/output/production/snake.main/dp_snake.mixins.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "com.gmail.s154095g.dp_snake.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - "AntiDropMixin", - "EndGameOnDeathMixin" - ], - "client": [ - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/output/production/snake.main/fabric.mod.json b/output/production/snake.main/fabric.mod.json deleted file mode 100644 index af9a5ae..0000000 --- a/output/production/snake.main/fabric.mod.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "schemaVersion": 1, - "id": "dp_snake", - "version": "1.0.0", - - "name": "Snake", - "description": "Allows you to play snake in Minecraft!", - "authors": [ - "DamienPup" - ], - "contact": { - "homepage": "", - "sources": "" - }, - - "license": "GPL-3.0", - "icon": "assets/dp_snake/icon.png", - - "environment": "*", - "entrypoints": { - "main": [ - "com.gmail.s154095g.dp_snake.SnakeMod" - ] - }, - "mixins": [ - "dp_snake.mixins.json" - ], - - "depends": { - "fabricloader": ">=0.14.11", - "fabric-api": "*", - "minecraft": "~1.19.3", - "java": ">=17" - }, - "suggests": { - } -} diff --git a/src/main/java/com/gmail/s154095g/dp_snake/SnakeMod.java b/src/main/java/com/gmail/s154095g/dp_snake/SnakeMod.java index 362bbbd..c4068ca 100644 --- a/src/main/java/com/gmail/s154095g/dp_snake/SnakeMod.java +++ b/src/main/java/com/gmail/s154095g/dp_snake/SnakeMod.java @@ -7,17 +7,22 @@ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; +import net.fabricmc.fabric.api.event.player.UseBlockCallback; +import net.fabricmc.fabric.api.event.player.UseEntityCallback; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.ActionResult; import net.minecraft.util.math.BlockPos; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Objects; +import java.util.UUID; public class SnakeMod implements ModInitializer { public static final String MOD_ID = "dp_snake"; @@ -29,7 +34,7 @@ public class SnakeMod implements ModInitializer { public static final Item SNAKE_SOUTH = Registry.register(Registries.ITEM, Utils.identifier("snake_south"), new SnakeController(0, 1)); public static final Item SNAKE_WEST = Registry.register(Registries.ITEM, Utils.identifier("snake_west"), new SnakeController(-1, 0)); - public static final HashMap activeGames = new HashMap<>(); + public static final HashMap activeGames = new HashMap<>(); @Override public void onInitialize() { @@ -52,25 +57,35 @@ public void onInitialize() { activeGames.clear(); }); + UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> PreventInteractions(player)); + UseEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> PreventInteractions(player)); + LOGGER.info("Successfully set up dp_snake mod!"); } + public ActionResult PreventInteractions(PlayerEntity player){ + if (activeGames.containsKey(player.getUuid())) { + return ActionResult.FAIL; + } + return ActionResult.PASS; + } + public static void addGame(ServerPlayerEntity player, BlockPos corner1, BlockPos corner2){ Objects.requireNonNull(player, "Missing player!"); Objects.requireNonNull(corner1, "Missing corner 1!"); Objects.requireNonNull(corner2, "Missing corner 2!"); - if (activeGames.containsKey(player)){ - activeGames.get(player).stop(); + if (activeGames.containsKey(player.getUuid())){ + activeGames.get(player.getUuid()).stop(); } - activeGames.put(player, new SnakeGame(player, corner1, corner2)); + activeGames.put(player.getUuid(), new SnakeGame(player, corner1, corner2)); } public static boolean removeGame(ServerPlayerEntity player){ if (player == null) return false; - if (activeGames.containsKey(player)) - activeGames.get(player).stop(); - return activeGames.remove(player) != null; + if (activeGames.containsKey(player.getUuid())) + activeGames.get(player.getUuid()).stop(); + return activeGames.remove(player.getUuid()) != null; } } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 539e58f..a45d34b 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "dp_snake", - "version": "1.0.0", + "version": "1.0.1", "name": "Snake", "description": "Allows you to play snake in Minecraft!",