Skip to content

Commit

Permalink
fix: Fix compile error on Forge
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Oct 30, 2024
1 parent b6a3730 commit 6e54261
Showing 1 changed file with 2 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,18 @@
import net.blay09.mods.balm.api.Balm;
import net.blay09.mods.balm.api.EmptyLoadContext;
import net.blay09.mods.balm.api.client.BalmClient;
import net.blay09.mods.balm.forge.provider.ForgeBalmProviders;
import net.blay09.mods.hardcorerevival.capability.HardcoreRevivalDataImpl;
import net.blay09.mods.hardcorerevival.client.HardcoreRevivalClient;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.*;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

import javax.annotation.Nullable;

@Mod(HardcoreRevival.MOD_ID)
public class ForgeHardcoreRevival {

private final Capability<HardcoreRevivalData> hardcoreRevivalDataCapability = CapabilityManager.get(new CapabilityToken<>() {
});

public ForgeHardcoreRevival() {
Balm.initialize(HardcoreRevival.MOD_ID, EmptyLoadContext.INSTANCE, HardcoreRevival::initialize);
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> BalmClient.initialize(HardcoreRevival.MOD_ID, EmptyLoadContext.INSTANCE, HardcoreRevivalClient::initialize));

FMLJavaModLoadingContext.get().getModEventBus().addListener(this::registerCapabilities);
MinecraftForge.EVENT_BUS.addGenericListener(Entity.class, this::attachEntityCapabilities);

ForgeBalmProviders providers = (ForgeBalmProviders) Balm.getProviders();
providers.register(HardcoreRevivalData.class, new CapabilityToken<>() {
});
}

private void registerCapabilities(RegisterCapabilitiesEvent event) {
event.register(HardcoreRevivalData.class);
DistExecutor.runWhenOn(Dist.CLIENT,
() -> () -> BalmClient.initialize(HardcoreRevival.MOD_ID, EmptyLoadContext.INSTANCE, HardcoreRevivalClient::initialize));
}

private void attachEntityCapabilities(AttachCapabilitiesEvent<Entity> event) {
if (event.getObject() instanceof Player) {
event.addCapability(ResourceLocation.fromNamespaceAndPath(HardcoreRevival.MOD_ID, "entity_data"), new ICapabilityProvider() {
private LazyOptional<HardcoreRevivalData> revival;

private LazyOptional<HardcoreRevivalData> getRevivalCapabilityInstance() {
if (revival == null) {
revival = LazyOptional.of(HardcoreRevivalDataImpl::new);
}

return revival;
}

@Override
public <T> LazyOptional<T> getCapability(Capability<T> cap, @Nullable Direction facing) {
return hardcoreRevivalDataCapability.orEmpty(cap, getRevivalCapabilityInstance());
}
});
}
}
}

0 comments on commit 6e54261

Please sign in to comment.