Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loonium with data-driven structure loot #4639

Open
wants to merge 21 commits into
base: 1.20.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c3969ac
Add structure detection to Loonium
TheRealWormbo May 7, 2024
d3b2ab5
Datagen for Loonium loot tables
TheRealWormbo May 8, 2024
7cd3bfa
Remove igloo bottom from loot structures
TheRealWormbo May 8, 2024
5d5e216
Adjust loot table definitions
TheRealWormbo May 8, 2024
420f919
Update lexicon description of Loonium
TheRealWormbo May 8, 2024
2807ba6
Expand wand HUD to indicate Loonium structure detection
TheRealWormbo May 9, 2024
37d1686
Datagen for structure-specific Loonium configurations
TheRealWormbo May 9, 2024
39db350
Datagen for and loading of structure-specific Loonium configurations
TheRealWormbo May 10, 2024
3086c97
Loonium uses structure configs and loot
TheRealWormbo May 10, 2024
40c8422
Remove unintended non-Loonium drops from additional mobs
TheRealWormbo May 12, 2024
1f52560
Limit number of spawned mobs around Loonium
TheRealWormbo May 12, 2024
1f2ec79
Loonium-spawned mobs have no instant despawn range
TheRealWormbo May 12, 2024
5d4214d
Fix structure configuration lookup
TheRealWormbo May 13, 2024
18658f4
Apply bonuses to additionally spawned Loonium mobs
TheRealWormbo May 17, 2024
6903b3d
General Loonium structure config cleanup
TheRealWormbo May 18, 2024
0ec339e
Add equipment table support to Loonium
TheRealWormbo May 20, 2024
afca0bf
Fix spawned mobs suffocating and add spawn effect to flower
TheRealWormbo May 24, 2024
20814da
Actually consume the configured amount of mana
TheRealWormbo May 24, 2024
e9df32d
Loonium mobs are on a team and grant an advancement
TheRealWormbo May 30, 2024
1c516fd
Hint at Loonium item exclusion list in lexicon description
TheRealWormbo Jun 17, 2024
39cc716
Code style improvements and review findings
TheRealWormbo Aug 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -733,11 +733,12 @@ public static void registerWandHudCaps(BotaniaBlockEntities.BECapConsumer<WandHU
consumer.accept(be -> new HopperhockBlockEntity.WandHud((HopperhockBlockEntity) be), HOPPERHOCK, HOPPERHOCK_CHIBI);
consumer.accept(be -> new PollidisiacBlockEntity.WandHud((PollidisiacBlockEntity) be), POLLIDISIAC);
consumer.accept(be -> new RannuncarpusBlockEntity.WandHud((RannuncarpusBlockEntity) be), RANNUNCARPUS, RANNUNCARPUS_CHIBI);
consumer.accept(be -> new LooniumBlockEntity.WandHud((LooniumBlockEntity) be), LOONIUM);
consumer.accept(be -> new BindableSpecialFlowerBlockEntity.BindableFlowerWandHud<>((FunctionalFlowerBlockEntity) be),
BELLETHORNE, BELLETHORNE_CHIBI, DREADTHORN, HEISEI_DREAM, TIGERSEYE,
JADED_AMARANTHUS, ORECHID, FALLEN_KANADE, EXOFLAME, AGRICARNATION, AGRICARNATION_CHIBI,
TANGLEBERRIE, TANGLEBERRIE_CHIBI, JIYUULIA, JIYUULIA_CHIBI, HYACIDUS,
CLAYCONIA, CLAYCONIA_CHIBI, LOONIUM, DAFFOMILL, VINCULOTUS, SPECTRANTHEMUM, MEDUMONE,
CLAYCONIA, CLAYCONIA_CHIBI, DAFFOMILL, VINCULOTUS, SPECTRANTHEMUM, MEDUMONE,
MARIMORPHOSIS, MARIMORPHOSIS_CHIBI, BUBBELL, BUBBELL_CHIBI, SOLEGNOLIA, SOLEGNOLIA_CHIBI,
ORECHID_IGNEM, LABELLIA);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
*/
package vazkii.botania.common.block.flower.functional;

import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectBooleanPair;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -196,7 +199,7 @@ private ItemStack pickRandomLoot(ServerLevel world, RandomSource rand) {

private void autodetectStructureLootTables(ServerLevel world) {
// structure ID -> whether the position is inside a structure piece (false = only overall bounding box)
var detectedStructures = new Object2BooleanOpenHashMap<ResourceLocation>();
var detectedStructures = new ArrayList<ObjectBooleanPair<ResourceLocation>>();
StructureManager structureManager = world.structureManager();
BlockPos pos = getBlockPos();
var structures = structureManager.getAllStructuresAt(pos);
Expand All @@ -207,7 +210,7 @@ private void autodetectStructureLootTables(ServerLevel world) {
ResourceLocation structureId = world.registryAccess().registryOrThrow(Registries.STRUCTURE).getKey(structure);
boolean insidePiece = structureManager.structureHasPieceAt(pos, start);
BotaniaAPI.LOGGER.info("Found structure {}, inside piece: {}", structureId, insidePiece);
detectedStructures.put(structureId, insidePiece);
detectedStructures.add(ObjectBooleanPair.of(structureId, insidePiece));
}
}

Expand All @@ -217,12 +220,12 @@ private void autodetectStructureLootTables(ServerLevel world) {
}

var lootTableCandidates = new ArrayList<ResourceLocation>(detectedStructures.size());
for (var entry : detectedStructures.object2BooleanEntrySet()) {
for (var entry : detectedStructures) {
// TODO: grab structure configuration data from registry (assume must be inside a piece for now)
if (!entry.getBooleanValue()) {
if (!entry.valueBoolean()) {
continue;
}
var structureId = entry.getKey();
var structureId = entry.key();
var candidateId = prefix("loonium/%s/%s".formatted(structureId.getNamespace(), structureId.getPath()));
LootTable lootTable = world.getServer().getLootData().getLootTable(candidateId);
if (lootTable != LootTable.EMPTY) {
Expand All @@ -234,6 +237,7 @@ private void autodetectStructureLootTables(ServerLevel world) {
BotaniaAPI.LOGGER.info("Using loot tables: {}", lootTableCandidates);
lootTables = lootTableCandidates.toArray(ResourceLocation[]::new);
setChanged();
sync();
}
}

Expand Down Expand Up @@ -262,7 +266,7 @@ public void readFromPacketNBT(CompoundTag cmp) {
super.readFromPacketNBT(cmp);
if (cmp.contains(TAG_LOOT_TABLE)) {
var lootTableString = cmp.getString(TAG_LOOT_TABLE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a String right? should just say String instead of var

lootTables = Arrays.stream(cmp.getString(lootTableString).split(","))
lootTables = Arrays.stream(lootTableString.split(","))
.map(ResourceLocation::new).toArray(ResourceLocation[]::new);
}
}
Expand All @@ -282,4 +286,30 @@ public static void dropLooniumItems(LivingEntity living, Consumer<ItemStack> con
consumer.accept(comp.getDrop());
}
}

public static class WandHud extends BindableFlowerWandHud<LooniumBlockEntity> {
public WandHud(LooniumBlockEntity flower) {
super(flower);
}

@Override
public void renderHUD(GuiGraphics gui, Minecraft mc) {
String attuneType;
if (Arrays.equals(flower.lootTables, DEFAULT_LOOT_TABLES)) {
attuneType = "generic_drops";
} else if (flower.lootTables.length == 1) {
attuneType = "structure_drops";
} else {
attuneType = "multiple_structure_drops";
}
String attuned = I18n.get("botaniamisc.loonium." + attuneType).formatted(flower.lootTables.length);
int filterWidth = mc.font.width(attuned);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter? is this copied from hopperhock?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is, oops.

int filterTextStart = (mc.getWindow().getGuiScaledWidth() - filterWidth) / 2;
int halfMinWidth = (filterWidth + 4) / 2;
int centerY = mc.getWindow().getGuiScaledHeight() / 2;

super.renderHUD(gui, mc, halfMinWidth, halfMinWidth, 40);
gui.drawString(mc.font, attuned, filterTextStart, centerY + 30, flower.getColor());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.Potions;
import net.minecraft.world.level.levelgen.structure.BuiltinStructures;
import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
Expand All @@ -18,7 +17,6 @@
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.entries.LootTableReference;
import net.minecraft.world.level.storage.loot.functions.SetPotionFunction;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;

import org.jetbrains.annotations.NotNull;
Expand Down
3 changes: 3 additions & 0 deletions Xplat/src/main/resources/assets/botania/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
"botaniamisc.rannuncarpus.state_sensitive": "Match Exact State",
"botaniamisc.rannuncarpus.state_insensitive": "Match Block Only",
"botaniamisc.lokiRingLimitReached": "Selection limit reached",
"botaniamisc.loonium.generic_drops": "Not attuned",
"botaniamisc.loonium.structure_drops": "Attuned to structure",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to say which structure it's attuned to if it's only one? The name could be specified in the config maybe. Another reason to require config i guess. It would result in twice the files together with my other idea (config references a loot table, and we have loot table functions that limit to one drop), but maybe not a huge issue? It feels cleaner and the most customizable

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That part changed in a later commit to "Generic loot", "Structure loot", or "Custom loot" (if the Loonium BE NBT is edited to have a custom loot table assigned), but either way, structures do not have display names. The only thing we could show is the structure resource location.

"botaniamisc.loonium.multiple_structure_drops": "Attuned to %d structures",
"botaniamisc.pollidisiac.feed_adults": "Feeding adult animals",
"botaniamisc.pollidisiac.feed_babies": "Feeding baby animals",
"botaniamisc.pollidisiac.feed_all": "Feeding all animals",
Expand Down