Skip to content

Commit

Permalink
Impl FallingColors#491, make Spellbooks fireproof and make them not d…
Browse files Browse the repository at this point in the history
…ropped by GTP (made this configurable so other items can be made un-droppable at the user's discretion)
  • Loading branch information
Talia-12 committed Feb 6, 2024
1 parent 50400c2 commit 7ab0cc2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public interface ServerConfigAccess {
// fun fact, although dimension keys are a RegistryHolder, they aren't a registry, so i can't do tags
boolean canTeleportInThisDimension(ResourceKey<Level> dimension);

boolean teleportDropItems();

boolean teleportDropItem(ResourceLocation item);

int DEFAULT_MAX_OP_COUNT = 2_000_000;
int DEFAULT_MAX_SPELL_CIRCLE_LENGTH = 1024;
int DEFAULT_OP_BREAK_HARVEST_LEVEL = 3;
Expand All @@ -77,6 +81,10 @@ public interface ServerConfigAccess {

List<String> DEFAULT_DIM_TP_DENYLIST = List.of("twilightforest:twilight_forest");

boolean DEFAULT_TELEPORT_DROP_ITEMS = true;

List<String> DEFAULT_TP_ITEM_DROP_DENYLIST = List.of("hexcasting:spellbook");

default Tier opBreakHarvestLevel() {
return switch (this.opBreakHarvestLevelBecauseForgeThoughtItWasAGoodIdeaToImplementHarvestTiersUsingAnHonestToGodTopoSort()) {
case 0 -> Tiers.WOOD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import at.petrak.hexcasting.api.mod.HexTags
import at.petrak.hexcasting.common.msgs.MsgBlinkS2C
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.core.BlockPos
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.server.level.ServerLevel
import net.minecraft.server.level.ServerPlayer
import net.minecraft.server.level.TicketType
Expand Down Expand Up @@ -66,6 +67,9 @@ object OpTeleport : SpellAction {
// Drop items conditionally, based on distance teleported.
// MOST IMPORTANT: Never drop main hand item, since if it's a trinket, it will get duplicated later.

if (!HexConfig.server().teleportDropItems())
return

val baseDropChance = distance / 10000.0

// Armor and hotbar items have a further reduced chance to be dropped since it's particularly annoying
Expand All @@ -83,6 +87,8 @@ object OpTeleport : SpellAction {

for ((pos, invItem) in teleportee.inventory.items.withIndex()) {
if (invItem == teleportee.mainHandItem) continue
if (!HexConfig.server().teleportDropItem(BuiltInRegistries.ITEM.getKey(invItem.item))) continue

val dropChance = if (pos < 9) baseDropChance * 0.5 else baseDropChance // hotbar
if (Math.random() < dropChance) {
teleportee.drop(invItem.copy(), true, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static void registerItemCreativeTab(CreativeModeTab.Output r, CreativeMod
public static final ItemAbacus ABACUS = make("abacus", new ItemAbacus(unstackable()));
public static final ItemThoughtKnot THOUGHT_KNOT = make("thought_knot", new ItemThoughtKnot(unstackable()));
public static final ItemFocus FOCUS = make("focus", new ItemFocus(unstackable()));
public static final ItemSpellbook SPELLBOOK = make("spellbook", new ItemSpellbook(unstackable()));
public static final ItemSpellbook SPELLBOOK = make("spellbook", new ItemSpellbook(unstackable().fireResistant()));

public static final ItemCypher CYPHER = make("cypher", new ItemCypher(unstackable()));
public static final ItemTrinket TRINKET = make("trinket", new ItemTrinket(unstackable().rarity(Rarity.UNCOMMON)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ public static final class Server implements HexConfig.ServerConfigAccess, Config
@ConfigEntry.Gui.Tooltip
private List<String> tpDimDenylist = DEFAULT_DIM_TP_DENYLIST;

@ConfigEntry.Gui.Tooltip
private boolean teleportDropItems = DEFAULT_TELEPORT_DROP_ITEMS;

@ConfigEntry.Gui.Tooltip
private List<String> tpItemDropDenylist = DEFAULT_TP_ITEM_DROP_DENYLIST;

// ModMenu bad and doesn't like java objects in here so we do stupid string parsing
@ConfigEntry.Gui.Tooltip
private List<String> scrollInjectionsRaw = HexLootHandler.DEFAULT_SCROLL_INJECTS
Expand Down Expand Up @@ -250,6 +256,16 @@ public boolean canTeleportInThisDimension(ResourceKey<Level> dimension) {
return noneMatch(tpDimDenylist, dimension.location());
}

@Override
public boolean teleportDropItems() {
return teleportDropItems;
}

@Override
public boolean teleportDropItem(ResourceLocation item) {
return noneMatch(tpItemDropDenylist, item);
}

/**
* Returns -1 if none is found
*/
Expand Down
20 changes: 20 additions & 0 deletions Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public static class Server implements HexConfig.ServerConfigAccess {

private static ForgeConfigSpec.ConfigValue<List<? extends String>> tpDimDenyList;

private static ForgeConfigSpec.BooleanValue teleportDropItems;

private static ForgeConfigSpec.ConfigValue<List<? extends String>> tpItemDropDenylist;

private static ForgeConfigSpec.ConfigValue<List<? extends String>> fewScrollTables;
private static ForgeConfigSpec.ConfigValue<List<? extends String>> someScrollTables;
private static ForgeConfigSpec.ConfigValue<List<? extends String>> manyScrollTables;
Expand Down Expand Up @@ -170,6 +174,12 @@ public Server(ForgeConfigSpec.Builder builder) {

tpDimDenyList = builder.comment("Resource locations of dimensions you can't Blink or Greater Teleport in.")
.defineList("tpDimDenyList", DEFAULT_DIM_TP_DENYLIST, Server::isValidReslocArg);

teleportDropItems = builder.comment("Whether Greater Teleporting drops any items at all for the caster.")
.define("teleportDropItems", DEFAULT_TELEPORT_DROP_ITEMS);

tpItemDropDenylist = builder.comment("Resource locations of items that won't be dropped when Greater Teleporting.")
.defineList("tpItemDropDenylist", DEFAULT_TP_ITEM_DROP_DENYLIST, Server::isValidReslocArg);
}

@Override
Expand Down Expand Up @@ -207,6 +217,16 @@ public boolean canTeleportInThisDimension(ResourceKey<Level> dimension) {
return noneMatch(tpDimDenyList.get(), dimension.location());
}

@Override
public boolean teleportDropItems() {
return teleportDropItems.get();
}

@Override
public boolean teleportDropItem(ResourceLocation item) {
return noneMatch(tpItemDropDenylist.get(), item);
}

private static boolean isValidReslocArg(Object o) {
return o instanceof String s && ResourceLocation.isValidResourceLocation(s);
}
Expand Down

0 comments on commit 7ab0cc2

Please sign in to comment.