-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
beb3e02
commit 67fc7f0
Showing
8 changed files
with
89 additions
and
19 deletions.
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
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
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
61 changes: 61 additions & 0 deletions
61
src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.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,61 @@ | ||
package com.tanishisherewith.dynamichud.widgets; | ||
|
||
import com.tanishisherewith.dynamichud.config.GlobalConfig; | ||
import com.tanishisherewith.dynamichud.widget.Widget; | ||
import com.tanishisherewith.dynamichud.widget.WidgetData; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NbtCompound; | ||
|
||
public class ItemWidget extends Widget { | ||
public static WidgetData<?> DATA = new WidgetData<>("ItemWidget","Displays item texture", ItemWidget::new); | ||
public ItemStack item; | ||
|
||
public ItemWidget(ItemStack itemStack,String modId) { | ||
super(DATA, modId); | ||
this.item = itemStack; | ||
} | ||
public ItemWidget() { | ||
this(ItemStack.EMPTY, "empty"); | ||
} | ||
|
||
@Override | ||
public void renderWidget(DrawContext context, int mouseX, int mouseY) { | ||
context.drawItem(item,x,y); | ||
widgetBox.setSizeAndPosition(getX(), getY(), 16, 16, this.shouldScale, GlobalConfig.get().getScale()); | ||
} | ||
|
||
@Override | ||
public void writeToTag(NbtCompound tag) { | ||
super.writeToTag(tag); | ||
tag.putInt("ItemID",Item.getRawId(item.getItem())); | ||
} | ||
|
||
@Override | ||
public void readFromTag(NbtCompound tag) { | ||
super.readFromTag(tag); | ||
item = Item.byRawId(tag.getInt("ItemID")).getDefaultStack(); | ||
} | ||
|
||
public void setItemStack(ItemStack item) { | ||
this.item = item; | ||
} | ||
public static class Builder extends WidgetBuilder<Builder,ItemWidget>{ | ||
ItemStack itemStack; | ||
public Builder setItemStack(ItemStack itemStack) { | ||
this.itemStack = itemStack; | ||
return self(); | ||
} | ||
|
||
@Override | ||
protected Builder self() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public ItemWidget build() { | ||
return new ItemWidget(itemStack,modID); | ||
} | ||
} | ||
} |
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