Skip to content

Commit

Permalink
feat(1.21.2): Update NeoForge to Minecraft 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Oct 22, 2024
1 parent da7a04b commit 4a7d404
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 108 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'fabric-loom' version '1.7-SNAPSHOT' apply(false)
id 'net.neoforged.moddev' version '0.1.110' apply(false)
id 'net.neoforged.moddev' version '1.0.21' apply(false)
id 'net.darkhax.curseforgegradle' version '1.1.18' apply(false)
id "com.modrinth.minotaur" version "2.+" apply(false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.blay09.mods.balm.api.event.BalmEvent;
import net.minecraft.client.multiplayer.ClientRecipeContainer;

@Deprecated
public class RecipesUpdatedEvent extends BalmEvent {
private final ClientRecipeContainer clientRecipeContainer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public DeferredObject<Block> registerBlock(Function<ResourceLocation, Block> sup

@Override
public DeferredObject<Item> registerBlockItem(Function<ResourceLocation, BlockItem> supplier, ResourceLocation identifier, @Nullable ResourceLocation creativeTab) {
return Balm.getItems().registerItem(() -> supplier.apply(identifier), identifier, creativeTab);
return Balm.getItems().registerItem(supplier::apply, identifier, creativeTab);
}

@Override
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion fabric/src/main/resources/balm.fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"AbstractContainerScreenMixin",
"ChatComponentMixin",
"CheckboxAccessor",
"ClientPacketListenerMixin",
"EntityModelSetAccessor",
"EntityModelSetMixin",
"GuiMixin",
Expand Down
22 changes: 11 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ modrinth_release_type = release
modrinth_project_id = MBAkmtvl

# Minecraft
minecraft_version = 1.21.2-pre1
minimum_minecraft_version = 1.21
minecraft_versions = 1.21,1.21.1,1.21.2-pre1
minecraft_version_range = [1.21,)
minecraft_version = 1.21.2
minimum_minecraft_version = 1.21.2
minecraft_versions = 1.21,1.21.1,1.21.2
minecraft_version_range = [1.21.2,)
pack_format_number = 18
java_version = 21

# NeoForm and Parchment
neo_form_version=1.21.2-pre1-20241008.174159
neo_form_version=1.21.2-20241022.151510
parchment_minecraft=1.21
parchment_version=2024.06.23
parchment_version=2024.07.28

# Forge
forge_version = 52.0.18
Expand All @@ -38,16 +38,16 @@ forge_loader_version_range = [51,)

# NeoForge
neoforge_snapshot_url=
neoforge_version = 21.1.8
neoforge_version_range = [21.0.82-beta,)
neoforge_version = 21.2.0-beta
neoforge_version_range = [21.2.0-beta,)
neoforge_loader_version_range = [1,)

# Fabric
fabric_version = 0.105.3+1.21.2
fabric_loader_version = 0.16.5
fabric_version = 0.106.1+1.21.2
fabric_loader_version = 0.16.7

# Dependencies
kuma_version = [21.0,22)
kuma_version = [21.2,22)
jei_minecraft_version = 1.19.2
jei_version = 11.4.0.288
rei_version = 10.0.581
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.phys.BlockHitResult;
import net.neoforged.neoforge.common.EffectCures;
import net.neoforged.neoforge.common.ItemAbilities;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.common.util.FakePlayer;
Expand Down Expand Up @@ -84,11 +82,7 @@ public CompoundTag getPersistentData(Entity entity) {

@Override
public void curePotionEffects(LivingEntity entity, ItemStack curativeItem) {
if (curativeItem.getItem() == Items.MILK_BUCKET) {
entity.removeEffectsCuredBy(EffectCures.MILK);
} else if (curativeItem.getItem() == Items.HONEY_BOTTLE) {
entity.removeEffectsCuredBy(EffectCures.HONEY);
}
entity.removeAllEffects();
}

@Override
Expand All @@ -98,7 +92,7 @@ public boolean isFakePlayer(Player player) {

@Override
public ItemStack getCraftingRemainingItem(ItemStack itemStack) {
return itemStack.getCraftingRemainingItem();
return itemStack.getCraftingRemainder();
}

@Override
Expand All @@ -112,8 +106,8 @@ public boolean canItemsStack(ItemStack first, ItemStack second) {
}

@Override
public int getBurnTime(ItemStack itemStack) {
return itemStack.getBurnTime(RecipeType.SMELTING);
public int getBurnTime(Level level, ItemStack itemStack) {
return level.fuelValues().burnDuration(itemStack);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ public Collection<ResourceLocation> getItemKeys() {

@Override
public Item getItem(ResourceLocation key) {
return BuiltInRegistries.ITEM.get(key);
return BuiltInRegistries.ITEM.getValue(key);
}

@Override
public Block getBlock(ResourceLocation key) {
return BuiltInRegistries.BLOCK.get(key);
return BuiltInRegistries.BLOCK.getValue(key);
}

@Override
public Fluid getFluid(ResourceLocation key) {
return BuiltInRegistries.FLUID.get(key);
return BuiltInRegistries.FLUID.getValue(key);
}

@Override
public MobEffect getMobEffect(ResourceLocation key) {
return BuiltInRegistries.MOB_EFFECT.get(key);
return BuiltInRegistries.MOB_EFFECT.getValue(key);
}

@Override
Expand All @@ -84,6 +84,6 @@ public Fluid getMilkFluid() {

@Override
public Attribute getAttribute(ResourceLocation key) {
return BuiltInRegistries.ATTRIBUTE.get(key);
return BuiltInRegistries.ATTRIBUTE.getValue(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import net.blay09.mods.balm.neoforge.sound.NeoForgeBalmSounds;
import net.blay09.mods.balm.neoforge.stats.NeoForgeBalmStats;
import net.blay09.mods.balm.neoforge.world.NeoForgeBalmWorldGen;
import net.minecraft.core.HolderLookup;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.PreparableReloadListener;
import net.minecraft.server.packs.resources.ResourceManager;
Expand All @@ -52,6 +53,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

public class NeoForgeBalmRuntime implements BalmRuntime<NeoForgeLoadContext> {
private final BalmWorldGen worldGen = new NeoForgeBalmWorldGen();
Expand Down Expand Up @@ -222,8 +224,8 @@ private void initializeAddons() {
}

@Override
public void addServerReloadListener(ResourceLocation identifier, PreparableReloadListener reloadListener) {
NeoForge.EVENT_BUS.addListener((AddReloadListenerEvent event) -> event.addListener(reloadListener));
public void addServerReloadListener(ResourceLocation identifier, Function<HolderLookup.Provider, PreparableReloadListener> reloadListener) {
NeoForge.EVENT_BUS.addListener((AddReloadListenerEvent event) -> event.addListener(reloadListener.apply(event.getRegistryAccess())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,28 @@
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import org.jetbrains.annotations.Nullable;

import java.util.function.Supplier;
import java.util.function.BiFunction;
import java.util.function.Function;

public class NeoForgeBalmBlocks implements BalmBlocks {
@Override
public BlockBehaviour.Properties blockProperties() {
return BlockBehaviour.Properties.of();
}

@Override
public DeferredObject<Block> registerBlock(Supplier<Block> supplier, ResourceLocation identifier) {
public DeferredObject<Block> registerBlock(Function<ResourceLocation, Block> supplier, ResourceLocation identifier) {
final var register = DeferredRegisters.get(Registries.BLOCK, identifier.getNamespace());
final var registryObject = register.register(identifier.getPath(), supplier);
return new DeferredObject<>(identifier, registryObject, registryObject::isBound);
}

@Override
public DeferredObject<Item> registerBlockItem(Supplier<BlockItem> supplier, ResourceLocation identifier, @Nullable ResourceLocation creativeTab) {
return Balm.getItems().registerItem(supplier::get, identifier, creativeTab);
public DeferredObject<Item> registerBlockItem(Function<ResourceLocation, BlockItem> supplier, ResourceLocation identifier, @Nullable ResourceLocation creativeTab) {
return Balm.getItems().registerItem(supplier::apply, identifier, creativeTab);
}

@Override
public void register(Supplier<Block> blockSupplier, Supplier<BlockItem> blockItemSupplier, ResourceLocation identifier, @Nullable ResourceLocation creativeTab) {
registerBlock(blockSupplier, identifier);
registerBlockItem(blockItemSupplier, identifier, creativeTab);
public void register(Function<ResourceLocation, Block> blockSupplier, BiFunction<Block, ResourceLocation, BlockItem> blockItemSupplier, ResourceLocation identifier, @Nullable ResourceLocation creativeTab) {
final var deferredBlock = registerBlock(blockSupplier, identifier);
registerBlockItem((id) -> blockItemSupplier.apply(deferredBlock.get(), id), identifier, creativeTab);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.neoforged.neoforge.registries.DeferredRegister;

import java.util.Arrays;
import java.util.function.Supplier;
Expand All @@ -20,7 +19,7 @@ public <T extends BlockEntity> DeferredObject<BlockEntityType<T>> registerBlockE
final var register = DeferredRegisters.get(Registries.BLOCK_ENTITY_TYPE, identifier.getNamespace());
final var registryObject = register.register(identifier.getPath(), () -> {
Block[] resolvedBlocks = blocks.get();
return BlockEntityType.Builder.of(factory::create, resolvedBlocks).build(null);
return new BlockEntityType<>(factory::create, resolvedBlocks);
});
return new DeferredObject<>(identifier, registryObject, registryObject::isBound);
}
Expand All @@ -30,7 +29,7 @@ public <T extends BlockEntity> DeferredObject<BlockEntityType<T>> registerBlockE
final var register = DeferredRegisters.get(Registries.BLOCK_ENTITY_TYPE, identifier.getNamespace());
final var registryObject = register.register(identifier.getPath(), () -> {
Block[] resolvedBlocks = Arrays.stream(blocks).map(DeferredObject::get).toArray(Block[]::new);
return BlockEntityType.Builder.of(factory::create, resolvedBlocks).build(null);
return new BlockEntityType<>(factory::create, resolvedBlocks);
});
return new DeferredObject<>(identifier, registryObject, registryObject::isBound);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void resolveAndSet(ModelBakery modelBakery, Map<ModelResourceLocation, Ba
set(resolve(modelBakery, modelRegistry, textureGetter));
} catch (Exception exception) {
LOGGER.warn("Unable to bake model: '{}':", getIdentifier(), exception);
set(modelBakery.getBakedTopLevelModels().get(ModelBakery.MISSING_MODEL_LOCATION));
set(modelBakery.getBakedTopLevelModels().get(MissingBlockModel.VARIANT));
}
}

Expand Down Expand Up @@ -157,7 +157,7 @@ public DeferredObject<BakedModel> loadDynamicModel(ModelResourceLocation identif
public BakedModel resolve(ModelBakery bakery, Map<ModelResourceLocation, BakedModel> modelRegistry, ModelBakery.TextureGetter textureGetter) {
final var unbakedModels = new HashMap<ModelResourceLocation, UnbakedModel>();
for (final var modelId : models) {
unbakedModels.put(modelId, ((ModelBakeryAccessor) bakery).callGetModel(modelId.id()));
unbakedModels.put(modelId, getUnbakedModelOrMissing(modelId.id()));
}
return new NeoForgeCachedDynamicModel(bakery,
unbakedModels,
Expand Down Expand Up @@ -186,12 +186,12 @@ public ModelState getModelState(Transformation transformation) {

@Override
public UnbakedModel getUnbakedModelOrMissing(ResourceLocation location) {
return ((ModelBakeryAccessor) modelBakery).callGetModel(location);
return ((ModelBakeryAccessor) modelBakery).getUnbakedModels().getOrDefault(location, ((ModelBakeryAccessor) modelBakery).getMissingModel());
}

@Override
public UnbakedModel getUnbakedMissingModel() {
return ((ModelBakeryAccessor) modelBakery).callGetModel(ModelBakery.MISSING_MODEL_LOCATION);
return ((ModelBakeryAccessor) modelBakery).getMissingModel();
}

public void register(String modId, IEventBus eventBus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ public List<RenderType> getItemRenderTypes(ItemStack itemStack, boolean fabulous
return renderTypes;
}

@Override
public List<RenderType> getRenderTypes(ItemStack itemStack, boolean fabulous) {
List<RenderType> result = getItemRenderTypes(itemStack, fabulous);
if (result.isEmpty()) {
return super.getRenderTypes(itemStack, fabulous);
}
return result;
}

@Override
public List<RenderType> getBlockRenderTypes(BlockState state, RandomSource rand) {
return renderTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.blay09.mods.balm.api.entity.BalmEntities;
import net.blay09.mods.balm.neoforge.DeferredRegisters;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
Expand Down Expand Up @@ -38,7 +39,7 @@ public void registerAttributes(EntityAttributeCreationEvent event) {
@Override
public <T extends Entity> DeferredObject<EntityType<T>> registerEntity(ResourceLocation identifier, EntityType.Builder<T> typeBuilder) {
final var register = DeferredRegisters.get(Registries.ENTITY_TYPE, identifier.getNamespace());
final var registryObject = register.register(identifier.getPath(), () -> typeBuilder.build(identifier.toString()));
final var registryObject = register.register(identifier.getPath(), () -> typeBuilder.build(ResourceKey.create(Registries.ENTITY_TYPE, identifier)));
return new DeferredObject<>(identifier, registryObject, registryObject::isBound);
}

Expand All @@ -47,7 +48,7 @@ public <T extends LivingEntity> DeferredObject<EntityType<T>> registerEntity(Res
final var register = DeferredRegisters.get(Registries.ENTITY_TYPE, identifier.getNamespace());
final var registrations = getActiveRegistrations();
final var registryObject = register.register(identifier.getPath(), () -> {
EntityType<T> entityType = typeBuilder.build(identifier.toString());
EntityType<T> entityType = typeBuilder.build(ResourceKey.create(Registries.ENTITY_TYPE, identifier));
registrations.attributeSuppliers.put(entityType, attributeBuilder.get().build());
return entityType;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,6 @@ public static void registerEvents(NeoForgeBalmEvents events) {
});
});

events.registerEvent(RecipesUpdatedEvent.class, priority -> {
NeoForge.EVENT_BUS.addListener(NeoForgeBalmEvents.toForge(priority), (net.neoforged.neoforge.client.event.RecipesUpdatedEvent orig) -> {
RegistryAccess registryAccess = Minecraft.getInstance().level.registryAccess(); // same way that Minecraft does it in the packet handler
final RecipesUpdatedEvent event = new RecipesUpdatedEvent(orig.getRecipeManager(), registryAccess);
events.fireEventHandlers(priority, event);
});
});

events.registerEvent(ItemTooltipEvent.class, priority -> {
NeoForge.EVENT_BUS.addListener(NeoForgeBalmEvents.toForge(priority), (net.neoforged.neoforge.event.entity.player.ItemTooltipEvent orig) -> {
final ItemTooltipEvent event = new ItemTooltipEvent(orig.getItemStack(), orig.getEntity(), orig.getToolTip(), orig.getFlags());
Expand Down
Loading

0 comments on commit 4a7d404

Please sign in to comment.