Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -16,7 +16,7 @@
"model": "mia:block/abyss_spawner_active"
},
"ominous=false,trial_spawner_state=waiting_for_reward_ejection": {
"model": "mia:block/abyss_spawner_active"
"model": "mia:block/abyss_spawner_ejecting_reward"
},
"ominous=true,trial_spawner_state=active": {
"model": "mia:block/abyss_spawner_active_ominous"
Expand All @@ -34,7 +34,7 @@
"model": "mia:block/abyss_spawner_active_ominous"
},
"ominous=true,trial_spawner_state=waiting_for_reward_ejection": {
"model": "mia:block/abyss_spawner_active_ominous"
"model": "mia:block/abyss_spawner_ejecting_reward_ominous"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"base_mobs": 1,
"entity_tables": [
{
"entity": "minecraft:warden",
"weight": 1
}
],
"loot_tables": [
{
"loot_table": "minecraft:chests/trial_chambers/reward_unique",
"weight": 10
},
{
"loot_table": "minecraft:chests/trial_chambers/reward_ominous_rare",
"weight": 5
}
],
"mobs_per_player": 0,
"spawn_per_tick": 1,
"spawn_range": 8
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"base_mobs": 2,
"entity_tables": [
{
"entity": "minecraft:skeleton",
"weight": 10
},
{
"entity": "minecraft:stray",
"weight": 5
},
{
"entity": "minecraft:bogged",
"weight": 2
}
],
"loot_tables": [
{
"loot_table": "minecraft:chests/trial_chambers/reward_common",
"weight": 10
},
{
"loot_table": "minecraft:chests/trial_chambers/reward_rare",
"weight": 5
}
],
"mobs_per_player": 1,
"spawn_per_tick": 1,
"spawn_range": 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"base_mobs": 4,
"entity_tables": [
{
"entity": "minecraft:spider",
"weight": 10
},
{
"entity": "minecraft:cave_spider",
"weight": 5
}
],
"loot_tables": [
{
"loot_table": "minecraft:chests/trial_chambers/reward_common",
"weight": 10
}
],
"mobs_per_player": 2,
"spawn_per_tick": 2,
"spawn_range": 6
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"base_mobs": 3,
"entity_tables": [
{
"entity": "minecraft:zombie",
"weight": 10
},
{
"entity": "minecraft:husk",
"weight": 5
},
{
"entity": "minecraft:drowned",
"weight": 3
}
],
"loot_tables": [
{
"loot_table": "minecraft:chests/trial_chambers/reward_common",
"weight": 10
},
{
"loot_table": "minecraft:chests/trial_chambers/reward_rare",
"weight": 3
},
{
"loot_table": "minecraft:chests/trial_chambers/reward_unique",
"weight": 1
}
],
"mobs_per_player": 2,
"spawn_per_tick": 1,
"spawn_range": 4
}
4 changes: 4 additions & 0 deletions src/main/java/com/altnoir/mia/MIA.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.altnoir.mia;

