From 85db38a9a8c7aa346e10e4d3f0d68016c20a02a3 Mon Sep 17 00:00:00 2001 From: zongor Date: Sun, 17 Nov 2024 00:19:35 -0500 Subject: [PATCH] add positions to runes --- README.md | 2 +- src/main/java/com/futhark/RuneData.java | 13 ++++++ src/main/java/com/futhark/RuneType.java | 39 ++++++++++++++++++ .../java/com/futhark/StateSaverAndLoader.java | 30 ++++++++++++++ .../java/com/futhark/block/RuneBlock.java | 4 +- .../com/futhark/item/RunicChiselItem.java | 9 ++++ .../futhark/textures/item/jaffa_cake.png | Bin 5777 -> 5698 bytes .../futhark/textures/item/jaffa_cake.png~ | Bin 0 -> 5777 bytes 8 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/futhark/RuneData.java create mode 100644 src/main/java/com/futhark/RuneType.java create mode 100644 src/main/resources/assets/futhark/textures/item/jaffa_cake.png~ 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 737b4fd044d4c6a70ebdf822b70b1318a06f1e9b..a86f0fe93d09137af30a9407b28d1ed89466d2ca 100644 GIT binary patch delta 551 zcmV+?0@(eLEy66YClr4MNklJ&P1E7=9+nWIp!86>o197F13w?r^cN&_avD z%FfQeVr%8^uonCQc7iA(HV1Mih@dv!?cUD1b2GDmBiNA4m%bvy=2w%Q@zh5?cT7uhG#>iP)bo6a)x-38l3SW#E-s zK`^oLdjDYNNLa(8v5Iu0w`r;%+e zOl1rSVCY66PV%3C**wAJOBZR;VtO=%6h4lZiVP0)lYHOp5DXF{X=HR+20j4;8t%E0WPv!2+$;U9U?Y;4 z(}}7wB;TUYD>y@>c>!A#Fhm~3F#?jWi`*^M7HCTt_5FXEHI^JpRU#$8;c|)NEUWX5 z==%0H+}YNYt$%8Qw;w)IV$1G~Iyfl=nJ31G3(Tn$OL9Xx^-Q;eBG15-#onhc*xflN z3HM9E{X1jt*^96C+Jz837^2nKj2nT9{%Meb_dXZ6I~jBzKYdf%d94>7KDdSF?+#Dx pg?l$Q<)a@bui9St%|`!e`UB_3&J{JI&XE8B002ovPDHLkV1goE1d0Fv delta 630 zcmV-+0*U>?ERij+Clr5GNkl5Lp7==&nXOfxDhtke0Y^~OXErp7ULP1f% zjUX1f@)!66-09MV;#Svgq;BgUa4Qw7AYDiW#f2!0rFEv0PBOW<_xh$Vg>hR0feXnw zdCqzB0w=tJfA!0A(^UlGdg1*Y#jxm^sKTS;ynk=3-Kd1&_S=8YJ7%OiHn@7>4Ei>> z=sg~C&R5gi)SP#Sw1$=nc~SUK>0dkuUKG|od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