forked from FabricMC/fabric
Fix ItemGroup API on servers
This commit is contained in:
parent
8c5c87466f
commit
1345c08cb8
5 changed files with 49 additions and 21 deletions
|
@ -92,12 +92,11 @@ public final class FabricItemGroupBuilder {
|
||||||
public ItemGroup build() {
|
public ItemGroup build() {
|
||||||
((ItemGroupExtensions) ItemGroup.BUILDING_BLOCKS).fabric_expandArray();
|
((ItemGroupExtensions) ItemGroup.BUILDING_BLOCKS).fabric_expandArray();
|
||||||
return new ItemGroup(ItemGroup.GROUPS.length - 1, String.format("%s.%s", identifier.getNamespace(), identifier.getPath())) {
|
return new ItemGroup(ItemGroup.GROUPS.length - 1, String.format("%s.%s", identifier.getNamespace(), identifier.getPath())) {
|
||||||
@Override
|
|
||||||
public ItemStack getIconItem() {
|
public ItemStack getIconItem() {
|
||||||
return stackSupplier.get();
|
return stackSupplier.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getStacksForDisplay(DefaultedList<ItemStack> stacks) {
|
public void getStacksForDisplay(DefaultedList<ItemStack> stacks) {
|
||||||
if(stacksForDisplay != null){
|
if(stacksForDisplay != null){
|
||||||
stacksForDisplay.accept(stacks);
|
stacksForDisplay.accept(stacks);
|
||||||
|
|
|
@ -17,23 +17,16 @@
|
||||||
package net.fabricmc.fabric.mixin.client.itemgroup;
|
package net.fabricmc.fabric.mixin.client.itemgroup;
|
||||||
|
|
||||||
import net.fabricmc.fabric.client.itemgroup.FabricCreativeGuiComponents;
|
import net.fabricmc.fabric.client.itemgroup.FabricCreativeGuiComponents;
|
||||||
import net.fabricmc.fabric.client.itemgroup.ItemGroupExtensions;
|
|
||||||
import net.minecraft.item.ItemGroup;
|
import net.minecraft.item.ItemGroup;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Mutable;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
@Mixin(ItemGroup.class)
|
@Mixin(ItemGroup.class)
|
||||||
public abstract class MixinItemGroup implements ItemGroupExtensions {
|
public abstract class MixinItemGroup {
|
||||||
|
|
||||||
@Shadow
|
|
||||||
@Final
|
|
||||||
@Mutable
|
|
||||||
public static ItemGroup[] GROUPS;
|
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
public abstract int getId();
|
public abstract int getId();
|
||||||
|
@ -45,14 +38,6 @@ public abstract class MixinItemGroup implements ItemGroupExtensions {
|
||||||
@Final
|
@Final
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fabric_expandArray() {
|
|
||||||
ItemGroup[] tempGroups = GROUPS;
|
|
||||||
GROUPS = new ItemGroup[GROUPS.length + 1];
|
|
||||||
for (ItemGroup group : tempGroups) {
|
|
||||||
GROUPS[group.getId()] = group;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "isTopRow", cancellable = true, at = @At("HEAD"))
|
@Inject(method = "isTopRow", cancellable = true, at = @At("HEAD"))
|
||||||
private void isTopRow(CallbackInfoReturnable<Boolean> info) {
|
private void isTopRow(CallbackInfoReturnable<Boolean> info) {
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 2017, 2018 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.fabricmc.fabric.mixin.itemgroup;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.client.itemgroup.ItemGroupExtensions;
|
||||||
|
import net.minecraft.item.ItemGroup;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Mutable;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
|
||||||
|
@Mixin(ItemGroup.class)
|
||||||
|
public abstract class MixinItemGroup implements ItemGroupExtensions {
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
@Final
|
||||||
|
@Mutable
|
||||||
|
public static ItemGroup[] GROUPS;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fabric_expandArray() {
|
||||||
|
ItemGroup[] tempGroups = GROUPS;
|
||||||
|
GROUPS = new ItemGroup[GROUPS.length + 1];
|
||||||
|
for (int i = 0; i < tempGroups.length; i++) {
|
||||||
|
GROUPS[i] = tempGroups[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,6 +17,7 @@
|
||||||
"events.server.MixinMinecraftServer",
|
"events.server.MixinMinecraftServer",
|
||||||
"events.tick.MixinMinecraftServer",
|
"events.tick.MixinMinecraftServer",
|
||||||
"events.tick.MixinWorld",
|
"events.tick.MixinWorld",
|
||||||
|
"itemgroup.MixinItemGroup",
|
||||||
"misc.MixinCrashReport",
|
"misc.MixinCrashReport",
|
||||||
"networking.MixinServerPlayNetworkHandler",
|
"networking.MixinServerPlayNetworkHandler",
|
||||||
"networking.MixinSPacketCustomPayload",
|
"networking.MixinSPacketCustomPayload",
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package net.fabricmc.fabric.itemgroup;
|
package net.fabricmc.fabric.itemgroup;
|
||||||
|
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
@ -27,9 +27,9 @@ import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
|
|
||||||
public class ItemGroupMod implements ClientModInitializer {
|
public class ItemGroupMod implements ModInitializer {
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitialize() {
|
||||||
//This creates your standard Item Group
|
//This creates your standard Item Group
|
||||||
ItemGroup group = FabricItemGroupBuilder.build(new Identifier("fabric", "fabric_test_tab"), () -> new ItemStack(Items.IRON_CHESTPLATE));
|
ItemGroup group = FabricItemGroupBuilder.build(new Identifier("fabric", "fabric_test_tab"), () -> new ItemStack(Items.IRON_CHESTPLATE));
|
||||||
Item testItem = new Item(new Item.Settings().itemGroup(group));
|
Item testItem = new Item(new Item.Settings().itemGroup(group));
|
||||||
|
|
Loading…
Reference in a new issue