mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-25 14:34:28 +00:00
Update to 1.17
Update to Official classnames Patchwork Make the game compile and run Merge in the new HUD overlay API Merge in the new render properties API PEEL Use Gradle 7.2 snapshot to fix eclipse integration bug in 7.1, Would use 7.0 but FG needs 7.1 for some reason. New FML installer Update to 1.17.1 Co-authored-by: LexManos <[email protected]> Co-authored-by: SizableShrimp <[email protected]> Co-authored-by: cpw <[email protected]> Co-authored-by: Curle <[email protected]> Co-authored-by: Unnoen <[email protected]> Co-authored-by: covers1624 <[email protected]> Co-authored-by: DaemonUmbra <[email protected]> Co-authored-by: gigaherz <[email protected]> Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
064ae6961b
commit
be5446b91c
1990 files changed
+35661
-37544
No files matched your search
@@ -19,16 +19,9 @@
|
||||
|
||||
package net.minecraftforge.common.capabilities;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* This is the core holder object Capabilities.
|
||||
@@ -39,104 +32,12 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public class Capability<T>
|
||||
{
|
||||
public static interface IStorage<T>
|
||||
{
|
||||
/**
|
||||
* Serialize the capability instance to a NBTTag.
|
||||
* This allows for a central implementation of saving the data.
|
||||
*
|
||||
* It is important to note that it is up to the API defining
|
||||
* the capability what requirements the 'instance' value must have.
|
||||
*
|
||||
* Due to the possibility of manipulating internal data, some
|
||||
* implementations MAY require that the 'instance' be an instance
|
||||
* of the 'default' implementation.
|
||||
*
|
||||
* Review the API docs for more info.
|
||||
*
|
||||
* @param capability The Capability being stored.
|
||||
* @param instance An instance of that capabilities interface.
|
||||
* @param side The side of the object the instance is associated with.
|
||||
* @return a NBT holding the data. Null if no data needs to be stored.
|
||||
*/
|
||||
@Nullable
|
||||
INBT writeNBT(Capability<T> capability, T instance, Direction side);
|
||||
|
||||
/**
|
||||
* Read the capability instance from a NBT tag.
|
||||
*
|
||||
* This allows for a central implementation of saving the data.
|
||||
*
|
||||
* It is important to note that it is up to the API defining
|
||||
* the capability what requirements the 'instance' value must have.
|
||||
*
|
||||
* Due to the possibility of manipulating internal data, some
|
||||
* implementations MAY require that the 'instance' be an instance
|
||||
* of the 'default' implementation.
|
||||
*
|
||||
* Review the API docs for more info. *
|
||||
*
|
||||
* @param capability The Capability being stored.
|
||||
* @param instance An instance of that capabilities interface.
|
||||
* @param side The side of the object the instance is associated with.
|
||||
* @param nbt A NBT holding the data. Must not be null, as doesn't make sense to call this function with nothing to read...
|
||||
*/
|
||||
void readNBT(Capability<T> capability, T instance, Direction side, INBT nbt);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The unique name of this capability, typically this is
|
||||
* the fully qualified class name for the target interface.
|
||||
*/
|
||||
public String getName() { return name; }
|
||||
|
||||
/**
|
||||
* @return An instance of the default storage handler. You can safely use this store your default implementation in NBT.
|
||||
*/
|
||||
public IStorage<T> getStorage() { return storage; }
|
||||
|
||||
/**
|
||||
* Quick access to the IStorage's readNBT.
|
||||
* See {@link IStorage#readNBT(Capability, Object, EnumFacing, NBTBase)} for documentation.
|
||||
*/
|
||||
public void readNBT(T instance, Direction side, INBT nbt)
|
||||
{
|
||||
storage.readNBT(this, instance, side, nbt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick access to the IStorage's writeNBT.
|
||||
* See {@link IStorage#writeNBT(Capability, Object, EnumFacing)} for documentation.
|
||||
*/
|
||||
@Nullable
|
||||
public INBT writeNBT(T instance, Direction side)
|
||||
{
|
||||
return storage.writeNBT(this, instance, side);
|
||||
}
|
||||
|
||||
/**
|
||||
* A NEW instance of the default implementation.
|
||||
*
|
||||
* If it important to note that if you want to use the default storage
|
||||
* you may be required to use this exact implementation.
|
||||
* Refer to the owning API of the Capability in question.
|
||||
*
|
||||
* @return A NEW instance of the default implementation.
|
||||
*/
|
||||
@Nullable
|
||||
public T getDefaultInstance()
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.factory.call();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Throwables.throwIfUnchecked(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public @Nonnull <R> LazyOptional<R> orEmpty(Capability<R> toCheck, LazyOptional<T> inst)
|
||||
{
|
||||
return this == toCheck ? inst.cast() : LazyOptional.empty();
|
||||
@@ -144,13 +45,9 @@ public class Capability<T>
|
||||
|
||||
// INTERNAL
|
||||
private final String name;
|
||||
private final IStorage<T> storage;
|
||||
private final Callable<? extends T> factory;
|
||||
|
||||
Capability(String name, IStorage<T> storage, Callable<? extends T> factory)
|
||||
Capability(String name)
|
||||
{
|
||||
this.name = name;
|
||||
this.storage = storage;
|
||||
this.factory = factory;
|
||||
}
|
||||
}
|
||||
@@ -27,11 +27,11 @@ import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
@@ -47,10 +47,10 @@ import net.minecraftforge.common.util.LazyOptional;
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
public final class CapabilityDispatcher implements INBTSerializable<CompoundNBT>, ICapabilityProvider
|
||||
public final class CapabilityDispatcher implements INBTSerializable<CompoundTag>, ICapabilityProvider
|
||||
{
|
||||
private ICapabilityProvider[] caps;
|
||||
private INBTSerializable<INBT>[] writers;
|
||||
private INBTSerializable<Tag>[] writers;
|
||||
private String[] names;
|
||||
private final List<Runnable> listeners;
|
||||
|
||||
@@ -63,7 +63,7 @@ public final class CapabilityDispatcher implements INBTSerializable<CompoundNBT>
|
||||
public CapabilityDispatcher(Map<ResourceLocation, ICapabilityProvider> list, List<Runnable> listeners, @Nullable ICapabilityProvider parent)
|
||||
{
|
||||
List<ICapabilityProvider> lstCaps = Lists.newArrayList();
|
||||
List<INBTSerializable<INBT>> lstWriters = Lists.newArrayList();
|
||||
List<INBTSerializable<Tag>> lstWriters = Lists.newArrayList();
|
||||
List<String> lstNames = Lists.newArrayList();
|
||||
this.listeners = listeners;
|
||||
|
||||
@@ -72,7 +72,7 @@ public final class CapabilityDispatcher implements INBTSerializable<CompoundNBT>
|
||||
lstCaps.add(parent);
|
||||
if (parent instanceof INBTSerializable)
|
||||
{
|
||||
lstWriters.add((INBTSerializable<INBT>)parent);
|
||||
lstWriters.add((INBTSerializable<Tag>)parent);
|
||||
lstNames.add("Parent");
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public final class CapabilityDispatcher implements INBTSerializable<CompoundNBT>
|
||||
lstCaps.add(prov);
|
||||
if (prov instanceof INBTSerializable)
|
||||
{
|
||||
lstWriters.add((INBTSerializable<INBT>)prov);
|
||||
lstWriters.add((INBTSerializable<Tag>)prov);
|
||||
lstNames.add(entry.getKey().toString());
|
||||
}
|
||||
}
|
||||
@@ -119,9 +119,9 @@ public final class CapabilityDispatcher implements INBTSerializable<CompoundNBT>
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT serializeNBT()
|
||||
public CompoundTag serializeNBT()
|
||||
{
|
||||
CompoundNBT nbt = new CompoundNBT();
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
for (int x = 0; x < writers.length; x++)
|
||||
{
|
||||
nbt.put(names[x], writers[x].serializeNBT());
|
||||
@@ -130,7 +130,7 @@ public final class CapabilityDispatcher implements INBTSerializable<CompoundNBT>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundNBT nbt)
|
||||
public void deserializeNBT(CompoundTag nbt)
|
||||
{
|
||||
for (int x = 0; x < writers.length; x++)
|
||||
{
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import net.minecraftforge.forgespi.language.ModFileScanData;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -53,15 +52,11 @@ public enum CapabilityManager
|
||||
* To retrieve the Capability instance, use the @CapabilityInject annotation.
|
||||
* This method is safe to call during parallel mod loading.
|
||||
*
|
||||
* @param type The Interface to be registered
|
||||
* @param storage A default implementation of the storage handler.
|
||||
* @param factory A Factory that will produce new instances of the default implementation.
|
||||
* @param type The class type to be registered
|
||||
*/
|
||||
public <T> void register(Class<T> type, Capability.IStorage<T> storage, Callable<? extends T> factory)
|
||||
public <T> void register(Class<T> type)
|
||||
{
|
||||
Objects.requireNonNull(type,"Attempted to register a capability with invalid type");
|
||||
Objects.requireNonNull(storage,"Attempted to register a capability with no storage implementation");
|
||||
Objects.requireNonNull(factory,"Attempted to register a capability with no default implementation factory");
|
||||
String realName = type.getName().intern();
|
||||
Capability<T> cap;
|
||||
|
||||
@@ -72,7 +67,7 @@ public enum CapabilityManager
|
||||
throw new IllegalArgumentException("Cannot register a capability implementation multiple times : "+ realName);
|
||||
}
|
||||
|
||||
cap = new Capability<>(realName, storage, factory);
|
||||
cap = new Capability<>(realName);
|
||||
providers.put(realName, cap);
|
||||
}
|
||||
|
||||
@@ -87,7 +82,7 @@ public enum CapabilityManager
|
||||
final List<ModFileScanData.AnnotationData> capabilities = data.stream()
|
||||
.map(ModFileScanData::getAnnotations)
|
||||
.flatMap(Collection::stream)
|
||||
.filter(a -> CAP_INJECT.equals(a.getAnnotationType()))
|
||||
.filter(a -> CAP_INJECT.equals(a.annotationType()))
|
||||
.collect(Collectors.toList());
|
||||
final IdentityHashMap<String, List<Function<Capability<?>, Object>>> m = new IdentityHashMap<>();
|
||||
capabilities.forEach(entry -> attachCapabilityToMethod(m, entry));
|
||||
@@ -96,9 +91,9 @@ public enum CapabilityManager
|
||||
|
||||
private static void attachCapabilityToMethod(Map<String, List<Function<Capability<?>, Object>>> cbs, ModFileScanData.AnnotationData entry)
|
||||
{
|
||||
final String targetClass = entry.getClassType().getClassName();
|
||||
final String targetName = entry.getMemberName();
|
||||
Type type = (Type)entry.getAnnotationData().get("value");
|
||||
final String targetClass = entry.clazz().getClassName();
|
||||
final String targetName = entry.memberName();
|
||||
Type type = (Type)entry.annotationData().get("value");
|
||||
if (type == null)
|
||||
{
|
||||
LOGGER.warn(CAPABILITIES,"Unable to inject capability at {}.{} (Invalid Annotation)", targetClass, targetName);
|
||||
@@ -108,7 +103,7 @@ public enum CapabilityManager
|
||||
|
||||
List<Function<Capability<?>, Object>> list = cbs.computeIfAbsent(capabilityName, k -> new ArrayList<>());
|
||||
|
||||
if (entry.getMemberName().indexOf('(') > 0)
|
||||
if (entry.memberName().indexOf('(') > 0)
|
||||
{
|
||||
list.add(input -> {
|
||||
try
|
||||
|
||||
@@ -22,9 +22,9 @@ package net.minecraftforge.common.capabilities;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
|
||||
@@ -78,7 +78,7 @@ public abstract class CapabilityProvider<B extends CapabilityProvider<B>> implem
|
||||
}
|
||||
}
|
||||
|
||||
protected final @Nullable CompoundNBT serializeCaps()
|
||||
protected final @Nullable CompoundTag serializeCaps()
|
||||
{
|
||||
final CapabilityDispatcher disp = getCapabilities();
|
||||
if (disp != null)
|
||||
@@ -88,7 +88,7 @@ public abstract class CapabilityProvider<B extends CapabilityProvider<B>> implem
|
||||
return null;
|
||||
}
|
||||
|
||||
protected final void deserializeCaps(CompoundNBT tag)
|
||||
protected final void deserializeCaps(CompoundTag tag)
|
||||
{
|
||||
final CapabilityDispatcher disp = getCapabilities();
|
||||
if (disp != null)
|
||||
|
||||
@@ -22,7 +22,7 @@ package net.minecraftforge.common.capabilities;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
public interface ICapabilityProvider
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
package net.minecraftforge.common.capabilities;
|
||||
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
|
||||
//Just a mix of the two, useful in patches to lower the size.
|
||||
public interface ICapabilitySerializable<T extends INBT> extends ICapabilityProvider, INBTSerializable<T>{}
|
||||
public interface ICapabilitySerializable<T extends Tag> extends ICapabilityProvider, INBTSerializable<T>{}
|
||||
Reference in new issue
Block a user