Skip to content

Commit

Permalink
Update to 1.21 and fix normals
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiDragon committed Jun 23, 2024
1 parent e348783 commit 3210344
Show file tree
Hide file tree
Showing 67 changed files with 82 additions and 77 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -33,8 +33,8 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:$fabric_version"

// Dependencies
include modImplementation("com.kneelawk.graphlib:core-fabric:$graphlib_version")
modLocalRuntime("com.kneelawk.graphlib:debugrender-fabric:$graphlib_version")
include modImplementation("com.kneelawk.graphlib:graphlib-core-fabric:$graphlib_version")
modLocalRuntime("com.kneelawk.graphlib:graphlib-debugrender-fabric:$graphlib_version")
//modImplementation "vazkii.patchouli:Patchouli:$patchouli_version"

modImplementation annotationProcessor(include("com.github.mattidragon:ConfigToolkit:$configtoolkit_version"))
Expand Down
2 changes: 2 additions & 0 deletions changelog/3.0.0+1.21.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Updated to 1.21
* Fix longstanding issues with lighting of items in drawers
3 changes: 0 additions & 3 deletions changelog/3.0.0-beta.1+1.20.6.md

This file was deleted.

14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
org.gradle.jvmargs=-Xmx1G

minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
minecraft_version=1.21
yarn_mappings=1.21+build.2
loader_version=0.15.11

mod_version=3.0.0-beta.1
mod_version=3.0.0
maven_group=io.github.mattidragon
archives_base_name=ExtendedDrawers

fabric_version=0.98.0+1.20.6
graphlib_version=2.0.0-alpha.16+1.20.6
fabric_version=0.100.3+1.21
graphlib_version=2.0.0+1.21
patchouli_version=1.20.1-81-FABRIC
yacl_version=3.4.2+1.20.5
modmenu_version=10.0.0-beta.1
yacl_version=3.5.0+1.21
modmenu_version=11.0.1
configtoolkit_version=1.1.1
noindium_version=1.1.0+1.20.4
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public int render(DrawContext context, int x, int y, int renderWidth, float tick
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(180));
matrices.translate(0.5, -0.5, 0);

