Skip to content

Commit

Permalink
NeoForge - 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Aug 11, 2024
1 parent 9084023 commit 916909a
Show file tree
Hide file tree
Showing 170 changed files with 10,778 additions and 1,758 deletions.
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<h1>MohistNeo 1.21</h1>
<h1>Youer 1.21.1</h1>

### Minecraft NeoForge Hybrid server implementing the Spigot/Bukkit API, formerly known as Thermos/Cauldron/MCPC+
### Minecraft NeoForge Hybrid server implementing the Spigot/Bukkit API

[![](https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fci.codemc.io%2Fjob%2FMohistMC%2Fjob%2FMohist-1.20.1)](https://ci.codemc.io/job/MohistMC/job/Mohist-1.20.1)
[![](https://img.shields.io/github/stars/MohistMC/Mohist.svg?label=Stars&logo=github)](https://github.com/MohistMC/Mohist/stargazers)
Expand All @@ -18,7 +18,7 @@
Progress
------

- [x] Rectify NeoForge([**0e7ecfce**](https://github.com/neoforged/NeoForge/commit/0e7ecfce))
- [x] Rectify NeoForge([**4c6f3a4418**](https://github.com/neoforged/NeoForge/commit/4c6f3a4418))
- [ ] Start patch
* [x] Bukkit([**69fa4695**](https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/69fa4695))
* [ ] CraftBukkit([**661afb43c**](https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/commits/661afb43c))
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ org.gradle.debug=false

java_version=21

minecraft_version=1.21
neoform_version=20240613.152323
minecraft_version=1.21.1
neoform_version=20240808.144430
# on snapshot versions, used to prefix the version
neoforge_snapshot_next_stable=22.0

mergetool_version=2.0.0
accesstransformers_version=10.0.1
coremods_version=6.0.4
eventbus_version=8.0.1
modlauncher_version=11.0.2
modlauncher_version=11.0.4
securejarhandler_version=3.0.8
bootstraplauncher_version=2.0.2
asm_version=9.5
installer_version=2.1.+
mixin_version=0.13.4+mixin.0.8.5
terminalconsoleappender_version=1.2.0
mixin_version=0.14.0+mixin.0.8.6
terminalconsoleappender_version=1.3.0
jline_version=3.12.+
nightconfig_version=3.6.4
nightconfig_version=3.8.0
jetbrains_annotations_version=24.0.1
slf4j_api_version=2.0.7
apache_maven_artifact_version=3.8.5
jarjar_version=0.4.1
fancy_mod_loader_version=4.0.6
fancy_mod_loader_version=4.0.24
mojang_logging_version=1.1.1
log4j_version=2.22.1
guava_version=31.1.2-jre
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package net.neoforged.neoforge.capabilities;

import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;

/**
* Base class to reuse code common between most/all {@code *Capability} implementation.
Expand All @@ -18,7 +19,7 @@
* @param <T> Type of queried objects.
* @param <C> Type of the additional context.
*/
public abstract class BaseCapability<T, C> {
public abstract class BaseCapability<T, C extends @Nullable Object> {
private final ResourceLocation name;
private final Class<T> typeClass;
private final Class<C> contextClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@
* @param <T> type of queried objects
* @param <C> type of the additional context
*/
public final class BlockCapability<T, C> extends BaseCapability<T, C> {
public final class BlockCapability<T, C extends @Nullable Object> extends BaseCapability<T, C> {
/**
* Creates a new block capability, or gets it if it already exists.
*
* @param name name of the capability
* @param typeClass type of the queried API
* @param contextClass type of the additional context
*/
public static <T, C> BlockCapability<T, C> create(ResourceLocation name, Class<T> typeClass, Class<C> contextClass) {
public static <T, C extends @Nullable Object> BlockCapability<T, C> create(ResourceLocation name, Class<T> typeClass, Class<C> contextClass) {
return (BlockCapability<T, C>) registry.create(name, typeClass, contextClass);
}

Expand All @@ -107,7 +107,7 @@ public static <T, C> BlockCapability<T, C> create(ResourceLocation name, Class<T
*
* @see #create(ResourceLocation, Class, Class)
*/
public static <T> BlockCapability<T, Void> createVoid(ResourceLocation name, Class<T> typeClass) {
public static <T> BlockCapability<T, @Nullable Void> createVoid(ResourceLocation name, Class<T> typeClass) {
return create(name, typeClass, void.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* <p>Instances are automatically cleared by the garbage collector when they are no longer in use.
*/
public final class BlockCapabilityCache<T, C> {
public final class BlockCapabilityCache<T, C extends @Nullable Object> {
/**
* Creates a new cache instance and registers it to the level.
*
Expand All @@ -28,7 +28,7 @@ public final class BlockCapabilityCache<T, C> {
* @param pos the position
* @param context extra context for the query
*/
public static <T, C> BlockCapabilityCache<T, C> create(BlockCapability<T, C> capability, ServerLevel level, BlockPos pos, C context) {
public static <T, C extends @Nullable Object> BlockCapabilityCache<T, C> create(BlockCapability<T, C> capability, ServerLevel level, BlockPos pos, C context) {
return create(capability, level, pos, context, () -> true, () -> {});
}

Expand Down Expand Up @@ -56,7 +56,7 @@ public static <T, C> BlockCapabilityCache<T, C> create(BlockCapability<T, C> cap
* that should not receive invalidation notifications anymore once it is removed.
* @param invalidationListener the invalidation listener. Will be called whenever the capability of the cache might have changed.
*/
public static <T, C> BlockCapabilityCache<T, C> create(BlockCapability<T, C> capability, ServerLevel level, BlockPos pos, C context, BooleanSupplier isValid, Runnable invalidationListener) {
public static <T, C extends @Nullable Object> BlockCapabilityCache<T, C> create(BlockCapability<T, C> capability, ServerLevel level, BlockPos pos, C context, BooleanSupplier isValid, Runnable invalidationListener) {
Objects.requireNonNull(capability);
Objects.requireNonNull(isValid);
Objects.requireNonNull(invalidationListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public final class Capabilities {
public static final class EnergyStorage {
public static final BlockCapability<IEnergyStorage, @Nullable Direction> BLOCK = BlockCapability.createSided(create("energy"), IEnergyStorage.class);
public static final EntityCapability<IEnergyStorage, @Nullable Direction> ENTITY = EntityCapability.createSided(create("energy"), IEnergyStorage.class);
public static final ItemCapability<IEnergyStorage, Void> ITEM = ItemCapability.createVoid(create("energy"), IEnergyStorage.class);
public static final ItemCapability<IEnergyStorage, @Nullable Void> ITEM = ItemCapability.createVoid(create("energy"), IEnergyStorage.class);

private EnergyStorage() {}
}

public static final class FluidHandler {
public static final BlockCapability<IFluidHandler, @Nullable Direction> BLOCK = BlockCapability.createSided(create("fluid_handler"), IFluidHandler.class);
public static final EntityCapability<IFluidHandler, @Nullable Direction> ENTITY = EntityCapability.createSided(create("fluid_handler"), IFluidHandler.class);
public static final ItemCapability<IFluidHandlerItem, Void> ITEM = ItemCapability.createVoid(create("fluid_handler"), IFluidHandlerItem.class);
public static final ItemCapability<IFluidHandlerItem, @Nullable Void> ITEM = ItemCapability.createVoid(create("fluid_handler"), IFluidHandlerItem.class);

private FluidHandler() {}
}
Expand All @@ -39,13 +39,13 @@ public static final class ItemHandler {
* Capability for the inventory of an entity.
* If an entity has multiple inventory "subparts", this capability should give a combined view of all the subparts.
*/
public static final EntityCapability<IItemHandler, Void> ENTITY = EntityCapability.createVoid(create("item_handler"), IItemHandler.class);
public static final EntityCapability<IItemHandler, @Nullable Void> ENTITY = EntityCapability.createVoid(create("item_handler"), IItemHandler.class);
/**
* Capability for an inventory of entity that should be accessible to automation,
* in the sense that droppers, hoppers, and similar modded devices will try to use it.
*/
public static final EntityCapability<IItemHandler, @Nullable Direction> ENTITY_AUTOMATION = EntityCapability.createSided(create("item_handler_automation"), IItemHandler.class);
public static final ItemCapability<IItemHandler, Void> ITEM = ItemCapability.createVoid(create("item_handler"), IItemHandler.class);
public static final ItemCapability<IItemHandler, @Nullable Void> ITEM = ItemCapability.createVoid(create("item_handler"), IItemHandler.class);

private ItemHandler() {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,8 @@ public static void registerVanillaProviders(RegisterCapabilitiesEvent event) {
event.registerEntity(Capabilities.ItemHandler.ENTITY_AUTOMATION, entityType, (entity, ctx) -> new InvWrapper(entity));
}
event.registerEntity(Capabilities.ItemHandler.ENTITY, EntityType.PLAYER, (player, ctx) -> new PlayerInvWrapper(player.getInventory()));
// Register to all entity types to make sure we support all living entity subclasses.
for (EntityType<?> entityType : BuiltInRegistries.ENTITY_TYPE) {
event.registerEntity(Capabilities.ItemHandler.ENTITY, entityType, (entity, ctx) -> {
if (entity instanceof AbstractHorse horse)
return new InvWrapper(horse.getInventory());
else if (entity instanceof LivingEntity livingEntity)
return new CombinedInvWrapper(new EntityHandsInvWrapper(livingEntity), new EntityArmorInvWrapper(livingEntity));

return null;
});
}

// Items
for (Item item : BuiltInRegistries.ITEM) {
if (item.getClass() == BucketItem.class)
event.registerItem(Capabilities.FluidHandler.ITEM, (stack, ctx) -> new FluidBucketWrapper(stack), item);
}
if (NeoForgeMod.MILK.isBound()) {
event.registerItem(Capabilities.FluidHandler.ITEM, (stack, ctx) -> new FluidBucketWrapper(stack), Items.MILK_BUCKET);
}
event.registerItem(Capabilities.ItemHandler.ITEM, (stack, ctx) -> new ComponentItemHandler(stack, DataComponents.CONTAINER, 27),
Items.SHULKER_BOX,
Items.BLACK_SHULKER_BOX,
Expand All @@ -152,6 +134,32 @@ else if (entity instanceof LivingEntity livingEntity)
Items.YELLOW_SHULKER_BOX);
}

public static void registerFallbackVanillaProviders(RegisterCapabilitiesEvent event) {
// Entities
// Register to all entity types to make sure we support all living entity subclasses.
for (EntityType<?> entityType : BuiltInRegistries.ENTITY_TYPE) {
event.registerEntity(Capabilities.ItemHandler.ENTITY, entityType, (entity, ctx) -> {
if (entity instanceof AbstractHorse horse)
return new InvWrapper(horse.getInventory());
else if (entity instanceof LivingEntity livingEntity)
return new CombinedInvWrapper(new EntityHandsInvWrapper(livingEntity), new EntityArmorInvWrapper(livingEntity));

return null;
});
}

// Items
for (Item item : BuiltInRegistries.ITEM) {
if (item.getClass() == BucketItem.class)
event.registerItem(Capabilities.FluidHandler.ITEM, (stack, ctx) -> new FluidBucketWrapper(stack), item);
}

// We want mods to be able to override our milk cap by default
if (NeoForgeMod.MILK.isBound()) {
event.registerItem(Capabilities.FluidHandler.ITEM, (stack, ctx) -> new FluidBucketWrapper(stack), Items.MILK_BUCKET);
}
}

public static void invalidateCapsOnChunkLoad(ChunkEvent.Load event) {
if (event.getLevel() instanceof ServerLevel sl) {
sl.invalidateCapabilities(event.getChunk().getPos());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
* @param <T> type of queried objects
* @param <C> type of the additional context
*/
public final class EntityCapability<T, C> extends BaseCapability<T, C> {
public final class EntityCapability<T, C extends @Nullable Object> extends BaseCapability<T, C> {
/**
* Creates a new entity capability, or gets it if it already exists.
*
* @param name name of the capability
* @param typeClass type of the queried API
* @param contextClass type of the additional context
*/
public static <T, C> EntityCapability<T, C> create(ResourceLocation name, Class<T> typeClass, Class<C> contextClass) {
public static <T, C extends @Nullable Object> EntityCapability<T, C> create(ResourceLocation name, Class<T> typeClass, Class<C> contextClass) {
return (EntityCapability<T, C>) registry.create(name, typeClass, contextClass);
}

Expand All @@ -64,7 +64,7 @@ public static <T, C> EntityCapability<T, C> create(ResourceLocation name, Class<
*
* @see #create(ResourceLocation, Class, Class)
*/
public static <T> EntityCapability<T, Void> createVoid(ResourceLocation name, Class<T> typeClass) {
public static <T> EntityCapability<T, @Nullable Void> createVoid(ResourceLocation name, Class<T> typeClass) {
return create(name, typeClass, void.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.jetbrains.annotations.Nullable;

@FunctionalInterface
public interface IBlockCapabilityProvider<T, C> {
public interface IBlockCapabilityProvider<T, C extends @Nullable Object> {
/**
* Returns the capability, or {@code null} if not available.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.jetbrains.annotations.Nullable;

@FunctionalInterface
public interface ICapabilityProvider<O, C, T> {
public interface ICapabilityProvider<O, C extends @Nullable Object, T> {
/**
* Returns the capability, or {@code null} if not available.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
* @param <T> type of queried objects
* @param <C> type of the additional context
*/
public final class ItemCapability<T, C> extends BaseCapability<T, C> {
public final class ItemCapability<T, C extends @Nullable Object> extends BaseCapability<T, C> {
/**
* Creates a new item capability, or gets it if it already exists.
*
* @param name name of the capability
* @param typeClass type of the queried API
* @param contextClass type of the additional context
*/
public static <T, C> ItemCapability<T, C> create(ResourceLocation name, Class<T> typeClass, Class<C> contextClass) {
public static <T, C extends @Nullable Object> ItemCapability<T, C> create(ResourceLocation name, Class<T> typeClass, Class<C> contextClass) {
return (ItemCapability<T, C>) registry.create(name, typeClass, contextClass);
}

Expand All @@ -63,7 +63,7 @@ public static <T, C> ItemCapability<T, C> create(ResourceLocation name, Class<T>
*
* @see #create(ResourceLocation, Class, Class)
*/
public static <T> ItemCapability<T, Void> createVoid(ResourceLocation name, Class<T> typeClass) {
public static <T> ItemCapability<T, @Nullable Void> createVoid(ResourceLocation name, Class<T> typeClass) {
return create(name, typeClass, void.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.neoforged.bus.api.Event;
import net.neoforged.fml.event.IModBusEvent;
import org.jetbrains.annotations.Nullable;

/**
* Fired to register capability providers at an appropriate time.
Expand All @@ -35,7 +36,7 @@ public class RegisterCapabilitiesEvent extends Event implements IModBusEvent {
* {@link Level#invalidateCapabilities(BlockPos)} MUST be called to notify the caches.</b>
* See {@link IBlockCapabilityProvider} for details.
*/
public <T, C> void registerBlock(BlockCapability<T, C> capability, IBlockCapabilityProvider<T, C> provider, Block... blocks) {
public <T, C extends @Nullable Object> void registerBlock(BlockCapability<T, C> capability, IBlockCapabilityProvider<T, C> provider, Block... blocks) {
Objects.requireNonNull(provider);
// Probably a programmer error
if (blocks.length == 0)
Expand All @@ -54,7 +55,7 @@ public <T, C> void registerBlock(BlockCapability<T, C> capability, IBlockCapabil
* {@link Level#invalidateCapabilities(BlockPos)} MUST be called to notify the caches.</b>
* See {@link IBlockCapabilityProvider} for details.
*/
public <T, C, BE extends BlockEntity> void registerBlockEntity(BlockCapability<T, C> capability, BlockEntityType<BE> blockEntityType, ICapabilityProvider<? super BE, C, T> provider) {
public <T, C extends @Nullable Object, BE extends BlockEntity> void registerBlockEntity(BlockCapability<T, C> capability, BlockEntityType<BE> blockEntityType, ICapabilityProvider<? super BE, C, T> provider) {
Objects.requireNonNull(provider);

IBlockCapabilityProvider<T, C> adaptedProvider = (level, pos, state, blockEntity, context) -> {
Expand Down Expand Up @@ -83,7 +84,7 @@ public boolean isBlockRegistered(BlockCapability<?, ?> capability, Block block)
/**
* Register a capability provider for some entity type.
*/
public <T, C, E extends Entity> void registerEntity(EntityCapability<T, C> capability, EntityType<E> entityType, ICapabilityProvider<? super E, C, T> provider) {
public <T, C extends @Nullable Object, E extends Entity> void registerEntity(EntityCapability<T, C> capability, EntityType<E> entityType, ICapabilityProvider<? super E, C, T> provider) {
Objects.requireNonNull(provider);
capability.providers.computeIfAbsent(entityType, et -> new ArrayList<>()).add((ICapabilityProvider<Entity, C, T>) provider);
}
Expand All @@ -101,7 +102,7 @@ public boolean isEntityRegistered(EntityCapability<?, ?> capability, EntityType<
/**
* Register a capability provider for some items.
*/
public <T, C> void registerItem(ItemCapability<T, C> capability, ICapabilityProvider<ItemStack, C, T> provider, ItemLike... items) {
public <T, C extends @Nullable Object> void registerItem(ItemCapability<T, C> capability, ICapabilityProvider<ItemStack, C, T> provider, ItemLike... items) {
Objects.requireNonNull(provider);
// Probably a programmer error
if (items.length == 0)
Expand Down
Loading

0 comments on commit 916909a

Please sign in to comment.