Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienPup committed Dec 27, 2022
1 parent d37336d commit 7bb3d6b
Show file tree
Hide file tree
Showing 23 changed files with 23 additions and 91 deletions.
Binary file removed output/production/snake.main/assets/dp_snake/icon.png
Binary file not shown.
7 changes: 0 additions & 7 deletions output/production/snake.main/assets/dp_snake/lang/en_us.json

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 0 additions & 15 deletions output/production/snake.main/dp_snake.mixins.json

This file was deleted.

37 changes: 0 additions & 37 deletions output/production/snake.main/fabric.mod.json

This file was deleted.

29 changes: 22 additions & 7 deletions src/main/java/com/gmail/s154095g/dp_snake/SnakeMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<ServerPlayerEntity, SnakeGame> activeGames = new HashMap<>();
public static final HashMap<UUID, SnakeGame> activeGames = new HashMap<>();

@Override
public void onInitialize() {
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -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!",
Expand Down

0 comments on commit 7bb3d6b

Please sign in to comment.