Skip to content

Commit

Permalink
Ensure bundle tooltip render fits in the tooltip
Browse files Browse the repository at this point in the history
Implement right click to dump
  • Loading branch information
TJT01 committed Oct 26, 2021
1 parent 945e973 commit 04a89a8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '1.16.5-0.1.1-alpha'
version = '1.16.5-0.1.2-alpha'
group = 'mod.tjt01.sprinkle' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'sprinkle'

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mod/tjt01/sprinkle/ForgeEventSubscriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void onRightClick(GuiScreenEvent.MouseReleasedEvent.Pre event) {

if (hoverSlot != null) {
if (heldStack.getItem() instanceof BundleItem || hoverSlot.getItem().getItem() instanceof BundleItem) {
Main.LOGGER.debug("poke");
//Main.LOGGER.debug("poke {}", hoverSlot.getSlotIndex());
SprinklePacketHandler.INSTANCE.sendToServer(containerScreen instanceof CreativeScreen ?
new CreativeBundleAction(hoverSlot.getSlotIndex(), heldStack) :
new BundleAction(hoverSlot.index));
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/mod/tjt01/sprinkle/item/BundleItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import mcp.MethodsReturnNonnullByDefault;
import mod.tjt01.sprinkle.data.ModTags;
import mod.tjt01.sprinkle.init.ModItems;
import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.client.Minecraft;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
Expand Down Expand Up @@ -140,11 +142,16 @@ public ItemStack addItem(ItemStack bundle, ItemStack toAdd) {
@Override
public void appendHoverText(ItemStack stack, @Nullable World level, List<ITextComponent> textComponents, ITooltipFlag tooltipFlag) {
super.appendHoverText(stack, level, textComponents, tooltipFlag);
Minecraft minecraft = Minecraft.getInstance();
textComponents.add(new StringTextComponent(""));
int rows = getRows(stack);
int columns = getColumns(stack);
String text = "";
while (minecraft.font.width(text) < (columns*18) + 2)
text += " ";
for (int i = 0; i < rows; i++) {
textComponents.add(new StringTextComponent(""));
textComponents.add(new StringTextComponent(""));
textComponents.add(new StringTextComponent(text));
textComponents.add(new StringTextComponent(text));
}
textComponents.add(new StringTextComponent(this.getFullness(stack) + "/" + MAX_FULLNESS).setStyle(Style.EMPTY.withColor(TextFormatting.GRAY)));
}
Expand All @@ -154,6 +161,11 @@ public void appendHoverText(ItemStack stack, @Nullable World level, List<ITextCo
public ActionResult<ItemStack> use(World level, PlayerEntity player, Hand hand) {
if (level.isClientSide)
return super.use(level, player, hand);
return super.use(level, player, hand);
NonNullList<ItemStack> stacks = this.getContents(player.getItemInHand(hand));
for (ItemStack stack: stacks) {
player.drop(stack, false, true);
}
this.setContents(player.getItemInHand(hand), NonNullList.create());
return ActionResult.success(player.getItemInHand(hand));
}
}

0 comments on commit 04a89a8

Please sign in to comment.