Skip to content

Commit

Permalink
Port Item Group module to 1.6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed May 9, 2024
1 parent 9170d75 commit f96b8da
Show file tree
Hide file tree
Showing 21 changed files with 295 additions and 20 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ For support, consider joining the [Legacy Fabric discord server](https://legacyf
? = Not sure if it was tested or working correctly\
❌ = Not working at all, likely crashing

| | 1.6.4 | 1.7.10 | 1.8 | 1.8.9 | 1.9.4 | 1.10.2 | 1.11.2 | 1.12.2 | 1.13.2 |
|----------------------|------------------------------------|--------|-----|-------|-------|--------|--------|--------|--------|
| api-base | |||||||||
| command-api-v1 | |||||||||
| command-api-v2 |<br/>Text formatting need rework |||||||||
| crash-report-info-v1 | |||||||||
| entity-events-v1 | |||||||||
| gamerule-api-v1 | ? |||||||| ? |
| item-groups-v1 | |||||||||
| keybindings-api-v1 | |||||||||
| lifecycle-events-v1 | |||||||||
| logger-api-v1 | |||||||||
| networking-api-v1 | |||||||||
| permissions-api-v1 | |||||||||
| registry-sync-api-v1 | |||||||||
| rendering-api-v1 | |||||||||
| resource-loader-v1 | |||||||||
| | 1.6.4 | 1.7.10 | 1.8 | 1.8.9 | 1.9.4 | 1.10.2 | 1.11.2 | 1.12.2 | 1.13.2 |
|----------------------|-------------------------------|--------|-----|-------|-------|--------|--------|--------|--------|
| api-base ||||||||||
| command-api-v1 ||||||||||
| command-api-v2 | ⚠ Text formatting need rework |||||||||
| crash-report-info-v1 ||||||||||
| entity-events-v1 ||||||||||
| gamerule-api-v1 | ? |||||||| ? |
| item-groups-v1 | |||||||||
| keybindings-api-v1 ||||||||||
| lifecycle-events-v1 ||||||||||
| logger-api-v1 ||||||||||
| networking-api-v1 ||||||||||
| permissions-api-v1 ||||||||||
| registry-sync-api-v1 |(Depends on networking-api) |||||||||
| rendering-api-v1 ||||||||||
| resource-loader-v1 ||||||||||
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2020 - 2024 Legacy Fabric
* Copyright (c) 2016 - 2022 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.legacyfabric.fabric.mixin.item.group.client;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import net.minecraft.client.gui.screen.Screen;

import net.legacyfabric.fabric.impl.item.group.ScreenAccessor;

@Mixin(Screen.class)
public abstract class MixinScreen implements ScreenAccessor {
@Shadow
public abstract void renderTooltip(String text, int x, int y);

@Override
public void callRenderTooltip(String text, int x, int y) {
this.renderTooltip(text, x, y);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"ItemGroupMixin"
],
"client": [
"client.MixinScreen"
],
"injectors": {
"defaultRequire": 1
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions legacy-fabric-item-groups-v1/1.6.4/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minVersionIncluded=1.3
maxVersionIncluded=1.6.4
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2020 - 2024 Legacy Fabric
* Copyright (c) 2016 - 2022 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.legacyfabric.fabric.impl.item.group;

import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Supplier;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.itemgroup.ItemGroup;

public class FabricItemGroup extends ItemGroup {
private final Supplier<ItemStack> itemSupplier;
private final BiConsumer<List<ItemStack>, ItemGroup> stacksForDisplay;

public FabricItemGroup(int index, String id, Supplier<ItemStack> itemSupplier, BiConsumer<List<ItemStack>, ItemGroup> stacksForDisplay) {
super(index, id);
this.itemSupplier = itemSupplier;
this.stacksForDisplay = stacksForDisplay;
}

@Override
@Environment(EnvType.CLIENT)
public Item method_3320() {
return this.itemSupplier.get().getItem();
}

@Override
@Environment(EnvType.CLIENT)
public void showItems(List stacks) {
if (stacksForDisplay != null) {
stacksForDisplay.accept(stacks, this);
return;
}

super.showItems(stacks);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2020 - 2024 Legacy Fabric
* Copyright (c) 2016 - 2022 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.legacyfabric.fabric.mixin.item.group;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.item.itemgroup.ItemGroup;

import net.legacyfabric.fabric.impl.item.group.FabricCreativeGuiComponents;
import net.legacyfabric.fabric.impl.item.group.FabricItemGroup;

@Mixin(ItemGroup.class)
public class ItemGroupMixin {
@Inject(method = "<clinit>", at = @At("RETURN"))
private static void classInit(CallbackInfo ci) {
FabricCreativeGuiComponents.ITEM_GROUP_CREATOR = FabricItemGroup::new;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.legacyfabric.fabric.mixin.item.group.client;

import net.legacyfabric.fabric.impl.item.group.ScreenAccessor;

import net.minecraft.client.gui.screen.ingame.HandledScreen;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(HandledScreen.class)
public abstract class HandledScreenMixin implements ScreenAccessor {
@Shadow
protected abstract void method_1128(String par1, int par2, int par3);

@Override
public void callRenderTooltip(String text, int x, int y) {
this.method_1128(text, x, y);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fabric.gui.creativeTabPage=Page %d/%d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fabric.gui.creativeTabPage=Страница %d/%d
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"schemaVersion": 1,
"id": "legacy-fabric-item-groups-v1",
"name": "Legacy Fabric Item Groups (V1)",
"version": "${version}",
"environment": "*",
"license": "Apache-2.0",
"icon": "assets/legacy-fabric/icon.png",
"contact": {
"homepage": "https://legacyfabric.net/",
"issues": "https://github.com/Legacy-Fabric/fabric/issues",
"sources": "https://github.com/Legacy-Fabric/fabric"
},
"authors": [
"FabricMC",
"Legacy Fabric"
],
"mixins": [
"legacy-fabric-item-groups-v1.mixins.json"
],
"description": "Advanced item groups.",
"depends": {
"minecraft": "${minecraft_version}"
},
"custom": {
"modmenu": {
"badges": [ "library" ],
"parent": {
"id": "legacy-fabric-api",
"name": "Legacy Fabric API",
"badges": [ "library" ],
"description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.",
"icon": "assets/legacy-fabric/icon.png"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"required": true,
"package": "net.legacyfabric.fabric.mixin.item.group",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ItemGroupMixin"
],
"client": [
"client.HandledScreenMixin"
],
"injectors": {
"defaultRequire": 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2020 - 2024 Legacy Fabric
* Copyright (c) 2016 - 2022 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.legacyfabric.fabric.test.item.group;

import java.util.Arrays;
import java.util.Objects;
import java.util.stream.StreamSupport;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.itemgroup.ItemGroup;

import net.fabricmc.api.ModInitializer;

import net.legacyfabric.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.legacyfabric.fabric.api.util.Identifier;

public class ItemGroupTest implements ModInitializer {
//Adds an item group with all items in it
private static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.create(new Identifier("legacy-fabric-item-groups-v1-testmod", "test_group"))
.iconWithItemStack(() -> new ItemStack(Item.DIAMOND))
.appendItems(stacks ->
StreamSupport.stream(Arrays.stream(Item.ITEMS).spliterator(), false)
.filter(Objects::nonNull)
.map(ItemStack::new)
.forEach(stacks::add)
).build();

private static final ItemGroup ITEM_GROUP_2 = FabricItemGroupBuilder.create(new Identifier("legacy-fabric-item-groups-v1-testmod", "test_group_two"))
.iconWithItemStack(() -> new ItemStack(Item.REDSTONE))
.appendItems((stacks, itemGroup) -> {
for (Item item : Item.ITEMS) {
if (item != null && (item.getItemGroup() == ItemGroup.FOOD || item.getItemGroup() == itemGroup)) {
stacks.add(new ItemStack(item));
}
}
}).build();

@Override
public void onInitialize() { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
itemGroup.dmn.testgroup=Test Group by DomamaN202
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"schemaVersion": 1,
"id": "legacy-fabric-item-groups-v0-testmod",
"description": "Tests for Item Groups",
"version": "1.0.0",
"entrypoints": {
"main": [
"net.legacyfabric.fabric.test.item.group.ItemGroupTest"
]
},
"depends": {
"minecraft": "${minecraft_version}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"ItemGroupMixin"
],
"client": [
"client.MixinScreen"
],
"injectors": {
"defaultRequire": 1
Expand Down
2 changes: 1 addition & 1 deletion legacy-fabric-item-groups-v1/common/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
minVersionIncluded=1.7.10
minVersionIncluded=1.3
maxVersionIncluded=1.12.2
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
],
"client": [
"client.MixinCreativePlayerInventoryGui",
"client.MixinItemGroup",
"client.MixinScreen"
"client.MixinItemGroup"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit f96b8da

Please sign in to comment.