Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal to Change Creative Buttons Texture #4221

Open
wants to merge 14 commits into
base: 1.21.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen.CreativeScreenHandler;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemGroups;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import net.fabricmc.fabric.api.client.itemgroup.v1.FabricCreativeInventoryScreen;
import net.fabricmc.fabric.impl.client.itemgroup.FabricCreativeGuiComponents;
Expand Down Expand Up @@ -68,11 +75,11 @@ private void updateSelection() {
}
}

@Inject(method = "init", at = @At("RETURN"))
@Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TextFieldWidget;setEditableColor(I)V", shift = At.Shift.AFTER))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed to stop creating creative buttons when in survival mode, incase anyone asks the purpose

private void init(CallbackInfo info) {
currentPage = getPage(selectedTab);

int xpos = x + 170;
int xpos = x + 166;
int ypos = y + 4;

CreativeInventoryScreen self = (CreativeInventoryScreen) (Object) this;
Expand Down Expand Up @@ -197,4 +204,38 @@ public boolean setSelectedItemGroup(ItemGroup itemGroup) {
setSelectedTab(itemGroup);
return true;
}

@Unique
private boolean displaySearchBarModification = false;

@Inject(method = "setSelectedTab", at = @At("TAIL"))
void searchBarBackgroundDeterminant(ItemGroup group, CallbackInfo ci) {
displaySearchBarModification = (group.getType() == ItemGroup.Type.SEARCH) && hasAdditionalPages();
}

@Unique
private static final Identifier CREATIVE_SEARCH_TAB = ItemGroup.getTabTextureId("item_search");

@Inject(method = "drawBackground", at = @At("TAIL"))
public void renderSearchBar(DrawContext context, float delta, int mouseX, int mouseY, CallbackInfo ci) {
if (displaySearchBarModification) {
context.drawTexture(RenderLayer::getGuiTextured, CREATIVE_SEARCH_TAB, x + 161, y + 4, 166, 4, 5, 12, 256, 256);
}
}

@WrapOperation(
method = "init",
at = @At(
value = "NEW",
target = "net/minecraft/client/gui/widget/TextFieldWidget"
)
)
private TextFieldWidget shortenSearchBarTextField(TextRenderer textRenderer, int x, int y, int width, int height, Text text, Operation<TextFieldWidget> original) {
// Modify only the available text space width to be 5 pixels shorter
if (hasAdditionalPages()) {
matthewperiut marked this conversation as resolved.
Show resolved Hide resolved
return original.call(textRenderer, x, y, width - 5, height, text);
} else {
return original.call(textRenderer, x, y, width, height, text);
}
}
}

This comment was marked as off-topic.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.