#strange bug in the ItemDisplayWidget class

34 messages · Page 1 of 1 (latest)

queen bear
#

I tried to create an object, but there were problems. I went into the class and there was this:

public ItemDisplayWidget(Minecraft minecraft, int i, int j, int k, int l, Component component, ItemStack itemStack, boolean bl, boolean bl2) {
        super(0, 0, k, l, component);
        this.minecraft = minecraft;
        this.offsetX = i;
        this.offsetY = j;
        this.itemStack = itemStack;
        this.decorations = bl;
        this.tooltip = bl2;
    }

Why are x,y always 0,0?

regal dove
queen bear
#

Well, that's doubtful. They're just throwing out two variables...

regal dove
#

k and l are passed to the super ctor

queen bear
#

oh

cyan osprey
#

that'd be width and height

regal dove
#

yep

queen bear
#

Here's the thing... at 0,0 an empty object is created that the player can click on, but where the item is, there isn't one.

cyan osprey
#

is its render function being called? I don't think I understand what you just said

queen bear
#

no it in init function

regal dove
#

did you pass an offset?

queen bear
regal dove
#

did you add it as a drawable?

queen bear
#

due to the displacement of problems there

queen bear
regal dove
#

check the positioning and offset, you've probably got the values wrong

queen bear
#

I can, like, manually put the value into a variable, but it feels like it shouldn't be that way.

#

It's just... well, it's strange. This method has probably been around for a long time, and I'm the first one to run into this kind of crap.

regal dove
#

it works just fine?

queen bear
#

and hold on 0 0 and click

#

So I fixed it, I think... wait, hold on...

regal dove
queen bear
#

what...

#

send this code

#

I'll try

regal dove
#

it's in the screenshot

#
var iw = new ItemDisplayWidget(minecraft, 0, 0, 16, 16, Component.empty(), new ItemStack(Items.ACACIA_STAIRS), false, false);
iw.setX(width/2);
addRenderableWidget(iw);
queen bear
#

bruh

#

now it working

#
        this.addRenderableWidget(
            ItemDisplayWidget(
                this.minecraft,
                0,
                0,
                50,
                50,
                item.customName ?: item.itemName,
                item,
                true,
                true
            ).apply {
                x = this.width / 2
                y = 50

//                val tooltipLines = getTooltipFromItem([email protected], item)
//
//                this.setTooltip(Tooltip.create(tooltipLines.first()))
            }
        )

this my old code

#

kotlin*