Skip to content

Commit

Permalink
remove furled map from live
Browse files Browse the repository at this point in the history
who needs branches im a cowboy
  • Loading branch information
iron431 committed Nov 28, 2023
1 parent 34b5d4d commit 43cd12a
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package io.redspace.ironsspellbooks.config;

import io.redspace.ironsspellbooks.IronsSpellbooks;
import io.redspace.ironsspellbooks.api.config.DefaultConfig;
import io.redspace.ironsspellbooks.api.registry.SchoolRegistry;
import io.redspace.ironsspellbooks.api.spells.AbstractSpell;
import io.redspace.ironsspellbooks.api.config.DefaultConfig;
import io.redspace.ironsspellbooks.api.spells.SchoolType;
import io.redspace.ironsspellbooks.api.spells.SpellRarity;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.event.config.ModConfigEvent;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.*;
import java.util.function.Supplier;
Expand All @@ -35,7 +32,7 @@ public class ServerConfigs {
public static final ForgeConfigSpec.ConfigValue<List<? extends String>> IMBUE_BLACKLIST;
public static final ForgeConfigSpec.ConfigValue<Integer> PRIEST_TOWER_SPAWNRATE;
public static final ForgeConfigSpec.ConfigValue<Boolean> ALLOW_CAULDRON_BREWING;
public static final ForgeConfigSpec.ConfigValue<Boolean> FURLED_MAPS_SKIP_CHUNKS;
// public static final ForgeConfigSpec.ConfigValue<Boolean> FURLED_MAPS_SKIP_CHUNKS;

//public static final ForgeConfigSpec.ConfigValue<String[]> UPGRADE_BLACKLIST;

Expand Down Expand Up @@ -69,8 +66,8 @@ public class ServerConfigs {
SCROLL_RECYCLE_CHANCE = BUILDER.worldRestart().define("scrollRecycleChance", 0.5);
BUILDER.comment("Whether or not potions should be allowed to be brewed in the alchemist cauldron)");
ALLOW_CAULDRON_BREWING = BUILDER.worldRestart().define("allowCauldronBrewing", true);
BUILDER.comment("Whether or not Furled Map items should skip chunks when searching for structures (only find new structures). Can impact performance while searching.");
FURLED_MAPS_SKIP_CHUNKS = BUILDER.worldRestart().define("furledMapSkipsExistingChunks", false);
// BUILDER.comment("Whether or not Furled Map items should skip chunks when searching for structures (only find new structures). Can impact performance while searching.");
// FURLED_MAPS_SKIP_CHUNKS = BUILDER.worldRestart().define("furledMapSkipsExistingChunks", false);
BUILDER.pop();

BUILDER.push("Upgrade Overrides");
Expand Down
204 changes: 102 additions & 102 deletions src/main/java/io/redspace/ironsspellbooks/item/FurledMapItem.java
Original file line number Diff line number Diff line change
@@ -1,102 +1,102 @@
package io.redspace.ironsspellbooks.item;

import com.mojang.datafixers.util.Pair;
import io.redspace.ironsspellbooks.config.ServerConfigs;
import io.redspace.ironsspellbooks.registries.ItemRegistry;
import io.redspace.ironsspellbooks.util.SpellbookModCreativeTabs;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.saveddata.maps.MapDecoration;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class FurledMapItem extends Item {
public static String FURLED_MAP_NBT = "furledMapData";
public static String FURLED_MAP_LOCATION = "destination";
public static String FURLED_MAP_DESCRIPTION = "description";

public FurledMapItem() {
super(new Properties().tab(SpellbookModCreativeTabs.SPELL_MATERIALS_TAB).stacksTo(1));
}

@Override
public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> lines, TooltipFlag pIsAdvanced) {
super.appendHoverText(pStack, pLevel, lines, pIsAdvanced);
}

@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
if (level instanceof ServerLevel serverlevel) {
ItemStack itemStack = player.getItemInHand(hand);
CompoundTag tag = itemStack.getTag();
level.playSound(null, player, SoundEvents.UI_CARTOGRAPHY_TABLE_TAKE_RESULT, player.getSoundSource(), 1.0F, 1.0F);
player.getCooldowns().addCooldown(ItemRegistry.FURLED_MAP.get(), 50);
if (tag != null && tag.contains(FURLED_MAP_NBT, 10) && tag.getCompound(FURLED_MAP_NBT).contains(FURLED_MAP_LOCATION)) {
ResourceLocation destinationResource = new ResourceLocation(tag.getCompound(FURLED_MAP_NBT).getString(FURLED_MAP_LOCATION));
ResourceKey<Structure> structureResourceKey = ResourceKey.create(Registry.STRUCTURE_REGISTRY, destinationResource);
var holder = serverlevel.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).getHolder(structureResourceKey).map(HolderSet::direct);
//IronsSpellbooks.LOGGER.debug("FurledMapItem: found location: {}", structureResourceKey);
if (holder.isPresent()) {
Pair<BlockPos, Holder<Structure>> pair = serverlevel.getChunkSource().getGenerator().findNearestMapStructure(serverlevel, holder.get(), player.blockPosition(), 100, ServerConfigs.FURLED_MAPS_SKIP_CHUNKS.get());
if (pair != null) {
var blockpos = pair.getFirst();
ItemStack mapStack = MapItem.create(serverlevel, blockpos.getX(), blockpos.getZ(), (byte) 2, true, true);
MapItem.renderBiomePreviewMap(serverlevel, mapStack);
MapItemSavedData.addTargetDecoration(mapStack, blockpos, "x", MapDecoration.Type.RED_X);


if (tag.getCompound(FURLED_MAP_NBT).contains(FURLED_MAP_DESCRIPTION)) {
Component mapTitle = Component.Serializer.fromJson(tag.getCompound(FURLED_MAP_NBT).getString(FURLED_MAP_DESCRIPTION));
mapStack.setHoverName(mapTitle);
}
replaceItem(player, mapStack, hand);
return InteractionResultHolder.sidedSuccess(itemStack, level.isClientSide);
}
}
}
replaceItem(player, new ItemStack(Items.MAP), hand);
}
return super.use(level, player, hand);
}

