use of net.minecraft.nbt.NbtCompound in project FabricWaystones by LordDeatHunter.
the class Config method toNbtCompound.
private NbtCompound toNbtCompound(JsonObject json) {
NbtCompound tag = new NbtCompound();
NbtCompound defaults = getDefaults();
NbtCompound worldgen = new NbtCompound();
if (json.has("worldgen")) {
var worldgenJson = json.get("worldgen").getAsJsonObject();
var defaultWorldgen = new NbtCompound();
worldgen.putBoolean("generate_in_villages", getBooleanOrDefault(worldgenJson, "generate_in_villages", defaultWorldgen));
// worldgen.putInt("min_per_village", getIntOrDefault(worldgenJson, "min_per_village", defaultWorldgen));
// worldgen.putInt("max_per_village", getIntOrDefault(worldgenJson, "max_per_village", defaultWorldgen));
worldgen.putInt("village_waystone_weight", getIntOrDefault(worldgenJson, "village_waystone_weight", defaultWorldgen));
} else {
++difference;
worldgen = defaults.getCompound("worldgen");
}
tag.put("worldgen", worldgen);
NbtCompound cost = new NbtCompound();
if (json.has("teleportation_cost")) {
var costJson = json.get("teleportation_cost").getAsJsonObject();
var defaultCost = new NbtCompound();
cost.putString("cost_type", getStringOrDefault(costJson, "cost_type", defaultCost));
cost.putString("cost_item", getStringOrDefault(costJson, "cost_item", defaultCost));
cost.putInt("base_cost", getIntOrDefault(costJson, "base_cost", defaultCost));
cost.putFloat("cost_per_block_distance", getFloatOrDefault(costJson, "cost_per_block_distance", defaultCost));
cost.putFloat("cost_multiplier_between_dimensions", getFloatOrDefault(costJson, "cost_multiplier_between_dimensions", defaultCost));
} else {
++difference;
cost = defaults.getCompound("teleportation_cost");
}
tag.put("teleportation_cost", cost);
tag.putString("discover_with_item", getStringOrDefault(json, "discover_with_item", defaults));
tag.putInt("take_amount_from_discover_item", getIntOrDefault(json, "take_amount_from_discover_item", defaults));
tag.putBoolean("consume_infinite_knowledge_scroll_on_use", getBooleanOrDefault(json, "consume_infinite_knowledge_scroll_on_use", defaults));
tag.putBoolean("consume_local_void_on_use", getBooleanOrDefault(json, "consume_local_void_on_use", defaults));
tag.putBoolean("free_local_void_teleport", getBooleanOrDefault(json, "free_local_void_teleport", defaults));
tag.putBoolean("store_waystone_data_on_sneak_break", getBooleanOrDefault(json, "store_waystone_data_on_sneak_break", defaults));
tag.putBoolean("can_owners_redeem_payments", getBooleanOrDefault(json, "can_owners_redeem_payments", defaults));
tag.putFloat("waystone_block_hardness", getFloatOrDefault(json, "waystone_block_hardness", defaults));
tag.putInt("waystone_block_required_mining_level", getIntOrDefault(json, "waystone_block_required_mining_level", defaults));
tag.putBoolean("prevent_non_owners_from_breaking_waystone", getBooleanOrDefault(json, "prevent_non_owners_from_breaking_waystone", defaults));
tag.putBoolean("can_players_toggle_global_mode", getBooleanOrDefault(json, "can_players_toggle_global_mode", defaults));
NbtCompound cooldowns = new NbtCompound();
if (json.has("teleportation_cooldown")) {
var cooldownsJson = json.get("teleportation_cooldown").getAsJsonObject();
var defaultCooldowns = defaults.getCompound("teleportation_cooldown");
cooldowns.putInt("cooldown_ticks_when_hurt", getIntOrDefault(cooldownsJson, "cooldown_ticks_when_hurt", defaultCooldowns));
cooldowns.putInt("cooldown_ticks_from_abyss_watcher", getIntOrDefault(cooldownsJson, "cooldown_ticks_from_abyss_watcher", defaultCooldowns));
cooldowns.putInt("cooldown_ticks_from_pocket_wormhole", getIntOrDefault(cooldownsJson, "cooldown_ticks_from_pocket_wormhole", defaultCooldowns));
cooldowns.putInt("cooldown_ticks_from_local_void", getIntOrDefault(cooldownsJson, "cooldown_ticks_from_local_void", defaultCooldowns));
cooldowns.putInt("cooldown_ticks_from_waystone", getIntOrDefault(cooldownsJson, "cooldown_ticks_from_waystone", defaultCooldowns));
} else {
++difference;
cooldowns = defaults.getCompound("teleportation_cooldown");
}
tag.put("teleportation_cooldown", cooldowns);
createFile(toJson(tag), difference > 0);
difference = 0;
return tag;
}
use of net.minecraft.nbt.NbtCompound in project FabricWaystones by LordDeatHunter.
the class Config method getDefaults.
private NbtCompound getDefaults() {
NbtCompound defaultConfig = new NbtCompound();
NbtCompound worldgen = new NbtCompound();
worldgen.putBoolean("generate_in_villages", true);
// worldgen.putInt("min_per_village", 1);
// worldgen.putInt("max_per_village", 1);
worldgen.putInt("village_waystone_weight", 5);
defaultConfig.put("worldgen", worldgen);
defaultConfig.putBoolean("consume_infinite_knowledge_scroll_on_use", false);
defaultConfig.putBoolean("consume_local_void_on_use", true);
defaultConfig.putBoolean("free_local_void_teleport", true);
defaultConfig.putBoolean("can_owners_redeem_payments", false);
defaultConfig.putBoolean("store_waystone_data_on_sneak_break", true);
NbtCompound cost = new NbtCompound();
cost.putString("cost_type", "level");
cost.putString("cost_item", "minecraft:ender_pearl");
cost.putInt("base_cost", 1);
cost.putFloat("cost_per_block_distance", 0F);
cost.putFloat("cost_multiplier_between_dimensions", 1F);
defaultConfig.put("teleportation_cost", cost);
defaultConfig.putFloat("waystone_block_hardness", 4F);
defaultConfig.putInt("waystone_block_required_mining_level", 1);
defaultConfig.putBoolean("prevent_non_owners_from_breaking_waystone", false);
defaultConfig.putBoolean("can_players_toggle_global_mode", true);
defaultConfig.putString("discover_with_item", "none");
defaultConfig.putInt("take_amount_from_discover_item", 0);
NbtCompound cooldown = new NbtCompound();
cooldown.putInt("cooldown_ticks_when_hurt", 0);
cooldown.putInt("cooldown_ticks_from_abyss_watcher", 0);
cooldown.putInt("cooldown_ticks_from_pocket_wormhole", 0);
cooldown.putInt("cooldown_ticks_from_local_void", 0);
cooldown.putInt("cooldown_ticks_from_waystone", 0);
defaultConfig.put("teleportation_cooldown", cooldown);
return defaultConfig;
}
use of net.minecraft.nbt.NbtCompound in project FabricWaystones by LordDeatHunter.
the class WaystonesClient method registerPacketHandlers.
private void registerPacketHandlers() {
ClientPlayNetworking.registerGlobalReceiver(Utils.ID("waystone_packet"), (client, networkHandler, data, sender) -> {
var nbt = data.readNbt();
client.execute(() -> {
if (Waystones.WAYSTONE_STORAGE == null) {
Waystones.WAYSTONE_STORAGE = new WaystoneStorage(null);
}
Waystones.WAYSTONE_STORAGE.fromTag(nbt);
if (client.player == null) {
return;
}
HashSet<String> toForget = new HashSet<>();
for (String hash : ((PlayerEntityMixinAccess) client.player).getDiscoveredWaystones()) {
if (!Waystones.WAYSTONE_STORAGE.containsHash(hash)) {
toForget.add(hash);
}
}
((PlayerEntityMixinAccess) client.player).forgetWaystones(toForget);
if (client.player.currentScreenHandler instanceof UniversalWaystoneScreenHandler) {
((UniversalWaystoneScreenHandler) client.player.currentScreenHandler).updateWaystones(client.player);
}
});
});
ClientPlayNetworking.registerGlobalReceiver(Utils.ID("waystone_config_update"), (client, networkHandler, data, sender) -> {
NbtCompound tag = data.readNbt();
client.execute(() -> Config.getInstance().loadConfig(tag));
});
ClientPlayNetworking.registerGlobalReceiver(Utils.ID("sync_player"), (client, networkHandler, data, sender) -> {
NbtCompound tag = data.readNbt();
client.execute(() -> {
if (client.player != null) {
((PlayerEntityMixinAccess) client.player).fromTagW(tag);
}
});
});
}
use of net.minecraft.nbt.NbtCompound in project FabricWaystones by LordDeatHunter.
the class LocalVoidItem method appendTooltip.
@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
super.appendTooltip(stack, world, tooltip, context);
String name = null;
NbtCompound tag = stack.getNbt();
boolean invalid = false;
if (tag == null || !tag.contains("waystone")) {
invalid = true;
} else {
name = Waystones.WAYSTONE_STORAGE.getName(tag.getString("waystone"));
if (name == null) {
invalid = true;
}
}
if (invalid) {
tooltip.add(new TranslatableText("waystones.local_void.empty_tooltip"));
return;
}
tooltip.add(new TranslatableText("waystones.local_void.tooltip", new LiteralText(name).styled(style -> style.withColor(TextColor.parse(new TranslatableText("waystones.local_void.tooltip.arg_color").getString())))));
}
use of net.minecraft.nbt.NbtCompound in project FabricWaystones by LordDeatHunter.
the class LocalVoidItem method use.
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
ItemStack stack = user.getStackInHand(hand);
NbtCompound tag = stack.getNbt();
if (tag == null || !tag.contains("waystone")) {
return TypedActionResult.fail(stack);
}
if (user.isSneaking()) {
stack.removeSubNbt("waystone");
} else {
String hash = tag.getString("waystone");
if (Waystones.WAYSTONE_STORAGE != null) {
WaystoneBlockEntity waystone = Waystones.WAYSTONE_STORAGE.getWaystoneEntity(hash);
if (waystone != null && waystone.teleportPlayer(user, Config.getInstance().doLocalVoidsUseCost()) && !user.isCreative() && Config.getInstance().consumeLocalVoid()) {
stack.decrement(1);
}
}
}
if (stack.isEmpty()) {
user.setStackInHand(hand, ItemStack.EMPTY);
}
return TypedActionResult.success(user.getStackInHand(hand), world.isClient());
}
Aggregations