add positions to runes
This commit is contained in:
parent
6a94d4c45a
commit
85db38a9a8
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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<Integer, RuneType> 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;
|
||||
}
|
||||
}
|
|
@ -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<BlockPos, RuneData> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.6 KiB |
Loading…
Reference in New Issue