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:
LexManosandPaint_Ninja committed 2025-06-18 02:53:58 -07:00
1 parent a02f3f9841
commit 5e8942e0a7
642 files changed
+7258 -6187

No files matched your search

@@ -10,16 +10,21 @@ import java.util.Objects;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.TagValueInput;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.resources.ResourceKey;
import net.minecraft.util.ProblemReporter;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.Level;
import net.minecraftforge.server.ServerLifecycleHooks;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import com.mojang.logging.LogUtils;
/**
* Represents a captured snapshot of a block which will not change
@@ -29,6 +34,7 @@ import org.jetbrains.annotations.Nullable;
* can exist multiple times for any given Block.
*/
public class BlockSnapshot {
private static final Logger LOGGER = LogUtils.getLogger();
private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("forge.debugBlockSnapshot", "false"));
private final ResourceKey<Level> dim;
@@ -65,7 +71,7 @@ public class BlockSnapshot {
@Nullable
private static CompoundTag getBlockEntityTag(@Nullable BlockEntity te, HolderLookup.Provider lookup) {
return te == null ? null : te.saveCustomAndMetadata(lookup);
return te == null ? null : te.saveWithFullMetadata(lookup);
}
public BlockState getCurrentBlock() {
@@ -127,7 +133,10 @@ public class BlockSnapshot {
if (getTag() != null) {
te = world.getBlockEntity(pos);
if (te != null) {
te.loadWithComponents(nbt, world.registryAccess());
try (var problems = new ProblemReporter.ScopedCollector(te.problemPath(), LOGGER)) {
te.loadWithComponents(TagValueInput.create(problems, world.registryAccess(), getTag()));
}
te.setChanged();
}
}
@@ -0,0 +1,31 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.common.util;
import net.minecraftforge.eventbus.api.event.RecordEvent;
import org.jspecify.annotations.NullMarked;
@NullMarked
public interface HasResult {
Result getResult();
void setResult(Result result);
/**
* A version of {@link HasResult} tailored for {@link RecordEvent}s.
*/
@NullMarked
interface Record extends HasResult {
Result.Holder resultHolder();
default Result getResult() {
return resultHolder().get();
}
default void setResult(Result result) {
resultHolder().set(result);
}
}
}
@@ -0,0 +1,70 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.common.util;
import net.minecraftforge.eventbus.api.event.RecordEvent;
import org.jspecify.annotations.NullMarked;
import java.util.Objects;
@NullMarked
public enum Result {
ALLOW,
DEFAULT,
DENY;
public boolean isAllowed() {
return this == ALLOW;
}
public boolean isDefault() {
return this == DEFAULT;
}
public boolean isDenied() {
return this == DENY;
}
/**
* A mutable holder for a Result, useful for {@link RecordEvent}s combined with {@link HasResult.Record}
*/
@NullMarked
public static final class Holder {
private Result value;
public Holder() {
set(DEFAULT);
}
public Holder(Result value) {
set(value);
}
public Result get() {
return value;
}
public void set(Result value) {
Objects.requireNonNull(value);
this.value = value;
}
@Override
public String toString() {
return "Result.Holder{value=" + value + "\"}";
}
@Override
public boolean equals(Object that) {
return this == that || (that instanceof Holder thatHolder && this.value == thatHolder.value);
}
@Override
public int hashCode() {
return value.hashCode();
}
}
}