diff --git a/fabric/src/main/java/net/blay09/mods/excompressum/fabric/FabricExCompressum.java b/fabric/src/main/java/net/blay09/mods/excompressum/fabric/FabricExCompressum.java index 09834eb3..fb831222 100644 --- a/fabric/src/main/java/net/blay09/mods/excompressum/fabric/FabricExCompressum.java +++ b/fabric/src/main/java/net/blay09/mods/excompressum/fabric/FabricExCompressum.java @@ -3,10 +3,12 @@ import net.blay09.mods.balm.api.Balm; import net.blay09.mods.excompressum.ExCompressum; import net.fabricmc.api.ModInitializer; +import net.minecraft.world.level.storage.loot.LootTable; public class FabricExCompressum implements ModInitializer { @Override public void onInitialize() { Balm.initialize(ExCompressum.MOD_ID, ExCompressum::initialize); + ExCompressum.lootTableLoader = (gson, resourceLocation, jsonElement) -> gson.fromJson(jsonElement, LootTable.class); } } diff --git a/forge/src/main/java/net/blay09/mods/excompressum/forge/ForgeExCompressum.java b/forge/src/main/java/net/blay09/mods/excompressum/forge/ForgeExCompressum.java index cc645691..d8e6f206 100644 --- a/forge/src/main/java/net/blay09/mods/excompressum/forge/ForgeExCompressum.java +++ b/forge/src/main/java/net/blay09/mods/excompressum/forge/ForgeExCompressum.java @@ -6,6 +6,7 @@ import net.blay09.mods.excompressum.client.ExCompressumClient; import net.blay09.mods.excompressum.forge.compat.top.TheOneProbeAddon; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.common.Mod; @@ -20,6 +21,8 @@ public ForgeExCompressum() { DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> BalmClient.initialize(ExCompressum.MOD_ID, ExCompressumClient::initialize)); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::imc); + + ExCompressum.lootTableLoader = (gson, resourceLocation, jsonElement) -> ForgeHooks.loadLootTable(gson, resourceLocation, jsonElement, true); } private void imc(InterModEnqueueEvent event) { diff --git a/shared/src/main/java/net/blay09/mods/excompressum/ExCompressum.java b/shared/src/main/java/net/blay09/mods/excompressum/ExCompressum.java index 58f3d0f9..2813ddeb 100644 --- a/shared/src/main/java/net/blay09/mods/excompressum/ExCompressum.java +++ b/shared/src/main/java/net/blay09/mods/excompressum/ExCompressum.java @@ -1,5 +1,8 @@ package net.blay09.mods.excompressum; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.mojang.datafixers.util.Function3; import net.blay09.mods.balm.api.Balm; import net.blay09.mods.balm.api.proxy.SidedProxy; import net.blay09.mods.excompressum.api.ExCompressumAPI; @@ -16,8 +19,11 @@ import net.blay09.mods.excompressum.item.ModTags; import net.blay09.mods.excompressum.loot.ModLoot; import net.blay09.mods.excompressum.menu.ModMenus; +import net.blay09.mods.excompressum.registry.ExRegistries; import net.blay09.mods.excompressum.registry.ModRecipeTypes; import net.blay09.mods.excompressum.registry.autosieveskin.AutoSieveSkinRegistry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.storage.loot.LootTable; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -27,11 +33,13 @@ public class ExCompressum { public static final Logger logger = LogManager.getLogger(MOD_ID); public static SidedProxy proxy = Balm.sidedProxy("net.blay09.mods.excompressum.CommonProxy", "net.blay09.mods.excompressum.client.ClientProxy"); + public static Function3 lootTableLoader; public static void initialize() { ExCompressumAPI.__setupAPI(new InternalMethodsImpl()); ExCompressumConfig.initialize(); + ExRegistries.initialize(); ModBlocks.initialize(Balm.getBlocks()); ModBlockEntities.initialize(Balm.getBlockEntities()); ModEntities.initialize(Balm.getEntities()); diff --git a/shared/src/main/java/net/blay09/mods/excompressum/client/render/blockentity/AutoHammerRenderer.java b/shared/src/main/java/net/blay09/mods/excompressum/client/render/blockentity/AutoHammerRenderer.java index d5cccfa3..41817b66 100644 --- a/shared/src/main/java/net/blay09/mods/excompressum/client/render/blockentity/AutoHammerRenderer.java +++ b/shared/src/main/java/net/blay09/mods/excompressum/client/render/blockentity/AutoHammerRenderer.java @@ -63,7 +63,7 @@ public void render(AutoHammerBlockEntity tileEntity, float partialTicks, PoseSta tileEntity.hammerAngle += 0.4f * partialTicks; } - // Render the hammers + // Render the hammers TODO they movin way too fast rn poseStack.pushPose(); poseStack.mulPose(new Quaternionf(new AxisAngle4f(180, 0, 1f, 0f))); poseStack.mulPose(new Quaternionf(new AxisAngle4f((float) Math.sin(tileEntity.hammerAngle) * 15, 0, 0, 1f))); @@ -91,6 +91,8 @@ public void render(AutoHammerBlockEntity tileEntity, float partialTicks, PoseSta poseStack.popPose(); + // TODO content is slanted inside + ItemStack currentStack = tileEntity.getCurrentStack(); if (!currentStack.isEmpty()) { BlockState contentState = StupidUtils.getStateFromItemStack(currentStack); @@ -101,7 +103,7 @@ public void render(AutoHammerBlockEntity tileEntity, float partialTicks, PoseSta BlockRenderDispatcher dispatcher = Minecraft.getInstance().getBlockRenderer(); dispatcher.renderSingleBlock(contentState, poseStack, buffers, combinedLight, combinedOverlay); - if (tileEntity.getProgress() > 0f) { + if (tileEntity.getProgress() > 0f) { // TODO block break not showing on regular hammer? int blockDamage = Math.min(9, (int) (tileEntity.getProgress() * 9f)); BlockRenderUtils.renderBlockBreak(contentState, poseStack, buffers, combinedLight, combinedOverlay, blockDamage + 1); } diff --git a/shared/src/main/java/net/blay09/mods/excompressum/item/BatZapperItem.java b/shared/src/main/java/net/blay09/mods/excompressum/item/BatZapperItem.java index 7a8d11db..2b77b39a 100644 --- a/shared/src/main/java/net/blay09/mods/excompressum/item/BatZapperItem.java +++ b/shared/src/main/java/net/blay09/mods/excompressum/item/BatZapperItem.java @@ -1,5 +1,8 @@ package net.blay09.mods.excompressum.item; +import net.blay09.mods.balm.api.Balm; +import net.blay09.mods.balm.api.energy.BalmEnergyStorageProvider; +import net.blay09.mods.balm.api.energy.EnergyStorage; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.server.level.ServerLevel; @@ -25,6 +28,16 @@ public BatZapperItem(Item.Properties properties) { @Override public InteractionResult useOn(UseOnContext context) { + if (context.getPlayer() != null && context.getPlayer().getAbilities().instabuild) { + final var blockEntity = context.getLevel().getBlockEntity(context.getClickedPos()); + if (blockEntity != null) { + final var energyStorage = Balm.getProviders().getProvider(blockEntity, EnergyStorage.class); + if (energyStorage != null) { + energyStorage.setEnergy(energyStorage.getCapacity()); + } + } + } + return zapBatter(context.getLevel(), context.getPlayer(), context.getItemInHand(), context.getClickedPos(), context.getHand()).getResult(); } @@ -39,7 +52,8 @@ private InteractionResultHolder zapBatter(Level level, Player player, if (!level.isClientSide) { final int range = 5; - for (Bat entity : level.getEntitiesOfClass(Bat.class, new AABB(pos.getX() - range, pos.getY() - range, pos.getZ() - range, pos.getX() + range, pos.getY() + range, pos.getZ() + range))) { + for (Bat entity : level.getEntitiesOfClass(Bat.class, + new AABB(pos.getX() - range, pos.getY() - range, pos.getZ() - range, pos.getX() + range, pos.getY() + range, pos.getZ() + range))) { entity.hurt(level.damageSources().playerAttack(player), Float.MAX_VALUE); ((ServerLevel) level).sendParticles(ParticleTypes.CRIMSON_SPORE, entity.getX(), entity.getY(), entity.getZ(), 50, 0.1f, 0.1f, 0.1f, 0.1f); } diff --git a/shared/src/main/java/net/blay09/mods/excompressum/registry/ExRegistries.java b/shared/src/main/java/net/blay09/mods/excompressum/registry/ExRegistries.java index 89ee3098..2c011540 100644 --- a/shared/src/main/java/net/blay09/mods/excompressum/registry/ExRegistries.java +++ b/shared/src/main/java/net/blay09/mods/excompressum/registry/ExRegistries.java @@ -2,6 +2,8 @@ import net.blay09.mods.balm.api.Balm; import net.blay09.mods.balm.api.event.client.RecipesUpdatedEvent; +import net.blay09.mods.balm.api.event.server.ServerReloadFinishedEvent; +import net.blay09.mods.balm.api.event.server.ServerStartedEvent; import net.blay09.mods.excompressum.registry.chickenstick.ChickenStickRegistry; import net.blay09.mods.excompressum.registry.compressedhammer.CompressedHammerRegistry; import net.blay09.mods.excompressum.registry.compressor.CompressedRecipeRegistry; @@ -11,7 +13,7 @@ public class ExRegistries { - private static CompressedRecipeRegistry compressedRecipeRegistry; + private static final CompressedRecipeRegistry compressedRecipeRegistry = new CompressedRecipeRegistry(); private static final ChickenStickRegistry chickenStickRegistry = new ChickenStickRegistry(); private static final HammerRegistry hammerRegistry = new HammerRegistry(); private static final CompressedHammerRegistry compressedHammerRegistry = new CompressedHammerRegistry(); @@ -19,13 +21,17 @@ public class ExRegistries { private static final HeavySieveRegistry heavySieveRegistry = new HeavySieveRegistry(); public static void initialize() { - // TODO do we need this one still? Balm.addServerReloadListener(new ResourceLocation(ExCompressum.MOD_ID, "registries"), it -> compressedRecipeRegistry = new CompressedRecipeRegistry(it.getRecipeManager(), it.getRegistryAccess())); + Balm.getEvents() + .onEvent(ServerStartedEvent.class, + it -> compressedRecipeRegistry.reloadRecipes(it.getServer().getRecipeManager(), it.getServer().registryAccess())); + Balm.getEvents() + .onEvent(ServerReloadFinishedEvent.class, + it -> compressedRecipeRegistry.reloadRecipes(it.getServer().getRecipeManager(), it.getServer().registryAccess())); Balm.getEvents().onEvent(RecipesUpdatedEvent.class, ExRegistries::onRecipesUpdated); } public static void onRecipesUpdated(RecipesUpdatedEvent event) { - compressedRecipeRegistry = new CompressedRecipeRegistry(event.getRecipeManager(), event.getRegistryAccess()); - compressedRecipeRegistry.reloadRecipes(); + compressedRecipeRegistry.reloadRecipes(event.getRecipeManager(), event.getRegistryAccess()); } public static CompressedRecipeRegistry getCompressedRecipeRegistry() { diff --git a/shared/src/main/java/net/blay09/mods/excompressum/registry/LootTableProvider.java b/shared/src/main/java/net/blay09/mods/excompressum/registry/LootTableProvider.java index 86cc5ba4..23a8d1b8 100644 --- a/shared/src/main/java/net/blay09/mods/excompressum/registry/LootTableProvider.java +++ b/shared/src/main/java/net/blay09/mods/excompressum/registry/LootTableProvider.java @@ -1,6 +1,7 @@ package net.blay09.mods.excompressum.registry; import com.google.gson.*; +import net.blay09.mods.excompressum.ExCompressum; import net.blay09.mods.excompressum.api.ILootTableProvider; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.storage.loot.*; @@ -33,7 +34,7 @@ public LootTableProvider(LootTable inlineLootTable) { public LootTable getLootTable(@Nullable ResourceLocation resourceLocation, LootDataResolver lootDataResolver) { if (inlineLootTableJson != null || inlineLootTable != null) { if (inlineLootTable == null) { - inlineLootTable = GSON_INSTANCE.fromJson(inlineLootTableJson, LootTable.class); + inlineLootTable = ExCompressum.lootTableLoader.apply(GSON_INSTANCE, resourceLocation, inlineLootTableJson); } return inlineLootTable; } @@ -45,7 +46,7 @@ public LootTable getLootTable(@Nullable ResourceLocation resourceLocation, LootD public LootTable getLootTable(ResourceLocation resourceLocation, LootContext context) { if (inlineLootTableJson != null || inlineLootTable != null) { if (inlineLootTable == null) { - inlineLootTable = GSON_INSTANCE.fromJson(inlineLootTableJson, LootTable.class); + inlineLootTable = ExCompressum.lootTableLoader.apply(GSON_INSTANCE, resourceLocation, inlineLootTableJson); } return inlineLootTable; } diff --git a/shared/src/main/java/net/blay09/mods/excompressum/registry/compressor/CompressedRecipeRegistry.java b/shared/src/main/java/net/blay09/mods/excompressum/registry/compressor/CompressedRecipeRegistry.java index 2dafc68d..77d1a345 100644 --- a/shared/src/main/java/net/blay09/mods/excompressum/registry/compressor/CompressedRecipeRegistry.java +++ b/shared/src/main/java/net/blay09/mods/excompressum/registry/compressor/CompressedRecipeRegistry.java @@ -4,8 +4,6 @@ import net.minecraft.core.NonNullList; import net.minecraft.core.RegistryAccess; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.resources.ResourceManager; -import net.minecraft.server.packs.resources.ResourceManagerReloadListener; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; @@ -18,28 +16,17 @@ import java.util.List; import java.util.Map; -public class CompressedRecipeRegistry implements ResourceManagerReloadListener { +public class CompressedRecipeRegistry { private final List recipesSmall = new ArrayList<>(); private final List recipes = new ArrayList<>(); private final Map cachedResults = new HashMap<>(); - private final RecipeManager recipeManager; - private final RegistryAccess registryAccess; - private boolean recipesLoaded; - - public CompressedRecipeRegistry(RecipeManager recipeManager, RegistryAccess registryAccess) { - this.recipeManager = recipeManager; - this.registryAccess = registryAccess; - } - - @Override - public void onResourceManagerReload(ResourceManager resourceManager) { - recipesLoaded = false; + public CompressedRecipeRegistry() { } - public void reloadRecipes() { + public void reloadRecipes(RecipeManager recipeManager, RegistryAccess registryAccess) { cachedResults.clear(); recipesSmall.clear(); recipes.clear(); @@ -75,16 +62,10 @@ public void reloadRecipes() { } } } - - recipesLoaded = true; } @Nullable public CompressedRecipe getRecipe(ItemStack itemStack) { - if (!recipesLoaded) { - reloadRecipes(); - } - if (itemStack.getTag() != null) { return null; }