Skip to content

Commit

Permalink
wip: More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Jun 30, 2024
1 parent 65bfd55 commit 8459032
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -27,11 +33,13 @@ public class ExCompressum {
public static final Logger logger = LogManager.getLogger(MOD_ID);

public static SidedProxy<CommonProxy> proxy = Balm.sidedProxy("net.blay09.mods.excompressum.CommonProxy", "net.blay09.mods.excompressum.client.ClientProxy");
public static Function3<Gson, ResourceLocation, JsonElement, LootTable> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}

Expand All @@ -39,7 +52,8 @@ private InteractionResultHolder<ItemStack> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,21 +13,25 @@

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();
private static final WoodenCrucibleRegistry woodenCrucibleRegistry = new WoodenCrucibleRegistry();
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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,28 +16,17 @@
import java.util.List;
import java.util.Map;

public class CompressedRecipeRegistry implements ResourceManagerReloadListener {
public class CompressedRecipeRegistry {

private final List<CompressedRecipe> recipesSmall = new ArrayList<>();
private final List<CompressedRecipe> recipes = new ArrayList<>();

private final Map<ResourceLocation, CompressedRecipe> 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();
Expand Down Expand Up @@ -75,16 +62,10 @@ public void reloadRecipes() {
}
}
}

recipesLoaded = true;
}

@Nullable
public CompressedRecipe getRecipe(ItemStack itemStack) {
if (!recipesLoaded) {
reloadRecipes();
}

if (itemStack.getTag() != null) {
return null;
}
Expand Down

0 comments on commit 8459032

Please sign in to comment.