Skip to content

Commit

Permalink
fix: Fix compile errors on Forge
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Jan 13, 2025
1 parent ed62728 commit eba4171
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,17 @@
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);
}

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());
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.mrcrayfish.guns.event.GunFireEvent;
import net.blay09.mods.balm.api.Balm;
import net.blay09.mods.hardcorerevival.HardcoreRevival;
import net.blay09.mods.hardcorerevival.PlayerHardcoreRevivalManager;
import net.blay09.mods.hardcorerevival.config.HardcoreRevivalConfig;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
Expand All @@ -19,7 +19,7 @@ public MrCrayfishsGunModAddon() {

@SubscribeEvent
public void onGunFirePre(GunFireEvent.Pre event) {
if (HardcoreRevival.getRevivalData(event.getEntity()).isKnockedOut()) {
if (PlayerHardcoreRevivalManager.isKnockedOut(event.getEntity())) {
ResourceLocation mainHandItemKey = Balm.getRegistries().getKey(event.getEntity().getMainHandItem().getItem());
boolean isFiringPistol = Objects.equals(mainHandItemKey, PISTOL);
if (isFiringPistol && HardcoreRevivalConfig.getActive().allowPistols) {
Expand Down

0 comments on commit eba4171

Please sign in to comment.