diff --git a/README.md b/README.md index c351486..5c0f808 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # futhark-fabric -A minecraft alpha era inspired mod adding old functionality, nostalgic items, and a magic system inspired by the Bukkit plugin Runecraft +A minecraft magic mod inspired by the alpha era Bukkit plugin [Runecraft](https://dev.bukkit.org/projects/runecraft) diff --git a/src/main/java/com/futhark/RuneData.java b/src/main/java/com/futhark/RuneData.java new file mode 100644 index 0000000..52795ad --- /dev/null +++ b/src/main/java/com/futhark/RuneData.java @@ -0,0 +1,13 @@ +package com.futhark; + +import net.minecraft.util.math.BlockPos; + +public class RuneData { + public RuneType type; + public BlockPos pos; + + @Override + public String toString() { + return String.format("%s (%d %d %d)", type.toString(), pos.getX(), pos.getY(), pos.getZ()); + } +} diff --git a/src/main/java/com/futhark/RuneType.java b/src/main/java/com/futhark/RuneType.java new file mode 100644 index 0000000..5100e96 --- /dev/null +++ b/src/main/java/com/futhark/RuneType.java @@ -0,0 +1,39 @@ +package com.futhark; + +import java.util.HashMap; +import java.util.Map; + +public enum RuneType { + UNKNOWN(0), + INCOMPLETE_TIER_0(1), + INCOMPLETE_TIER_1(2), + INCOMPLETE_TIER_2(3), + TELEPORT_START(4), + TELEPORT_END(5); + + private final int value; + + RuneType(int value) { + this.value = value; + } + + public int asInt() { + return value; + } + + private static final Map intToTypeMap = new HashMap<>(); + + static { + for (RuneType type : RuneType.values()) { + intToTypeMap.put(type.value, type); + } + } + + public static RuneType fromInt(int value) { + RuneType type = intToTypeMap.get(Integer.valueOf(value)); + if (type == null) { + throw new IllegalArgumentException("Unknown value: " + value); + } + return type; + } +} \ No newline at end of file diff --git a/src/main/java/com/futhark/StateSaverAndLoader.java b/src/main/java/com/futhark/StateSaverAndLoader.java index f88c626..63c6f04 100644 --- a/src/main/java/com/futhark/StateSaverAndLoader.java +++ b/src/main/java/com/futhark/StateSaverAndLoader.java @@ -2,23 +2,53 @@ package com.futhark; import net.minecraft.nbt.NbtCompound; import net.minecraft.server.MinecraftServer; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.PersistentState; import net.minecraft.world.PersistentStateManager; import net.minecraft.world.World; +import java.util.HashMap; + public class StateSaverAndLoader extends PersistentState { public Integer totalNumberOfRunes = 0; + public HashMap runes = new HashMap<>(); @Override public NbtCompound writeNbt(NbtCompound nbt) { nbt.putInt("totalNumberOfRunes", totalNumberOfRunes); + + NbtCompound runesNbt = new NbtCompound(); + runes.forEach((pos, runeData) -> { + NbtCompound runeNbt = new NbtCompound(); + + runeNbt.putInt("type", runeData.type.asInt()); + + runesNbt.put(Long.toString(pos.asLong()), runeNbt); + }); + nbt.put("runes", runesNbt); + return nbt; } public static StateSaverAndLoader createFromNbt(NbtCompound tag) { StateSaverAndLoader state = new StateSaverAndLoader(); state.totalNumberOfRunes = tag.getInt("totalNumberOfRunes"); + + NbtCompound runesNbt = tag.getCompound("runes"); + runesNbt.getKeys().forEach(key -> { + long longPos = Long.parseLong(key); + BlockPos pos = BlockPos.fromLong(longPos); + + NbtCompound runeNbt = runesNbt.getCompound(key); + + RuneData runeData = new RuneData(); + runeData.type = RuneType.fromInt(runeNbt.getInt("type")); + runeData.pos = pos; + + state.runes.put(pos, runeData); + }); + return state; } diff --git a/src/main/java/com/futhark/block/RuneBlock.java b/src/main/java/com/futhark/block/RuneBlock.java index 1e1d54f..2e7db7a 100644 --- a/src/main/java/com/futhark/block/RuneBlock.java +++ b/src/main/java/com/futhark/block/RuneBlock.java @@ -26,8 +26,8 @@ public class RuneBlock extends Block { MinecraftServer server = world.getServer(); if (server != null) { StateSaverAndLoader serverState = StateSaverAndLoader.getServerState(server); - player.sendMessage(Text.literal(String.format("Clicked rune at (%d,%d,%d) Total Runes in World: %d", pos.getX(), pos.getY(), pos.getZ(), serverState.totalNumberOfRunes))); - world.playSound(player, pos, SoundEvents.BLOCK_PORTAL_TRIGGER, SoundCategory.BLOCKS, 1f, 1f); + player.sendMessage(Text.literal(String.format("Clicked rune %s Total Runes in World: %d", serverState.runes.get(pos), serverState.totalNumberOfRunes))); + world.playSound(player, pos, SoundEvents.BLOCK_AMETHYST_BLOCK_CHIME, SoundCategory.BLOCKS, 1f, 1f); } return ActionResult.SUCCESS; diff --git a/src/main/java/com/futhark/item/RunicChiselItem.java b/src/main/java/com/futhark/item/RunicChiselItem.java index 902ea77..e8c0634 100644 --- a/src/main/java/com/futhark/item/RunicChiselItem.java +++ b/src/main/java/com/futhark/item/RunicChiselItem.java @@ -1,5 +1,7 @@ package com.futhark.item; +import com.futhark.RuneData; +import com.futhark.RuneType; import com.futhark.StateSaverAndLoader; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -10,6 +12,8 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.util.ActionResult; import net.minecraft.util.math.BlockPos; +import java.util.UUID; + import static com.futhark.block.FutharkBlocks.RUNE_BLOCK; public class RunicChiselItem extends Item { @@ -30,11 +34,16 @@ public class RunicChiselItem extends Item { if (server != null) { StateSaverAndLoader serverState = StateSaverAndLoader.getServerState(server); serverState.totalNumberOfRunes += 1; + RuneData runeData = new RuneData(); + runeData.type = RuneType.UNKNOWN; + runeData.pos = pos; + serverState.runes.put(pos, runeData); } } else if (state.isOf(RUNE_BLOCK)) { context.getWorld().setBlockState(pos, Blocks.STONE.getDefaultState()); if (server != null) { StateSaverAndLoader serverState = StateSaverAndLoader.getServerState(server); + serverState.runes.remove(pos); serverState.totalNumberOfRunes -= 1; } } diff --git a/src/main/resources/assets/futhark/textures/item/jaffa_cake.png b/src/main/resources/assets/futhark/textures/item/jaffa_cake.png index 737b4fd..a86f0fe 100644 Binary files a/src/main/resources/assets/futhark/textures/item/jaffa_cake.png and b/src/main/resources/assets/futhark/textures/item/jaffa_cake.png differ diff --git a/src/main/resources/assets/futhark/textures/item/jaffa_cake.png~ b/src/main/resources/assets/futhark/textures/item/jaffa_cake.png~ new file mode 100644 index 0000000..737b4fd Binary files /dev/null and b/src/main/resources/assets/futhark/textures/item/jaffa_cake.png~ differ