Nothing to see here folks 👀
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.CraterConstants;
|
||||
import com.hypherionmc.craterlib.core.systems.internal.CreativeTabRegistry;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = CraterConstants.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class NeoForgeCommonEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerTabs(BuildCreativeModeTabContentsEvent event) {
|
||||
CreativeModeTab tab = event.getTab();
|
||||
|
||||
CreativeTabRegistry.getTabItems().stream()
|
||||
.filter(p -> p.getLeft().get() == tab && p.getRight() != null)
|
||||
.forEach(itemPair -> event.accept(itemPair.getRight().get()));
|
||||
}
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.api.blockentity.caps.CraterCapabilityHandler;
|
||||
import com.hypherionmc.craterlib.api.blockentity.caps.ICraterCapProvider;
|
||||
import com.hypherionmc.craterlib.core.network.CraterNetworkHandler;
|
||||
import com.hypherionmc.craterlib.core.platform.CommonPlatform;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.ICraterFluidHandler;
|
||||
import com.hypherionmc.craterlib.network.NeoForgeNetworkHandler;
|
||||
import com.hypherionmc.craterlib.systems.energy.NeoForgeEnergyReader;
|
||||
import com.hypherionmc.craterlib.systems.fluid.NeoForgeFluidReader;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.neoforged.neoforge.common.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.common.extensions.IMenuTypeExtension;
|
||||
import net.neoforged.neoforge.server.ServerLifecycleHooks;
|
||||
import org.apache.commons.lang3.function.TriFunction;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
public class NeoForgeCommonHelper implements CommonPlatform {
|
||||
|
||||
public static Map<ResourceLocation, CreativeModeTab> TABS = new HashMap<>();
|
||||
|
||||
public NeoForgeCommonHelper() {}
|
||||
|
||||
@Override
|
||||
public CraterNetworkHandler createPacketHandler(String modid, boolean requiredClient, boolean requiredServer) {
|
||||
return NeoForgeNetworkHandler.of(modid, requiredClient, requiredServer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinecraftServer getMCServer() {
|
||||
return ServerLifecycleHooks.getCurrentServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openMenu(ServerPlayer player, MenuProvider menu, @Nullable Consumer<FriendlyByteBuf> initialData) {
|
||||
// TODO Fix Menus
|
||||
/*if (initialData != null) {
|
||||
player.openMenu(menu, initialData);
|
||||
} else {
|
||||
player.openMenu(menu, player.getOnPos());
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends AbstractContainerMenu> MenuType<T> createMenuType(TriFunction<Integer, Inventory, FriendlyByteBuf, T> constructor) {
|
||||
return IMenuTypeExtension.create(constructor::apply);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> getCapabilityHandler(BlockEntity entity, Direction side, CraterCapabilityHandler capability) {
|
||||
if (capability == CraterCapabilityHandler.ENERGY) {
|
||||
AtomicReference<NeoForgeEnergyReader> energyReference = new AtomicReference<>();
|
||||
entity.getCapability(Capabilities.ENERGY, side).ifPresent(storage -> energyReference.set(new NeoForgeEnergyReader(storage)));
|
||||
|
||||
return energyReference.get() != null ? (Optional<T>) Optional.of(energyReference.get()) : Optional.empty();
|
||||
}
|
||||
|
||||
if (capability == CraterCapabilityHandler.FLUID) {
|
||||
AtomicReference<ICraterFluidHandler> craterFluidHandler = new AtomicReference<>();
|
||||
entity.getCapability(Capabilities.FLUID_HANDLER, side).ifPresent(iFluidHandler -> craterFluidHandler.set(new NeoForgeFluidReader(iFluidHandler)));
|
||||
|
||||
return craterFluidHandler.get() != null ? (Optional<T>) Optional.of(craterFluidHandler.get()) : Optional.empty();
|
||||
}
|
||||
|
||||
if (entity instanceof ICraterCapProvider capProvider) {
|
||||
return capProvider.getCapability(capability, side);
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.CraterFluidHelper;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.CraterFluidTank;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.FluidHolder;
|
||||
import com.hypherionmc.craterlib.core.systems.fluid.ICraterFluidHandler;
|
||||
import com.hypherionmc.craterlib.systems.fluid.NeoForgeFluidTankInteractor;
|
||||
import com.hypherionmc.craterlib.systems.fluid.NeoForgeFluidUtils;
|
||||
import com.hypherionmc.craterlib.systems.fluid.NeoForgeWrappedFluidTank;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions;
|
||||
import net.neoforged.neoforge.fluids.FluidStack;
|
||||
import net.neoforged.neoforge.fluids.FluidUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class NeoForgeFluidHelper implements CraterFluidHelper {
|
||||
|
||||
@Override
|
||||
public CraterFluidTank createFluidTank(int capacity) {
|
||||
return new NeoForgeWrappedFluidTank(capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraterFluidTank createFluidTank(int capacity, Fluid... validFluids) {
|
||||
return new NeoForgeWrappedFluidTank(capacity, (variant) -> Arrays.stream(validFluids).allMatch(f -> f.isSame(variant.getFluid())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean interactWithFluidHandler(Player player, InteractionHand hand, ICraterFluidHandler fluidHandler) {
|
||||
NeoForgeFluidTankInteractor interactor = new NeoForgeFluidTankInteractor(fluidHandler);
|
||||
return FluidUtil.interactWithFluidHandler(player, hand, interactor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean interactWithFluidHandler(@NotNull Player player, @NotNull InteractionHand hand, @NotNull Level level, @NotNull BlockPos pos, @Nullable Direction side) {
|
||||
return FluidUtil.interactWithFluidHandler(player, hand, level, pos, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getFluidTexture(FluidHolder fluidHolder) {
|
||||
return NeoForgeFluidUtils.getFluidTexture(new FluidStack(fluidHolder.getFluid(), 0), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidColor(Fluid fluid) {
|
||||
IClientFluidTypeExtensions props = IClientFluidTypeExtensions.of(fluid);
|
||||
return props.getTintColor();
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.Environment;
|
||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.neoforged.fml.ModList;
|
||||
import net.neoforged.fml.loading.FMLLoader;
|
||||
import net.neoforged.fml.loading.FMLPaths;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
public class NeoForgeLoaderHelper implements ModloaderEnvironment {
|
||||
|
||||
public NeoForgeLoaderHelper() {}
|
||||
|
||||
@Override
|
||||
public boolean isFabric() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGameVersion() {
|
||||
return SharedConstants.VERSION_STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getGameFolder() {
|
||||
return Minecraft.getInstance().gameDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getConfigFolder() {
|
||||
return FMLPaths.CONFIGDIR.get().toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getModsFolder() {
|
||||
return FMLPaths.MODSDIR.get().toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Environment getEnvironment() {
|
||||
switch (FMLLoader.getDist()) {
|
||||
case CLIENT -> {
|
||||
return Environment.CLIENT;
|
||||
}
|
||||
case DEDICATED_SERVER -> {
|
||||
return Environment.SERVER;
|
||||
}
|
||||
}
|
||||
return Environment.UNKNOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModLoaded(String modid) {
|
||||
return ModList.get().isLoaded(modid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDevEnv() {
|
||||
return !FMLLoader.isProduction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModCount() {
|
||||
return ModList.get().size();
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.server.CraterRegisterCommandEvent;
|
||||
import com.hypherionmc.craterlib.api.event.server.CraterServerLifecycleEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStartingEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
|
||||
|
||||
public class NeoForgeServerEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
public void serverStarting(ServerStartingEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Starting(event.getServer()));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void serverStarted(ServerStartedEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Started());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void serverStopping(ServerStoppingEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Stopping());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void serverStopped(ServerStoppedEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Stopped());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onCommandRegister(RegisterCommandsEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterRegisterCommandEvent(event.getDispatcher()));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user