mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Fix LevelChunk capability attach crash.
Fix client chunks not having capability providers attached. Add capability attach tests.
This commit is contained in:
1 parent
d414e31f08
commit
1b7bdc3ec6
5 files changed
+195
-9
No files matched your search
@@ -30,6 +30,7 @@ import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -83,10 +84,16 @@ public abstract class CapabilityProvider<B extends ICapabilityProviderImpl<B>> i
|
||||
|
||||
private void doGatherCapabilities(@Nullable ICapabilityProvider parent)
|
||||
{
|
||||
this.capabilities = ForgeEventFactory.gatherCapabilities(baseClass, this, parent);
|
||||
this.capabilities = ForgeEventFactory.gatherCapabilities(baseClass, getProvider(), parent);
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
B getProvider()
|
||||
{
|
||||
return (B)this;
|
||||
}
|
||||
|
||||
protected final @Nullable CapabilityDispatcher getCapabilities()
|
||||
{
|
||||
if (isLazy && !initialized)
|
||||
@@ -196,14 +203,18 @@ public abstract class CapabilityProvider<B extends ICapabilityProviderImpl<B>> i
|
||||
*/
|
||||
public static class AsField<B extends ICapabilityProviderImpl<B>> extends CapabilityProvider<B>
|
||||
{
|
||||
public AsField(Class<B> baseClass)
|
||||
private final B owner;
|
||||
|
||||
public AsField(Class<B> baseClass, B owner)
|
||||
{
|
||||
super(baseClass);
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public AsField(Class<B> baseClass, boolean isLazy)
|
||||
public AsField(Class<B> baseClass, B owner, boolean isLazy)
|
||||
{
|
||||
super(baseClass, isLazy);
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public void initInternal()
|
||||
@@ -221,6 +232,13 @@ public abstract class CapabilityProvider<B extends ICapabilityProviderImpl<B>> i
|
||||
{
|
||||
deserializeCaps(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
B getProvider()
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2021.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.capabilities;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
Reference in new issue
Block a user