Skip to content

Commit

Permalink
feat: Update to Minecraft 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Oct 10, 2024
1 parent bbeb307 commit a684e5e
Show file tree
Hide file tree
Showing 25 changed files with 108 additions and 120 deletions.
12 changes: 12 additions & 0 deletions common/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
repositories {
exclusiveContent {
forRepository {
maven {
name = 'Minecraft'
url = 'https://libraries.minecraft.net/'
}
}
filter { includeGroupAndSubgroups("com.mojang") }
}
}

dependencies {
compileOnly "net.blay09.mods:kuma-api-common:$kuma_version"
compileOnly "mezz.jei:jei-$jei_minecraft_version-common-api:$jei_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ default CompoundTag getPersistentData(Player player) {

boolean canItemsStack(ItemStack first, ItemStack second);

int getBurnTime(ItemStack itemStack);
int getBurnTime(Level level, ItemStack itemStack);

void setBurnTime(Item item, int burnTime);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ default UnbakedModel retexture(ModelBakery bakery, ModelResourceLocation identif
Collections.emptyList());

// We have to resolve parents as that is usually done during stitching, which we're already past
blockModel.resolveParents(it -> ((ModelBakeryAccessor) bakery).callGetModel(it));
// TODO resolveDependencies? blockModel.resolveParents(it -> ((ModelBakeryAccessor) bakery).callGetModel(it));

return blockModel;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package net.blay09.mods.balm.api.event.client;

import net.blay09.mods.balm.api.event.BalmEvent;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.client.multiplayer.ClientRecipeContainer;

public class RecipesUpdatedEvent extends BalmEvent {
private final RecipeManager recipeManager;
private final RegistryAccess registryAccess;
private final ClientRecipeContainer clientRecipeContainer;

public RecipesUpdatedEvent(RecipeManager recipeManager, RegistryAccess registryAccess) {
this.recipeManager = recipeManager;
this.registryAccess = registryAccess;
public RecipesUpdatedEvent(ClientRecipeContainer clientRecipeContainer) {
this.clientRecipeContainer = clientRecipeContainer;
}

public RecipeManager getRecipeManager() {
return recipeManager;
}

public RegistryAccess getRegistryAccess() {
return registryAccess;
public ClientRecipeContainer getClientRecipeContainer() {
return clientRecipeContainer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void export(String filter) {
minecraft.execute(() -> {
RenderTarget renderTarget = null;
try {
renderTarget = new TextureTarget(64, 64, true, Minecraft.ON_OSX);
renderTarget = new TextureTarget(64, 64, true);

renderTarget.setClearColor(0f, 0f, 0f, 0f);
CreativeModeTabs.tryRebuildTabContents(minecraft.player.connection.enabledFeatures(),
Expand All @@ -43,7 +43,7 @@ public static void export(String filter) {
continue;
}

renderTarget.clear(false);
renderTarget.clear();
RenderSystem.enableDepthTest();
renderTarget.bindWrite(false);

Expand All @@ -52,14 +52,12 @@ public static void export(String filter) {
final var modelViewStack = RenderSystem.getModelViewStack();
modelViewStack.pushMatrix();
modelViewStack.translation(0f, 0f, -11000f);
RenderSystem.applyModelViewMatrix();
Lighting.setupForFlatItems();

guiGraphics.renderItem(itemStack, 0, 0);
guiGraphics.flush();

modelViewStack.popMatrix();
RenderSystem.applyModelViewMatrix();
renderTarget.unbindWrite();
RenderSystem.disableDepthTest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@
import net.blay09.mods.balm.api.client.rendering.BalmModels;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.*;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;

Expand Down Expand Up @@ -131,11 +127,6 @@ public ItemTransforms getTransforms() {
return ItemTransforms.NO_TRANSFORMS;
}

@Override
public ItemOverrides getOverrides() {
return ItemOverrides.EMPTY;
}

public abstract List<RenderType> getBlockRenderTypes(BlockState state, RandomSource rand);
public abstract List<RenderType> getItemRenderTypes(ItemStack itemStack, boolean fabulous);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.resources.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.Map;

@Mixin(ModelBakery.class)
public interface ModelBakeryAccessor {
@Invoker
UnbakedModel callGetModel(ResourceLocation location);
@Accessor
UnbakedModel getMissingModel();

@Accessor
Map<ResourceLocation, UnbakedModel> getUnbakedModels();

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.blay09.mods.balm.api.event.server.ServerReloadedEvent;
import net.minecraft.commands.Commands;
import net.minecraft.core.LayeredRegistryAccess;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.RegistryLayer;
import net.minecraft.server.ReloadableServerResources;
Expand All @@ -14,14 +15,15 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

@Mixin(ReloadableServerResources.class)
public class ReloadableServerResourcesMixin {

@Inject(method = "loadResources(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/core/LayeredRegistryAccess;Lnet/minecraft/world/flag/FeatureFlagSet;Lnet/minecraft/commands/Commands$CommandSelection;ILjava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;", at = @At("RETURN"), cancellable = true)
private static void loadResources(ResourceManager resourceManager, LayeredRegistryAccess<RegistryLayer> registryAccess, FeatureFlagSet featureFlagSet, Commands.CommandSelection commandSelection, int i, Executor e1, Executor e2, CallbackInfoReturnable<CompletableFuture<ReloadableServerResources>> callbackInfo) {
@Inject(method = "loadResources(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/core/LayeredRegistryAccess;Ljava/util/List;Lnet/minecraft/world/flag/FeatureFlagSet;Lnet/minecraft/commands/Commands$CommandSelection;ILjava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;", at = @At("RETURN"), cancellable = true)
private static void loadResources(ResourceManager resourceManager, LayeredRegistryAccess<RegistryLayer> registryAccess, List<Registry.PendingTags<?>> pendingTags, FeatureFlagSet featureFlagSet, Commands.CommandSelection commandSelection, int i, Executor e1, Executor e2, CallbackInfoReturnable<CompletableFuture<ReloadableServerResources>> callbackInfo) {
callbackInfo.getReturnValue().thenAccept(it -> Balm.getEvents().fireEvent(new ServerReloadedEvent(it)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import net.blay09.mods.balm.api.event.server.ServerStartedEvent;
import net.blay09.mods.balm.api.event.server.ServerStoppedEvent;
import net.blay09.mods.balm.api.fluid.FluidTank;
import net.fabricmc.fabric.api.item.v1.FabricItem;
import net.fabricmc.fabric.api.item.v1.FabricItemStack;
import net.fabricmc.fabric.api.registry.FuelRegistry;
import net.fabricmc.fabric.api.registry.FuelRegistryEvents;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponents;
Expand Down Expand Up @@ -72,16 +70,7 @@ public boolean isFakePlayer(Player player) {

@Override
public ItemStack getCraftingRemainingItem(ItemStack itemStack) {
if ((Object) itemStack instanceof FabricItemStack fabricItemStack) {
return fabricItemStack.getRecipeRemainder();
}

Item craftingRemainingItem = itemStack.getItem().getCraftingRemainingItem();
if (craftingRemainingItem != null) {
return new ItemStack(craftingRemainingItem);
} else {
return ItemStack.EMPTY;
}
return itemStack.getRecipeRemainder();
}

@Override
Expand All @@ -99,14 +88,13 @@ public boolean canItemsStack(ItemStack first, ItemStack second) {
}

@Override
public int getBurnTime(ItemStack itemStack) {
Integer burnTime = FuelRegistry.INSTANCE.get(itemStack.getItem());
return burnTime != null ? burnTime : 0;
public int getBurnTime(Level level, ItemStack itemStack) {
return level.fuelValues().burnDuration(itemStack);
}

@Override
public void setBurnTime(Item item, int burnTime) {
FuelRegistry.INSTANCE.add(item, burnTime);
FuelRegistryEvents.BUILD.register((builder, context) -> builder.add(item, burnTime));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ public ResourceLocation getKey(MenuType<?> menuType) {

@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 @@ -89,6 +89,6 @@ public Collection<ResourceLocation> getItemKeys() {

@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 @@ -48,7 +48,6 @@
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.resources.PreparableReloadListener;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller;

import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -215,8 +214,8 @@ public ResourceLocation getFabricId() {
}

@Override
public CompletableFuture<Void> reload(PreparationBarrier preparationBarrier, ResourceManager resourceManager, ProfilerFiller profilerFiller, ProfilerFiller profilerFiller2, Executor executor, Executor executor2) {
return reloadListener.reload(preparationBarrier, resourceManager, profilerFiller, profilerFiller2, executor, executor2);
public CompletableFuture<Void> reload(PreparationBarrier preparationBarrier, ResourceManager resourceManager, Executor executor, Executor executor2) {
return reloadListener.reload(preparationBarrier, resourceManager, executor, executor2);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.blay09.mods.balm.api.Balm;
import net.blay09.mods.balm.api.DeferredObject;
import net.blay09.mods.balm.api.block.BalmBlocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -18,7 +17,7 @@
public class FabricBalmBlocks implements BalmBlocks {
@Override
public BlockBehaviour.Properties blockProperties() {
return FabricBlockSettings.create();
return BlockBehaviour.Properties.of();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void set(BakedModel object) {
private ModelBakery modelBakery;

@Override
public void onInitializeModelLoader(Context context) {
public void initialize(Context context) {
context.addModels(additionalModels);
}

Expand Down Expand Up @@ -117,7 +117,7 @@ public DeferredObject<BakedModel> loadDynamicModel(ModelResourceLocation identif
public BakedModel resolve(ModelBakery bakery, 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 FabricCachedDynamicModel(bakery, unbakedModels, effectiveModelFunction, null, textureMapFunction, transformFunction, renderTypes, identifier, textureGetter);
}
Expand Down Expand Up @@ -153,12 +153,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();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
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 All @@ -18,15 +20,15 @@ public class FabricBalmEntities implements BalmEntities {
@Override
public <T extends Entity> DeferredObject<EntityType<T>> registerEntity(ResourceLocation identifier, EntityType.Builder<T> typeBuilder) {
return new DeferredObject<>(identifier, () -> {
EntityType<T> entityType = typeBuilder.build(identifier.toString());
EntityType<T> entityType = typeBuilder.build(ResourceKey.create(Registries.ENTITY_TYPE, identifier));
return Registry.register(BuiltInRegistries.ENTITY_TYPE, identifier, entityType);
}).resolveImmediately();
}

@Override
public <T extends LivingEntity> DeferredObject<EntityType<T>> registerEntity(ResourceLocation identifier, EntityType.Builder<T> typeBuilder, Supplier<AttributeSupplier.Builder> attributeBuilder) {
return new DeferredObject<>(identifier, () -> {
EntityType<T> entityType = typeBuilder.build(identifier.toString());
EntityType<T> entityType = typeBuilder.build(ResourceKey.create(Registries.ENTITY_TYPE, identifier));
FabricDefaultAttributeRegistry.register(entityType, attributeBuilder.get());
return Registry.register(BuiltInRegistries.ENTITY_TYPE, identifier, entityType);
}).resolveImmediately();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -129,17 +128,15 @@ public static void registerEvents(FabricBalmEvents events) {
return event.getInteractionResult();
}));

events.registerEvent(UseItemEvent.class, () -> {
UseItemCallback.EVENT.register((player, world, hand) -> {
final UseItemEvent event = new UseItemEvent(player, world, hand);
events.fireEventHandlers(event);
if (event.isCanceled()) {
return InteractionResultHolder.fail(player.getItemInHand(hand));
}
events.registerEvent(UseItemEvent.class, () -> UseItemCallback.EVENT.register((player, world, hand) -> {
final UseItemEvent event = new UseItemEvent(player, world, hand);
events.fireEventHandlers(event);
if (event.isCanceled()) {
return InteractionResult.FAIL;
}

return new InteractionResultHolder<>(event.getInteractionResult(), player.getItemInHand(hand));
});
});
return event.getInteractionResult();
}));

events.registerEvent(PlayerConnectedEvent.class, () -> ServerPlayConnectionEvents.JOIN.register((listener, sender, server) -> {
final PlayerLoginEvent event = new PlayerLoginEvent(listener.player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
@Mixin(AbstractClientPlayer.class)
public class AbstractClientPlayerMixin {

@Inject(method = "getFieldOfViewModifier()F", at = @At("TAIL"), cancellable = true)
private void getFieldOfViewModifier(CallbackInfoReturnable<Float> callbackInfo) {
@Inject(method = "getFieldOfViewModifier(ZF)F", at = @At("TAIL"), cancellable = true)
private void getFieldOfViewModifier(boolean allowScoping, float current, CallbackInfoReturnable<Float> callbackInfo) {
FovUpdateEvent event = new FovUpdateEvent((LivingEntity) (Object) this);
Balm.getEvents().fireEvent(event);
Float override = event.getFov();
Expand Down
Loading

0 comments on commit a684e5e

Please sign in to comment.