var voidingSprite = atlas.apply(new Identifier("minecraft", "item/lava_bucket"));
var voidingSprite = atlas.apply(Identifier.ofVanilla("item/lava_bucket"));
var lockSprite = atlas.apply(id("item/lock"));
var upgrade2Sprite = atlas.apply(id("item/t2_upgrade"));
var upgrade4Sprite = atlas.apply(id("item/t4_upgrade"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public String getString() {

@Override
public void setFromString(String value) {
option.requestSet(Objects.requireNonNullElse(Identifier.tryParse(value), new Identifier("air")));
option.requestSet(Objects.requireNonNullElse(Identifier.tryParse(value), Identifier.ofVanilla("air")));
}

@Override
public boolean isInputValid(String input) {
return Identifier.isValid(input);
return !Identifier.validate(input).isError();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.mattidragon.extendeddrawers.client.mixin;

import com.mojang.blaze3d.systems.RenderSystem;
import org.joml.Vector3f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(RenderSystem.class)
public interface RenderSystemAccess {
@Accessor
static Vector3f[] getShaderLightDirections() {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.mattidragon.extendeddrawers.client.renderer;

import io.github.mattidragon.extendeddrawers.ExtendedDrawers;
import io.github.mattidragon.extendeddrawers.client.mixin.RenderSystemAccess;
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
Expand All @@ -27,6 +28,7 @@
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;

import java.util.List;
import java.util.Objects;
Expand All @@ -37,7 +39,6 @@ public abstract class AbstractDrawerBlockEntityRenderer<T extends BlockEntity> i

private final ItemRenderer itemRenderer;
private final TextRenderer textRenderer;
private boolean isGui = false;

public AbstractDrawerBlockEntityRenderer(ItemRenderer itemRenderer, TextRenderer textRenderer) {
this.itemRenderer = itemRenderer;
Expand All @@ -49,13 +50,11 @@ public AbstractDrawerBlockEntityRenderer(ItemRenderer itemRenderer, TextRenderer
*/
public static AbstractDrawerBlockEntityRenderer<BlockEntity> createRendererTool() {
var client = MinecraftClient.getInstance();
AbstractDrawerBlockEntityRenderer<BlockEntity> renderer = new AbstractDrawerBlockEntityRenderer<>(client.getItemRenderer(), client.textRenderer) {
return new AbstractDrawerBlockEntityRenderer<>(client.getItemRenderer(), client.textRenderer) {
@Override
public void render(BlockEntity entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
}
};
renderer.isGui = true;
return renderer;
}

public void renderSlot(ItemVariant item, @Nullable String amount, boolean small, boolean hidden, List<Sprite> icons, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, int seed, BlockPos pos, World world) {
Expand Down Expand Up @@ -134,26 +133,29 @@ public void renderItem(ItemVariant item, boolean small, int light, MatrixStack m
matrices.push();
matrices.scale(itemScale, itemScale, 1);
matrices.scale(0.75f, 0.75f, 1);
matrices.multiplyPositionMatrix(new Matrix4f().scale(1, 1, 0.01f));

matrices.peek().getPositionMatrix().mul(new Matrix4f().scale(1, 1, 0.01f));
var stack = item.toStack();
var model = itemRenderer.getModel(stack, world, null, seed);

if (isGui) {
DiffuseLighting.disableGuiDepthLighting();
// Copy existing light configuration
var lights = new Vector3f[2];
System.arraycopy(RenderSystemAccess.getShaderLightDirections(), 0, lights, 0, 2);

// Set up gui lighting
if (model.isSideLit()) {
matrices.peek().getNormalMatrix().rotate(ITEM_LIGHT_ROTATION_3D);
DiffuseLighting.enableGuiDepthLighting();
} else {
// Stolen from storage drawers
if (model.isSideLit()) {
matrices.peek().getNormalMatrix().rotate(ITEM_LIGHT_ROTATION_3D);
} else {
matrices.peek().getNormalMatrix().rotate(ITEM_LIGHT_ROTATION_FLAT);
}
matrices.peek().getNormalMatrix().rotate(ITEM_LIGHT_ROTATION_FLAT);
DiffuseLighting.disableGuiDepthLighting();
}

itemRenderer.renderItem(stack, ModelTransformationMode.GUI, false, matrices, vertexConsumers, light, OverlayTexture.DEFAULT_UV, model);

if (isGui) DiffuseLighting.enableGuiDepthLighting();

// Restore light configuration
System.arraycopy(lights, 0, RenderSystemAccess.getShaderLightDirections(), 0, 2);

matrices.pop();
}

Expand Down Expand Up @@ -182,12 +184,13 @@ protected void alignMatrices(MatrixStack matrices, Direction dir, BlockFace face
default -> dir.getUnitVector();
};
matrices.translate(pos.x / 2 + 0.5, pos.y / 2 + 0.5, pos.z / 2 + 0.5);
matrices.multiplyPositionMatrix(new Matrix4f().rotation(dir.getRotationQuaternion()));
// We only transform the position matrix as the normals have to stay in the old configuration for item lighting
matrices.peek().getPositionMatrix().rotate(dir.getRotationQuaternion());
switch (face) {
case FLOOR -> matrices.multiplyPositionMatrix(new Matrix4f().rotation(RotationAxis.POSITIVE_X.rotationDegrees(-90)));
case CEILING -> matrices.multiplyPositionMatrix(new Matrix4f().rotation(RotationAxis.POSITIVE_X.rotationDegrees(90)));
case FLOOR -> matrices.peek().getPositionMatrix().rotate(RotationAxis.POSITIVE_X.rotationDegrees(-90));
case CEILING -> matrices.peek().getPositionMatrix().rotate(RotationAxis.POSITIVE_X.rotationDegrees(90));
}
matrices.multiplyPositionMatrix(new Matrix4f().rotation(RotationAxis.POSITIVE_X.rotationDegrees(-90)));
matrices.peek().getPositionMatrix().rotate(RotationAxis.POSITIVE_X.rotationDegrees(-90));
matrices.translate(0, 0, 0.01);
}
}
3 changes: 2 additions & 1 deletion src/client/resources/extended_drawers.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"compatibilityLevel": "JAVA_17",
"client": [
"ClientPlayerEntityMixin",
"ClientPlayerInteractionManagerMixin"
"ClientPlayerInteractionManagerMixin",
"RenderSystemAccess"
],
"injectors": {
"defaultRequire": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ExtendedDrawers implements ModInitializer {
public static ShiftAccess SHIFT_ACCESS = () -> false;

public static Identifier id(String path) {
return new Identifier(MOD_ID, path);
return Identifier.of(MOD_ID, path);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.item.TooltipType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.item.TooltipType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private ItemVariant parseItem(String data) {
}

var stack = new ItemStack(result.item());
stack.applyComponentsFrom(result.components());
stack.applyChanges(result.components());
return ItemVariant.of(stack);
} catch (CommandSyntaxException e) {
throw new JsonParseException("Failed to parse item", e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package io.github.mattidragon.extendeddrawers.compacting;

import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.recipe.RecipeManager;
import net.minecraft.recipe.RecipeType;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.recipe.input.CraftingRecipeInput;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -135,22 +133,12 @@ private Stream<ItemStack> findRecipes(ItemStack stack, int size, World world) {
* @param size The width and height of the inventory. Slot count is size squared.
* @return A filled crafting inventory of specified size
*/
private CraftingInventory createInventory(ItemStack stack, int size) {
var inventory = new CraftingInventory(new ScreenHandler(null, -1) {
@Override
public ItemStack quickMove(PlayerEntity player, int slot) {
return ItemStack.EMPTY;
}

@Override
public boolean canUse(PlayerEntity player) {
return false;
}
}, size, size);
private CraftingRecipeInput createInventory(ItemStack stack, int size) {
var list = new ArrayList<ItemStack>(size * size);
for (int i = 0; i < size * size; i++) {
inventory.setStack(i, stack);
list.add(stack);
}
return inventory;
return CraftingRecipeInput.create(size, size, list);
}

private record RecipePair(ItemVariant compressed, ItemVariant decompressed, int scale) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public record IconGroup(Identifier lockedIcon,
Identifier voidingIcon,
Identifier hiddenIcon,
Identifier dupingIcon) implements MutableClientCategory.MutableIconGroup.Source {
private static final IconGroup DEFAULT = new IconGroup(id("item/lock"), new Identifier("minecraft", "item/lava_bucket"), new Identifier("minecraft", "item/black_dye"), id("item/dupe_wand"));
private static final IconGroup DEFAULT = new IconGroup(id("item/lock"), Identifier.ofVanilla("item/lava_bucket"), Identifier.ofVanilla("item/black_dye"), id("item/dupe_wand"));

public static final Codec<IconGroup> CODEC = RecordCodecBuilder.create(instance -> instance.group(
AlwaysSerializedOptionalFieldCodec.create(Identifier.CODEC, "lockedIcon", DEFAULT.lockedIcon).forGetter(IconGroup::lockedIcon),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import io.github.mattidragon.extendeddrawers.block.base.DrawerInteractionHandler;
import io.github.mattidragon.extendeddrawers.registry.ModDataComponents;
import net.minecraft.client.item.TooltipType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import io.github.mattidragon.extendeddrawers.registry.ModDataComponents;
import io.github.mattidragon.extendeddrawers.registry.ModItems;
import io.github.mattidragon.extendeddrawers.registry.ModRecipes;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.recipe.SpecialCraftingRecipe;
import net.minecraft.recipe.book.CraftingRecipeCategory;
import net.minecraft.recipe.input.CraftingRecipeInput;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.world.World;
Expand All @@ -19,8 +19,8 @@ public CopyLimiterRecipe(CraftingRecipeCategory category) {
}

@Override
public boolean matches(RecipeInputInventory inventory, World world) {
var stacks = inventory.getHeldStacks();
public boolean matches(CraftingRecipeInput input, World world) {
var stacks = input.getStacks();
boolean setLimiterFound = false;
boolean unsetLimiterFound = false;

Expand All @@ -41,8 +41,8 @@ public boolean matches(RecipeInputInventory inventory, World world) {
}

@Override
public ItemStack craft(RecipeInputInventory inventory, RegistryWrapper.WrapperLookup registryLookup) {
var stacks = inventory.getHeldStacks();
public ItemStack craft(CraftingRecipeInput input, RegistryWrapper.WrapperLookup registryLookup) {
var stacks = input.getStacks();
Long limit = null;

for (var stack : stacks) {
Expand All @@ -67,11 +67,11 @@ public boolean fits(int width, int height) {
}

@Override
public DefaultedList<ItemStack> getRemainder(RecipeInputInventory inventory) {
var result = DefaultedList.ofSize(inventory.size(), ItemStack.EMPTY);
public DefaultedList<ItemStack> getRemainder(CraftingRecipeInput input) {
var result = DefaultedList.ofSize(input.getSize(), ItemStack.EMPTY);

for(int i = 0; i < result.size(); ++i) {
var stack = inventory.getStack(i);
var stack = input.getStackInSlot(i);
var item = stack.getItem();
if (item.getRecipeRemainder() != null) {
result.set(i, stack.getRecipeRemainder());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
import io.github.mattidragon.extendeddrawers.ExtendedDrawers;
import io.github.mattidragon.extendeddrawers.component.DrawerContentsComponent;
import io.github.mattidragon.extendeddrawers.component.DrawerSlotComponent;
import net.minecraft.component.DataComponentType;
import net.minecraft.component.ComponentType;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;

public class ModDataComponents {
public static final DataComponentType<Long> LIMITER_LIMIT = DataComponentType.<Long>builder()
public static final ComponentType<Long> LIMITER_LIMIT = ComponentType.<Long>builder()
.codec(Codec.LONG)
.packetCodec(PacketCodecs.VAR_LONG)
.build();
public static final DataComponentType<DrawerContentsComponent> DRAWER_CONTENTS = DataComponentType.<DrawerContentsComponent>builder()
public static final ComponentType<DrawerContentsComponent> DRAWER_CONTENTS = ComponentType.<DrawerContentsComponent>builder()
.codec(DrawerContentsComponent.CODEC)
.packetCodec(DrawerContentsComponent.PACKET_CODEC)
.cache()
.build();
public static final DataComponentType<DrawerSlotComponent> COMPACTING_DRAWER_CONTENTS = DataComponentType.<DrawerSlotComponent>builder()
public static final ComponentType<DrawerSlotComponent> COMPACTING_DRAWER_CONTENTS = ComponentType.<DrawerSlotComponent>builder()
.codec(DrawerSlotComponent.CODEC)
.packetCodec(DrawerSlotComponent.PACKET_CODEC)
.cache()
Expand Down
Loading

0 comments on commit 3210344

Please sign in to comment.