import com.altnoir.mia.core.curse.CurseManager;
import com.altnoir.mia.core.spawner.AbyssTrialSpawnerManager;
import com.altnoir.mia.core.spawner.records.AbyssTrialSpawnerPattern;
import com.altnoir.mia.init.*;
import com.altnoir.mia.init.event.EventHandle;
import com.altnoir.mia.init.worldgen.MiaBiomeSources;
Expand Down Expand Up @@ -28,6 +30,7 @@ public class MIA {
public static final Logger LOGGER = LogUtils.getLogger();

public static final CurseManager CURSE_MANAGER = new CurseManager();
public static final AbyssTrialSpawnerManager SPAWNER_MANAGER = new AbyssTrialSpawnerManager();

public MIA(IEventBus modEventBus, ModContainer modContainer) {
modEventBus.addListener(this::commonSetup);
Expand Down Expand Up @@ -79,6 +82,7 @@ public void onServerStarting(ServerStartingEvent event) {
@SubscribeEvent
private void reload(final AddReloadListenerEvent event) {
event.addListener(CURSE_MANAGER);
event.addListener(SPAWNER_MANAGER);
}

// You can use EventBusSubscriber to automatically register all static methods
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/altnoir/mia/block/AbyssSpawnerBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, Block
@Override
public void appendHoverText(ItemStack itemStack, Item.TooltipContext context, List<Component> components, TooltipFlag flag) {
super.appendHoverText(itemStack, context, components, flag);
Spawner.appendHoverText(itemStack, components, "spawn_data");
if (itemStack.has(net.minecraft.core.component.DataComponents.BLOCK_ENTITY_DATA)) {
var beData = itemStack.get(net.minecraft.core.component.DataComponents.BLOCK_ENTITY_DATA);
if (beData != null && beData.copyTag().contains("pattern_id")) {
String patternId = beData.copyTag().getString("pattern_id");
components.add(Component.literal("Pattern: " + patternId).withStyle(net.minecraft.ChatFormatting.GRAY));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,46 @@

import com.altnoir.mia.MIA;
import com.altnoir.mia.block.AbyssSpawnerBlock;
import com.altnoir.mia.core.spawner.AbyssTrialSpawner;
import com.altnoir.mia.core.spawner.records.AbyssTrialSpawnerPattern;
import com.altnoir.mia.init.MiaBlockEntities;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.EntityType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.Spawner;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.trialspawner.PlayerDetector;
import net.minecraft.world.level.block.entity.trialspawner.TrialSpawner;
import net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerState;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import org.jetbrains.annotations.Nullable;

public class AbyssSpawnerBlockEntity extends BlockEntity implements Spawner, TrialSpawner.StateAccessor {
private TrialSpawner abyssSpawner;
public class AbyssSpawnerBlockEntity extends BlockEntity implements AbyssTrialSpawner.StateAccessor {
private final AbyssTrialSpawner abyssSpawner;
@Nullable
private ResourceLocation patternId;
@Nullable
private AbyssTrialSpawnerPattern cachedPattern;

public AbyssSpawnerBlockEntity(BlockPos pos, BlockState state) {
super(MiaBlockEntities.ABYSS_SPAWNER.get(), pos, state);
PlayerDetector playerdetector = PlayerDetector.NO_CREATIVE_PLAYERS;
PlayerDetector.EntitySelector playerdetector$entityselector = PlayerDetector.EntitySelector.SELECT_FROM_LEVEL;
this.abyssSpawner = new TrialSpawner(this, playerdetector, playerdetector$entityselector);
this.abyssSpawner = new AbyssTrialSpawner(this);
}

@Override
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.loadAdditional(tag, registries);
if (tag.contains("normal_config")) {
CompoundTag compoundtag = tag.getCompound("normal_config").copy();
tag.put("ominous_config", compoundtag.merge(tag.getCompound("ominous_config")));
}

this.abyssSpawner.codec().parse(NbtOps.INSTANCE, tag).resultOrPartial(MIA.LOGGER::error).ifPresent(p_311911_ -> this.abyssSpawner = p_311911_);
if (tag.contains("pattern_id", CompoundTag.TAG_STRING)) {
this.patternId = ResourceLocation.parse(tag.getString("pattern_id"));
this.refreshPattern();
}

if (tag.contains("abyss_spawner", CompoundTag.TAG_COMPOUND)) {
this.abyssSpawner.load(tag.getCompound("abyss_spawner"));
}

if (this.level != null) {
this.markUpdated();
}
Expand All @@ -46,11 +50,12 @@ protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries)
@Override
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.saveAdditional(tag, registries);
this.abyssSpawner
.codec()
.encodeStart(NbtOps.INSTANCE, this.abyssSpawner)
.ifSuccess(tag1 -> tag.merge((CompoundTag) tag1))
.ifError(error -> MIA.LOGGER.warn("Failed to encode TrialSpawner {}", error.message()));

if (this.patternId != null) {
tag.putString("pattern_id", this.patternId.toString());
}

tag.put("abyss_spawner", this.abyssSpawner.save(new CompoundTag()));
}

public ClientboundBlockEntityDataPacket getUpdatePacket() {
Expand All @@ -59,21 +64,20 @@ public ClientboundBlockEntityDataPacket getUpdatePacket() {

@Override
public CompoundTag getUpdateTag(HolderLookup.Provider registries) {
return this.abyssSpawner.getData().getUpdateTag(this.getBlockState().getValue(AbyssSpawnerBlock.STATE));
var tag = new CompoundTag();
if (this.patternId != null) {
tag.putString("pattern_id", this.patternId.toString());
}
tag.put("abyss_spawner", this.abyssSpawner.save(new CompoundTag()));
return tag;
}

@Override
public boolean onlyOpCanSetNbt() {
return true;
}

@Override
public void setEntityId(EntityType<?> entityType, RandomSource random) {
this.abyssSpawner.getData().setEntityId(this.abyssSpawner, random, entityType);
this.setChanged();
}

public TrialSpawner getAbyssSpawner() {
public AbyssTrialSpawner getAbyssSpawner() {
return this.abyssSpawner;
}

Expand All @@ -97,4 +101,38 @@ public void markUpdated() {
this.level.sendBlockUpdated(this.worldPosition, this.getBlockState(), this.getBlockState(), 3);
}
}

public void setPatternId(@Nullable ResourceLocation patternId) {
this.patternId = patternId;
this.refreshPattern();
this.setChanged();
}

@Nullable
@Override
public ResourceLocation getPatternId() {
return this.patternId;
}

public void refreshPattern() {
if (this.patternId != null) {
this.cachedPattern = MIA.SPAWNER_MANAGER.getPattern(this.patternId).orElse(null);
if (this.cachedPattern == null) {
MIA.LOGGER.warn("Unknown spawner pattern: {}", this.patternId);
}
} else {
this.cachedPattern = null;
}
}

@Nullable
@Override
public AbyssTrialSpawnerPattern getPattern() {
return this.cachedPattern;
}

@Override
public boolean hasValidPattern() {
return this.cachedPattern != null;
}
}
18 changes: 8 additions & 10 deletions src/main/java/com/altnoir/mia/core/curse/CurseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.altnoir.mia.core.curse.records.CurseDimension;
import com.altnoir.mia.core.curse.records.CurseEffect;
import com.altnoir.mia.util.MiaUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
Expand All @@ -15,6 +16,7 @@
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
import net.minecraft.util.GsonHelper;
import net.minecraft.util.profiling.ProfilerFiller;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

import java.io.IOException;
Expand All @@ -34,22 +36,18 @@ public CurseManager() {
}

@Override
protected Map<ResourceLocation, JsonElement> prepare(ResourceManager resourceManager, ProfilerFiller profiler) {
protected @NotNull Map<ResourceLocation, JsonElement> prepare(ResourceManager resourceManager, @NotNull ProfilerFiller profiler) {
Map<ResourceLocation, JsonElement> result = new HashMap<>();

for (var namespace : resourceManager.getNamespaces()) {
var basePath = "mia/curse";
var resources = resourceManager.listResources(basePath, loc -> loc.getPath().endsWith(".json"));
for (Map.Entry<ResourceLocation, Resource> entry : resources.entrySet()) {
var fileLoc = entry.getKey();
var path = fileLoc.getPath();
if (!path.startsWith(basePath)) continue;
var trimmedPath = path.substring(basePath.length() + 1);
if (trimmedPath.endsWith(".json")) {
trimmedPath = trimmedPath.substring(0, trimmedPath.length() - 5);
}
var parts = trimmedPath.split("/");
if (parts.length > 2) continue;
var parts = MiaUtil.parseResourcePath(fileLoc.getPath(), basePath);

if (parts == null || parts.length > 2) continue;

var fixedLoc = ResourceLocation.fromNamespaceAndPath(parts[0], parts[1]);
var res = entry.getValue();
try (var stream = res.open()) {
Expand All @@ -65,7 +63,7 @@ protected Map<ResourceLocation, JsonElement> prepare(ResourceManager resourceMan
}

@Override
protected void apply(Map<ResourceLocation, JsonElement> resourceLocationJsonElementMap, ResourceManager resourceManager, ProfilerFiller profilerFiller) {
protected void apply(Map<ResourceLocation, JsonElement> resourceLocationJsonElementMap, @NotNull ResourceManager resourceManager, @NotNull ProfilerFiller profilerFiller) {
curseCache.clear();

LOGGER.info("Found {} curse config files.", resourceLocationJsonElementMap.size());
Expand Down
Loading