From 503dbf0d0bfc5c542ad9ddfbf31f7196dcbf398a Mon Sep 17 00:00:00 2001 From: EERussianguy Date: Sun, 28 Aug 2022 16:20:54 -0400 Subject: [PATCH] fix resource reloading issues, fix mixing bowl loot table, maybe fix beehive issue --- resources/assets.py | 2 +- .../com/eerussianguy/firmalife/FirmaLife.java | 2 +- .../firmalife/common/FLEvents.java | 63 +++++++-------- .../common/blocks/FLBeehiveBlock.java | 7 +- .../common/util/SafePathResourcePack.java | 77 ------------------- .../loot_tables/blocks/mixing_bowl.json | 2 +- 6 files changed, 40 insertions(+), 113 deletions(-) delete mode 100644 src/main/java/com/eerussianguy/firmalife/common/util/SafePathResourcePack.java diff --git a/resources/assets.py b/resources/assets.py index b67dd847..5781ca30 100644 --- a/resources/assets.py +++ b/resources/assets.py @@ -30,7 +30,7 @@ def generate(rm: ResourceManager): rm.blockstate('drying_mat', model='firmalife:block/drying_mat').with_item_model().with_tag('tfc:mineable_with_sharp_tool').with_lang(lang('drying mat')).with_block_loot('firmalife:drying_mat') block = rm.blockstate('mixing_bowl', model='firmalife:block/mixing_bowl').with_item_model().with_tag('minecraft:mineable/axe').with_lang(lang('mixing bowl')) - block.with_block_loot({'name': 'firmalife:mixing_bowl'}, {'name': 'firmalife:mixing_bowl', 'conditions': [loot_tables.block_state_property('firmalife:mixing_bowl[spoon=true]')]}) + block.with_block_loot({'name': 'firmalife:mixing_bowl'}, {'name': 'firmalife:spoon', 'conditions': [loot_tables.block_state_property('firmalife:mixing_bowl[spoon=true]')]}) for fruit in TFC_FRUITS: rm.item_model(('not_dried', fruit), 'tfc:item/food/%s' % fruit) diff --git a/src/main/java/com/eerussianguy/firmalife/FirmaLife.java b/src/main/java/com/eerussianguy/firmalife/FirmaLife.java index 404a0860..7c7af065 100644 --- a/src/main/java/com/eerussianguy/firmalife/FirmaLife.java +++ b/src/main/java/com/eerussianguy/firmalife/FirmaLife.java @@ -55,9 +55,9 @@ public FirmaLife() FLPackets.init(); - FLEvents.init(); bus.addListener(this::setup); + FLEvents.init(); FLForgeEvents.init(); if (FMLEnvironment.dist == Dist.CLIENT) { diff --git a/src/main/java/com/eerussianguy/firmalife/common/FLEvents.java b/src/main/java/com/eerussianguy/firmalife/common/FLEvents.java index 51470156..1fd9cca5 100644 --- a/src/main/java/com/eerussianguy/firmalife/common/FLEvents.java +++ b/src/main/java/com/eerussianguy/firmalife/common/FLEvents.java @@ -1,12 +1,13 @@ package com.eerussianguy.firmalife.common; +import net.minecraft.server.packs.PackType; + import java.io.IOException; import java.nio.file.Path; import javax.annotation.Nonnull; import net.minecraft.network.chat.TextComponent; -import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.metadata.pack.PackMetadataSection; import net.minecraft.server.packs.repository.Pack; import net.minecraft.server.packs.repository.PackSource; @@ -14,9 +15,9 @@ import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.resource.PathResourcePack; import com.eerussianguy.firmalife.FirmaLife; -import com.eerussianguy.firmalife.common.util.SafePathResourcePack; public class FLEvents { @@ -29,34 +30,34 @@ public static void init() public static void onPackFinder(AddPackFindersEvent event) { - ModList.get().getMods().forEach(mod -> FirmaLife.LOGGER.info(mod.getModId())); -// try -// { -// if (event.getPackType() == PackType.SERVER_DATA) -// { -// var modFile = ModList.get().getModFileById(FirmaLife.MOD_ID).getFile(); -// var resourcePath = modFile.getFilePath(); -// var pack = new SafePathResourcePack(modFile.getFileName() + ":overload", resourcePath) { -// @Nonnull -// @Override -// protected Path resolve(@Nonnull String... paths) -// { -// return modFile.findResource(paths); -// } -// }; -// -// var metadata = pack.getMetadataSection(PackMetadataSection.SERIALIZER); -// if (metadata != null) -// { -// event.addRepositorySource((consumer, constructor) -> -// consumer.accept(constructor.create("builtin/firmalife_data", new TextComponent("Firmalife Data"), true, () -> pack, metadata, Pack.Position.TOP, PackSource.BUILT_IN, false)) -// ); -// } -// } -// } -// catch (IOException e) -// { -// throw new RuntimeException(e); -// } + try + { + if (event.getPackType() == PackType.CLIENT_RESOURCES) + { + var modFile = ModList.get().getModFileById(FirmaLife.MOD_ID).getFile(); + var resourcePath = modFile.getFilePath(); + var pack = new PathResourcePack(modFile.getFileName() + ":overload", resourcePath) + { + @Nonnull + @Override + protected Path resolve(@Nonnull String... paths) + { + return modFile.findResource(paths); + } + }; + var metadata = pack.getMetadataSection(PackMetadataSection.SERIALIZER); + if (metadata != null) + { + event.addRepositorySource((consumer, constructor) -> + consumer.accept(constructor.create("builtin/firmalife_data", new TextComponent("Firmalife Resources"), true, () -> pack, metadata, Pack.Position.TOP, PackSource.BUILT_IN, false)) + ); + } + } + } + catch (IOException e) + { + throw new RuntimeException(e); + } } + } diff --git a/src/main/java/com/eerussianguy/firmalife/common/blocks/FLBeehiveBlock.java b/src/main/java/com/eerussianguy/firmalife/common/blocks/FLBeehiveBlock.java index 00fe6a12..b2aae71d 100644 --- a/src/main/java/com/eerussianguy/firmalife/common/blocks/FLBeehiveBlock.java +++ b/src/main/java/com/eerussianguy/firmalife/common/blocks/FLBeehiveBlock.java @@ -115,9 +115,12 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player }); return InteractionResult.sidedSuccess(level.isClientSide); } - else if (!player.isShiftKeyDown() && player instanceof ServerPlayer serverPlayer) + else if (!player.isShiftKeyDown()) { - level.getBlockEntity(pos, FLBlockEntities.BEEHIVE.get()).ifPresent(nest -> NetworkHooks.openGui(serverPlayer, nest, pos)); + if (player instanceof ServerPlayer serverPlayer) + { + level.getBlockEntity(pos, FLBlockEntities.BEEHIVE.get()).ifPresent(nest -> NetworkHooks.openGui(serverPlayer, nest, pos)); + } return InteractionResult.sidedSuccess(level.isClientSide); } return InteractionResult.PASS; diff --git a/src/main/java/com/eerussianguy/firmalife/common/util/SafePathResourcePack.java b/src/main/java/com/eerussianguy/firmalife/common/util/SafePathResourcePack.java deleted file mode 100644 index 7b41ba25..00000000 --- a/src/main/java/com/eerussianguy/firmalife/common/util/SafePathResourcePack.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.eerussianguy.firmalife.common.util; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collection; -import java.util.Collections; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import javax.annotation.Nonnull; - -import com.google.common.base.Joiner; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.PackType; -import net.minecraftforge.common.ForgeConfig; -import net.minecraftforge.resource.PathResourcePack; -import net.minecraftforge.resource.ResourceCacheManager; - -public class SafePathResourcePack extends PathResourcePack -{ - private final ResourceCacheManager cacheManager = new ResourceCacheManager(true, ForgeConfig.COMMON.indexModPackCachesOnThread, (packType, namespace) -> resolve(packType.getDirectory(), namespace).toAbsolutePath()); - - public SafePathResourcePack(String packName, Path source) - { - super(packName, source); - } - - @Override - public Collection getResources(PackType type, String resourceNamespace, String pathIn, int maxDepth, Predicate filter) - { - try - { - Path root = resolve(type.getDirectory(), resourceNamespace).toAbsolutePath(); - Path inputPath = root.getFileSystem().getPath(pathIn); - - if (ResourceCacheManager.shouldUseCache() && this.cacheManager.hasCached(type, resourceNamespace)) - { - return this.cacheManager.getResources(type, resourceNamespace, inputPath, filter); - } - - return Files.walk(root) - .map(root::relativize) - .filter(path -> path.getNameCount() <= maxDepth && !path.toString().endsWith(".mcmeta") && path.startsWith(inputPath)) - .filter(path -> filter.test(path.getFileName().toString())) - // backporting fix for resource location path validity - .filter(path -> ResourceLocation.isValidPath(Joiner.on('/').join(path))) - .map(path -> new ResourceLocation(resourceNamespace, Joiner.on('/').join(path))) - .collect(Collectors.toList()); - } - catch (IOException e) - { - return Collections.emptyList(); - } - } - - @Override - public void initForNamespace(final String namespace) - { - if (ResourceCacheManager.shouldUseCache()) - { - this.cacheManager.index(namespace); - } - } - - @Override - public Set getNamespaces(PackType type) - { - if (ResourceCacheManager.shouldUseCache()) - { - return this.cacheManager.getNamespaces(type); - } - - return getNamespacesFromDisk(type); - } -} diff --git a/src/main/resources/data/firmalife/loot_tables/blocks/mixing_bowl.json b/src/main/resources/data/firmalife/loot_tables/blocks/mixing_bowl.json index 21f56c00..8e66ebb5 100644 --- a/src/main/resources/data/firmalife/loot_tables/blocks/mixing_bowl.json +++ b/src/main/resources/data/firmalife/loot_tables/blocks/mixing_bowl.json @@ -23,7 +23,7 @@ "entries": [ { "type": "minecraft:item", - "name": "firmalife:mixing_bowl", + "name": "firmalife:spoon", "conditions": [ { "condition": "minecraft:block_state_property",