private static void replaceItem(Player player, ItemStack itemStack, InteractionHand hand) {
boolean flag = player.getAbilities().instabuild;
if (!flag) {
//We set in hand because stack size is 1 and i don't wanna do logic
player.setItemInHand(hand, itemStack);
} else {
player.getInventory().add(itemStack);
}
}

public static ItemStack of(ResourceLocation structure, MutableComponent descriptor) {
ItemStack itemStack = new ItemStack(ItemRegistry.FURLED_MAP.get());
itemStack.getOrCreateTagElement(FURLED_MAP_NBT).putString(FURLED_MAP_LOCATION, structure.toString());
itemStack.getOrCreateTagElement(FURLED_MAP_NBT).putString(FURLED_MAP_DESCRIPTION, Component.Serializer.toJson(descriptor));
ListTag lore = new ListTag();
lore.add(StringTag.valueOf(Component.Serializer.toJson(Component.translatable("item.irons_spellbooks.furled_map_descriptor_framing", descriptor).setStyle(Style.EMPTY.withColor(ChatFormatting.GRAY)))));
itemStack.getOrCreateTagElement("display").put("Lore", lore);
return itemStack;
}
}
//package io.redspace.ironsspellbooks.item;
//
//import com.mojang.datafixers.util.Pair;
//import io.redspace.ironsspellbooks.config.ServerConfigs;
//import io.redspace.ironsspellbooks.registries.ItemRegistry;
//import io.redspace.ironsspellbooks.util.SpellbookModCreativeTabs;
//import net.minecraft.ChatFormatting;
//import net.minecraft.core.BlockPos;
//import net.minecraft.core.Holder;
//import net.minecraft.core.HolderSet;
//import net.minecraft.core.Registry;
//import net.minecraft.nbt.CompoundTag;
//import net.minecraft.nbt.ListTag;
//import net.minecraft.nbt.StringTag;
//import net.minecraft.network.chat.Component;
//import net.minecraft.network.chat.MutableComponent;
//import net.minecraft.network.chat.Style;
//import net.minecraft.resources.ResourceKey;
//import net.minecraft.resources.ResourceLocation;
//import net.minecraft.server.level.ServerLevel;
//import net.minecraft.sounds.SoundEvents;
//import net.minecraft.world.InteractionHand;
//import net.minecraft.world.InteractionResultHolder;
//import net.minecraft.world.entity.player.Player;
//import net.minecraft.world.item.*;
//import net.minecraft.world.level.Level;
//import net.minecraft.world.level.levelgen.structure.Structure;
//import net.minecraft.world.level.saveddata.maps.MapDecoration;
//import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
//import org.jetbrains.annotations.Nullable;
//
//import java.util.List;
//
//public class FurledMapItem extends Item {
// public static String FURLED_MAP_NBT = "furledMapData";
// public static String FURLED_MAP_LOCATION = "destination";
// public static String FURLED_MAP_DESCRIPTION = "description";
//
// public FurledMapItem() {
// super(new Properties().tab(SpellbookModCreativeTabs.SPELL_MATERIALS_TAB).stacksTo(1));
// }
//
// @Override
// public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> lines, TooltipFlag pIsAdvanced) {
// super.appendHoverText(pStack, pLevel, lines, pIsAdvanced);
// }
//
// @Override
// public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
// if (level instanceof ServerLevel serverlevel) {
// ItemStack itemStack = player.getItemInHand(hand);
// CompoundTag tag = itemStack.getTag();
// level.playSound(null, player, SoundEvents.UI_CARTOGRAPHY_TABLE_TAKE_RESULT, player.getSoundSource(), 1.0F, 1.0F);
// player.getCooldowns().addCooldown(ItemRegistry.FURLED_MAP.get(), 50);
// if (tag != null && tag.contains(FURLED_MAP_NBT, 10) && tag.getCompound(FURLED_MAP_NBT).contains(FURLED_MAP_LOCATION)) {
// ResourceLocation destinationResource = new ResourceLocation(tag.getCompound(FURLED_MAP_NBT).getString(FURLED_MAP_LOCATION));
// ResourceKey<Structure> structureResourceKey = ResourceKey.create(Registry.STRUCTURE_REGISTRY, destinationResource);
// var holder = serverlevel.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).getHolder(structureResourceKey).map(HolderSet::direct);
// //IronsSpellbooks.LOGGER.debug("FurledMapItem: found location: {}", structureResourceKey);
// if (holder.isPresent()) {
// Pair<BlockPos, Holder<Structure>> pair = serverlevel.getChunkSource().getGenerator().findNearestMapStructure(serverlevel, holder.get(), player.blockPosition(), 100, ServerConfigs.FURLED_MAPS_SKIP_CHUNKS.get());
// if (pair != null) {
// var blockpos = pair.getFirst();
// ItemStack mapStack = MapItem.create(serverlevel, blockpos.getX(), blockpos.getZ(), (byte) 2, true, true);
// MapItem.renderBiomePreviewMap(serverlevel, mapStack);
// MapItemSavedData.addTargetDecoration(mapStack, blockpos, "x", MapDecoration.Type.RED_X);
//
//
// if (tag.getCompound(FURLED_MAP_NBT).contains(FURLED_MAP_DESCRIPTION)) {
// Component mapTitle = Component.Serializer.fromJson(tag.getCompound(FURLED_MAP_NBT).getString(FURLED_MAP_DESCRIPTION));
// mapStack.setHoverName(mapTitle);
// }
// replaceItem(player, mapStack, hand);
// return InteractionResultHolder.sidedSuccess(itemStack, level.isClientSide);
// }
// }
// }
// replaceItem(player, new ItemStack(Items.MAP), hand);
// }
// return super.use(level, player, hand);
// }
//
// private static void replaceItem(Player player, ItemStack itemStack, InteractionHand hand) {
// boolean flag = player.getAbilities().instabuild;
// if (!flag) {
// //We set in hand because stack size is 1 and i don't wanna do logic
// player.setItemInHand(hand, itemStack);
// } else {
// player.getInventory().add(itemStack);
// }
// }
//
// public static ItemStack of(ResourceLocation structure, MutableComponent descriptor) {
// ItemStack itemStack = new ItemStack(ItemRegistry.FURLED_MAP.get());
// itemStack.getOrCreateTagElement(FURLED_MAP_NBT).putString(FURLED_MAP_LOCATION, structure.toString());
// itemStack.getOrCreateTagElement(FURLED_MAP_NBT).putString(FURLED_MAP_DESCRIPTION, Component.Serializer.toJson(descriptor));
// ListTag lore = new ListTag();
// lore.add(StringTag.valueOf(Component.Serializer.toJson(Component.translatable("item.irons_spellbooks.furled_map_descriptor_framing", descriptor).setStyle(Style.EMPTY.withColor(ChatFormatting.GRAY)))));
// itemStack.getOrCreateTagElement("display").put("Lore", lore);
// return itemStack;
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.redspace.ironsspellbooks.api.spells.AbstractSpell;
import io.redspace.ironsspellbooks.api.spells.SpellRarity;
import io.redspace.ironsspellbooks.capabilities.spell.SpellData;
import io.redspace.ironsspellbooks.item.FurledMapItem;
import io.redspace.ironsspellbooks.item.InkItem;
import io.redspace.ironsspellbooks.loot.SpellFilter;
import io.redspace.ironsspellbooks.registries.ItemRegistry;
Expand All @@ -16,7 +15,6 @@
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.npc.VillagerTrades;
import net.minecraft.world.item.BundleItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.trading.MerchantOffer;
Expand Down Expand Up @@ -57,15 +55,15 @@ public static void addWanderingTrades(WandererTradesEvent event) {
new InkBuyTrade((InkItem) ItemRegistry.INK_RARE.get()),
new InkBuyTrade((InkItem) ItemRegistry.INK_EPIC.get()),
new InkBuyTrade((InkItem) ItemRegistry.INK_LEGENDARY.get()),
new RandomCurioTrade(),
new RandomCurioTrade()/*,
SimpleTrade.of((trader, random) -> new MerchantOffer(
new ItemStack(Items.EMERALD, 64 - random.nextIntBetweenInclusive(1, 8)),
new ItemStack(Items.ECHO_SHARD, random.nextIntBetweenInclusive(1, 3)),
FurledMapItem.of(IronsSpellbooks.id("evoker_fort"), Component.translatable("item.irons_spellbooks.evoker_fort_battle_plans")),
8,
0,
.05f
))
))*/
);
List<VillagerTrades.ItemListing> additionalRareTrades = List.of(
SimpleTrade.of((trader, random) -> new MerchantOffer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static void register(IEventBus eventBus) {
public static final RegistryObject<Item> FROZEN_BONE_SHARD = ITEMS.register("frozen_bone", () -> new Item((new Item.Properties()).tab(SpellbookModCreativeTabs.SPELL_MATERIALS_TAB)));
public static final RegistryObject<Item> BLOOD_VIAL = ITEMS.register("blood_vial", () -> new Item((new Item.Properties()).tab(SpellbookModCreativeTabs.SPELL_MATERIALS_TAB)));
public static final RegistryObject<Item> DIVINE_PEARL = ITEMS.register("divine_pearl", () -> new Item((new Item.Properties()).tab(SpellbookModCreativeTabs.SPELL_MATERIALS_TAB)));
public static final RegistryObject<Item> FURLED_MAP = ITEMS.register("furled_map", () -> new FurledMapItem());
// public static final RegistryObject<Item> FURLED_MAP = ITEMS.register("furled_map", () -> new FurledMapItem());
public static final RegistryObject<Item> HOGSKIN = ITEMS.register("hogskin", () -> new Item((new Item.Properties()).tab(SpellbookModCreativeTabs.SPELL_MATERIALS_TAB)));
public static final RegistryObject<Item> DRAGONSKIN = ITEMS.register("dragonskin", DragonskinItem::new);
public static final RegistryObject<Item> ARCANE_ESSENCE = ITEMS.register("arcane_essence", () -> new Item((new Item.Properties()).tab(SpellbookModCreativeTabs.SPELL_MATERIALS_TAB)));
Expand Down

0 comments on commit 43cd12a

Please sign in to comment.