mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 02:55:17 +00:00
1.21.6 - New EventBus 7
A full rewrite and redesign of the library that offers much better performance, new features and fixes all previous design flaws See the migration guide here: https://gist.github.com/PaintNinja/ad82c224aecee25efac1ea3e2cf19b91 Co-authored-by: Paint_Ninja <[email protected]>
This commit is contained in:
642 files changed
+7258
-6187
No files matched your search
@@ -6,8 +6,8 @@
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
@@ -39,8 +39,11 @@ import java.util.stream.Stream;
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* on both {@linkplain LogicalSide logical sides}.</p>
|
||||
*/
|
||||
public final class ModMismatchEvent extends Event implements IModBusEvent
|
||||
{
|
||||
public final class ModMismatchEvent implements IModBusEvent {
|
||||
public static EventBus<ModMismatchEvent> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, ModMismatchEvent.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The level being loaded. Useful for things like {@link net.minecraft.world.level.storage.DimensionDataStorage}
|
||||
* to manage multiple files changing between mod versions.
|
||||
@@ -58,8 +61,7 @@ public final class ModMismatchEvent extends Event implements IModBusEvent
|
||||
private final HashMap<String, ModContainer> resolved;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ModMismatchEvent(LevelStorageSource.LevelDirectory levelDirectory, Map<String, ArtifactVersion> previousVersions, Map<String, ArtifactVersion> missingVersions)
|
||||
{
|
||||
public ModMismatchEvent(LevelStorageSource.LevelDirectory levelDirectory, Map<String, ArtifactVersion> previousVersions, Map<String, ArtifactVersion> missingVersions) {
|
||||
this.levelDirectory = levelDirectory;
|
||||
this.resolved = new HashMap<>(previousVersions.size());
|
||||
this.versionDifferences = new HashMap<>();
|
||||
@@ -76,8 +78,7 @@ public final class ModMismatchEvent extends Event implements IModBusEvent
|
||||
* Gets the current level directory for the world being loaded.
|
||||
* Can be used for file operations and manual modification of mod files before world load.
|
||||
*/
|
||||
public LevelStorageSource.LevelDirectory getLevelDirectory()
|
||||
{
|
||||
public LevelStorageSource.LevelDirectory getLevelDirectory() {
|
||||
return this.levelDirectory;
|
||||
}
|
||||
|
||||
@@ -87,8 +88,7 @@ public final class ModMismatchEvent extends Event implements IModBusEvent
|
||||
* @return The previously known mod version, or {@link Optional#empty()} if unknown/not found.
|
||||
*/
|
||||
@Nullable
|
||||
public ArtifactVersion getPreviousVersion(String modId)
|
||||
{
|
||||
public ArtifactVersion getPreviousVersion(String modId) {
|
||||
if (this.versionDifferences.containsKey(modId))
|
||||
return this.versionDifferences.get(modId).oldVersion();
|
||||
|
||||
@@ -96,8 +96,7 @@ public final class ModMismatchEvent extends Event implements IModBusEvent
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ArtifactVersion getCurrentVersion(String modid)
|
||||
{
|
||||
public ArtifactVersion getCurrentVersion(String modid) {
|
||||
if (this.versionDifferences.containsKey(modid))
|
||||
return this.versionDifferences.get(modid).newVersion();
|
||||
|
||||
@@ -107,8 +106,7 @@ public final class ModMismatchEvent extends Event implements IModBusEvent
|
||||
/**
|
||||
* Marks the mod version mismatch as having been resolved safely by the current mod.
|
||||
*/
|
||||
public void markResolved(String modId)
|
||||
{
|
||||
public void markResolved(String modId) {
|
||||
final var resolvedBy = ModLoadingContext.get().getActiveContainer();
|
||||
resolved.putIfAbsent(modId, resolvedBy);
|
||||
}
|
||||
@@ -116,65 +114,53 @@ public final class ModMismatchEvent extends Event implements IModBusEvent
|
||||
/**
|
||||
* Fetches the status of a mod mismatch handling state.
|
||||
*/
|
||||
public boolean wasResolved(String modId)
|
||||
{
|
||||
public boolean wasResolved(String modId) {
|
||||
return this.resolved.containsKey(modId);
|
||||
}
|
||||
|
||||
public Optional<MismatchedVersionInfo> getVersionDifference(String modid)
|
||||
{
|
||||
public Optional<MismatchedVersionInfo> getVersionDifference(String modid) {
|
||||
return Optional.ofNullable(this.versionDifferences.get(modid));
|
||||
}
|
||||
|
||||
public Optional<ModContainer> getResolver(String modid)
|
||||
{
|
||||
public Optional<ModContainer> getResolver(String modid) {
|
||||
return Optional.ofNullable(this.resolved.get(modid));
|
||||
}
|
||||
|
||||
public boolean anyUnresolved()
|
||||
{
|
||||
public boolean anyUnresolved() {
|
||||
return resolved.size() < versionDifferences.size();
|
||||
}
|
||||
|
||||
public Stream<MismatchResolutionResult> getUnresolved()
|
||||
{
|
||||
public Stream<MismatchResolutionResult> getUnresolved() {
|
||||
return versionDifferences.keySet().stream()
|
||||
.filter(modid -> !resolved.containsKey(modid))
|
||||
.map(unresolved -> new MismatchResolutionResult(unresolved, versionDifferences.get(unresolved), null))
|
||||
.sorted(Comparator.comparing(MismatchResolutionResult::modid));
|
||||
}
|
||||
|
||||
public boolean anyResolved()
|
||||
{
|
||||
public boolean anyResolved() {
|
||||
return !resolved.isEmpty();
|
||||
}
|
||||
|
||||
public Stream<MismatchResolutionResult> getResolved()
|
||||
{
|
||||
public Stream<MismatchResolutionResult> getResolved() {
|
||||
return resolved.keySet().stream()
|
||||
.map(modid -> new MismatchResolutionResult(modid, versionDifferences.get(modid), resolved.get(modid)))
|
||||
.sorted(Comparator.comparing(MismatchResolutionResult::modid));
|
||||
}
|
||||
|
||||
public record MismatchResolutionResult(String modid, MismatchedVersionInfo versionDifference, @Nullable ModContainer resolver)
|
||||
{
|
||||
public boolean wasSelfResolved()
|
||||
{
|
||||
public record MismatchResolutionResult(String modid, MismatchedVersionInfo versionDifference, @Nullable ModContainer resolver) {
|
||||
public boolean wasSelfResolved() {
|
||||
return resolver != null && resolver.getModId().equals(modid);
|
||||
}
|
||||
}
|
||||
|
||||
public record MismatchedVersionInfo(ArtifactVersion oldVersion, @Nullable ArtifactVersion newVersion)
|
||||
{
|
||||
public boolean isMissing()
|
||||
{
|
||||
public record MismatchedVersionInfo(ArtifactVersion oldVersion, @Nullable ArtifactVersion newVersion) {
|
||||
public boolean isMissing() {
|
||||
return newVersion == null;
|
||||
}
|
||||
|
||||
public boolean wasUpgrade()
|
||||
{
|
||||
public boolean wasUpgrade() {
|
||||
if (newVersion == null) return false;
|
||||
return newVersion.compareTo(oldVersion) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user