forked from FabricMC/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request FabricMC#7 from BoogieMonster1O1/1.8.9
Itemgroups v0
- Loading branch information
Showing
23 changed files
with
630 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
archivesBaseName = "fabric-item-groups-v0" | ||
version = getSubprojectVersion(project, "0.1.0") | ||
|
||
dependencies { | ||
compile project(path: ':fabric-api-base', configuration: 'dev') | ||
compile project(path: ':fabric-resource-loader-v0', configuration: 'dev') | ||
} |
28 changes: 28 additions & 0 deletions
28
fabric-item-groups-v0/src/main/java/net/fabricmc/fabric/ItemgroupTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net.fabricmc.fabric; | ||
|
||
import net.fabricmc.api.ModInitializer; | ||
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; | ||
import net.minecraft.item.ItemGroup; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class ItemgroupTest implements ModInitializer { | ||
@Override | ||
public void onInitialize() { | ||
ItemGroup FOO = FabricItemGroupBuilder.create(new Identifier("foo:bar")).appendItems((stacks)->{ | ||
stacks.add(new ItemStack(Items.ARROW)); | ||
stacks.add(new ItemStack(Items.APPLE)); | ||
stacks.add(new ItemStack(Items.ARROW)); | ||
stacks.add(new ItemStack(Items.ARROW)); | ||
stacks.add(new ItemStack(Items.ARROW)); | ||
}).icon(()->new ItemStack(Items.ARMOR_STAND)).build(); | ||
ItemGroup BAR = FabricItemGroupBuilder.create(new Identifier("bar:foo")).appendItems((stacks)->{ | ||
stacks.add(new ItemStack(Items.CAKE)); | ||
stacks.add(new ItemStack(Items.SKULL)); | ||
stacks.add(new ItemStack(Items.FIREWORKS)); | ||
stacks.add(new ItemStack(Items.ARROW)); | ||
stacks.add(new ItemStack(Items.ARROW)); | ||
}).icon(()->new ItemStack(Items.CARROT)).build(); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...ups-v0/src/main/java/net/fabricmc/fabric/api/client/itemgroup/FabricItemGroupBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 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.api.client.itemgroup; | ||
|
||
import java.util.List; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemGroup; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.Identifier; | ||
|
||
import net.fabricmc.fabric.impl.item.group.ItemGroupExtensions; | ||
|
||
public class FabricItemGroupBuilder { | ||
private final Identifier identifier; | ||
private Supplier<ItemStack> stackSupplier = () -> new ItemStack((Item) null); | ||
private Consumer<List<ItemStack>> stacksForDisplay; | ||
|
||
private FabricItemGroupBuilder(Identifier identifier) { | ||
this.identifier = identifier; | ||
} | ||
|
||
public static FabricItemGroupBuilder create(Identifier identifier) { | ||
return new FabricItemGroupBuilder(identifier); | ||
} | ||
|
||
public FabricItemGroupBuilder icon(Supplier<ItemStack> stackSupplier) { | ||
this.stackSupplier = stackSupplier; | ||
return this; | ||
} | ||
|
||
public FabricItemGroupBuilder appendItems(Consumer<List<ItemStack>> stacksForDisplay) { | ||
this.stacksForDisplay = stacksForDisplay; | ||
return this; | ||
} | ||
|
||
public static ItemGroup build(Identifier identifier, Supplier<ItemStack> stackSupplier) { | ||
return new FabricItemGroupBuilder(identifier).icon(stackSupplier).build(); | ||
} | ||
|
||
public ItemGroup build() { | ||
((ItemGroupExtensions) ItemGroup.BUILDING_BLOCKS).fabric_expandArray(); | ||
return new ItemGroup(ItemGroup.itemGroups.length - 1, String.format("%s.%s", identifier.getNamespace(), identifier.getPath())) { | ||
@Override | ||
public Item getIconItem() { | ||
return stackSupplier.get().getItem(); | ||
} | ||
|
||
@Override | ||
public void method_8192(List<ItemStack> list) { | ||
if (stacksForDisplay != null) { | ||
stacksForDisplay.accept(list); | ||
return; | ||
} | ||
|
||
super.method_8192(list); | ||
} | ||
}; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
.../src/main/java/net/fabricmc/fabric/impl/item/group/CreativeInventoryScreenExtensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 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.impl.item.group; | ||
|
||
public interface CreativeInventoryScreenExtensions { | ||
void fabric_nextPage(); | ||
|
||
void fabric_previousPage(); | ||
|
||
int fabric_currentPage(); | ||
|
||
boolean fabric_isButtonVisible(FabricCreativeGuiComponents.Type type); | ||
|
||
boolean fabric_isButtonEnabled(FabricCreativeGuiComponents.Type type); | ||
} |
95 changes: 95 additions & 0 deletions
95
...ups-v0/src/main/java/net/fabricmc/fabric/impl/item/group/FabricCreativeGuiComponents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 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.impl.item.group; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
|
||
import com.mojang.blaze3d.platform.GlStateManager; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; | ||
import net.minecraft.client.gui.widget.ButtonWidget; | ||
import net.minecraft.item.ItemGroup; | ||
import net.minecraft.text.TranslatableText; | ||
import net.minecraft.util.Identifier; | ||
|
||
import net.fabricmc.fabric.mixin.item.group.client.MixinScreen; | ||
|
||
public class FabricCreativeGuiComponents { | ||
private static final Identifier BUTTON_TEX = new Identifier("fabric", "textures/gui/creative_buttons.png"); | ||
public static final Set<ItemGroup> COMMON_GROUPS = new HashSet<>(); | ||
|
||
static { | ||
COMMON_GROUPS.add(ItemGroup.SEARCH); | ||
COMMON_GROUPS.add(ItemGroup.INVENTORY); | ||
} | ||
|
||
public static class ItemGroupButtonWidget extends ButtonWidget { | ||
CreativeInventoryScreenExtensions extensions; | ||
CreativeInventoryScreen gui; | ||
public Type type; | ||
|
||
public ItemGroupButtonWidget(int id, int x, int y, Type type, CreativeInventoryScreenExtensions extensions) { | ||
super(id, x, y, 11, 10, type.text); | ||
this.extensions = extensions; | ||
this.type = type; | ||
this.gui = (CreativeInventoryScreen) extensions; | ||
} | ||
|
||
@Override | ||
public void render(MinecraftClient client, int mouseX, int mouseY) { | ||
this.focused = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height; | ||
this.visible = extensions.fabric_isButtonVisible(type); | ||
this.active = extensions.fabric_isButtonEnabled(type); | ||
|
||
if (this.visible) { | ||
int u = active && this.isFocused() ? 22 : 0; | ||
int v = active ? 0 : 10; | ||
|
||
MinecraftClient minecraftClient = MinecraftClient.getInstance(); | ||
minecraftClient.getTextureManager().bindTexture(BUTTON_TEX); | ||
GlStateManager.disableLighting(); | ||
GlStateManager.color4f(1F, 1F, 1F, 1F); | ||
this.drawTexture(this.x, this.y, u + (type == Type.NEXT ? 11 : 0), v, 11, 10); | ||
|
||
if (this.focused) { | ||
((MixinScreen) gui).invokeRenderTooltip(new TranslatableText("fabric.gui.creativeTabPage", extensions.fabric_currentPage() + 1, ((ItemGroup.itemGroups.length - 12) / 9) + 2).asString(), mouseX, mouseY); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void mouseReleased(int mouseX, int mouseY) { | ||
super.mouseReleased(mouseX, mouseY); | ||
} | ||
} | ||
|
||
public enum Type { | ||
NEXT(">", CreativeInventoryScreenExtensions::fabric_nextPage), | ||
PREVIOUS("<", CreativeInventoryScreenExtensions::fabric_previousPage); | ||
|
||
String text; | ||
public Consumer<CreativeInventoryScreenExtensions> clickConsumer; | ||
|
||
Type(String text, Consumer<CreativeInventoryScreenExtensions> clickConsumer) { | ||
this.text = text; | ||
this.clickConsumer = clickConsumer; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...item-groups-v0/src/main/java/net/fabricmc/fabric/impl/item/group/ItemGroupExtensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 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.impl.item.group; | ||
|
||
public interface ItemGroupExtensions { | ||
void fabric_expandArray(); | ||
} |
44 changes: 44 additions & 0 deletions
44
fabric-item-groups-v0/src/main/java/net/fabricmc/fabric/mixin/item/group/MixinItemGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 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.item.group; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import net.minecraft.item.ItemGroup; | ||
|
||
import net.fabricmc.fabric.impl.item.group.ItemGroupExtensions; | ||
|
||
@Mixin(ItemGroup.class) | ||
public class MixinItemGroup implements ItemGroupExtensions { | ||
@Shadow | ||
@Final | ||
@Mutable | ||
public static ItemGroup[] itemGroups; | ||
|
||
@Override | ||
public void fabric_expandArray() { | ||
ItemGroup[] groups = itemGroups; | ||
itemGroups = new ItemGroup[itemGroups.length + 1]; | ||
|
||
if (groups.length >= 0) { | ||
System.arraycopy(groups, 0, itemGroups, 0, groups.length); | ||
} | ||
} | ||
} |
Oops, something went wrong.