Skip to content

Instantly share code, notes, and snippets.

@gamma-02
Created May 6, 2022 17:42
Show Gist options
  • Save gamma-02/96f50eae873dcaf77a360b61a09d715e to your computer and use it in GitHub Desktop.
Save gamma-02/96f50eae873dcaf77a360b61a09d715e to your computer and use it in GitHub Desktop.
import [...]
public class CleanerMenu extends AbstractContainerMenu {
private Inventory playerInv;
private CleanerBlockEntity instance;
public boolean isInstanceNull(){
return instance == null;
}
public CleanerMenu(int pContainerId, Inventory playerInv, BlockEntity temp) {
super(modBlockEntities.modScreenTypes.CleanerScreenType.get(), pContainerId);
if(temp instanceof CleanerBlockEntity instance) {
for(int i = 0; i < 3; ++i) {
for(int j = 0; j < 9; ++j) {
this.addSlot(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for(int k = 0; k < 9; ++k) {
this.addSlot(new Slot(playerInv, k, 8 + k * 18, 142));
}
this.addSlot(new Slot(instance, 0, 56, 17));
this.addSlot(new Slot(instance, 1, 56, 53));
this.addSlot(new Slot(instance, 2, 124, 24));
this.addSlot(new Slot(instance, 3, 124+9, 24));
this.addSlot(new Slot(instance, 4, 124+18, 24));
this.addSlot(new Slot(instance, 5, 124, 24+9));
this.addSlot(new Slot(instance, 6, 124+9, 24+9));
this.addSlot(new Slot(instance, 7, 124+18, 24+9));
this.instance = instance;
this.playerInv = playerInv;
}
}
public int getAmountOfFluid(){
if(this.instance != null)
return this.instance.fluid.getAmount();
return 0;
}
public boolean isCleaning(){
if(this.instance != null)
return this.instance.isCleaning();
return false;
}
public int getProgress(){
if(this.instance != null)
return this.instance.getProgress()/22/*or 24 idk which but if it doesn't work that's why lol*/;
return 0;
}
public CleanerMenu(int id, Inventory inventory) {
super(modBlockEntities.modScreenTypes.CleanerScreenType.get(), id);
for(int i = 0; i < 3; ++i) {
for(int j = 0; j < 9; ++j) {
this.addSlot(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for(int k = 0; k < 9; ++k) {
this.addSlot(new Slot(inventory, k, 8 + k * 18, 142));
}
this.playerInv = inventory;
}
@Override
public boolean stillValid(Player pPlayer) {
return true;
}
public void setInstance(CleanerBlockEntity entity){
this.instance = entity;
}
}
import [...]
public class CleanerScreen extends AbstractContainerScreen<CleanerMenu> {
private static final ResourceLocation TEXTURE = resource("textures/gui/cleaning_station.png");
private static final int progressBarXOffset = 176;
private static final int progressBarYOffset = 14;
private static final int fluidBarXOffset = 177;
private static final int fluidBarYOffset = 81;//move this DOWN
public CleanerScreen(CleanerMenu pMenu, Inventory pPlayerInventory, Component pTitle) {
super(pMenu, pPlayerInventory, pTitle);
this.itemRenderer = Minecraft.getInstance().getItemRenderer();
// BlockEntity tempOwner = pPlayerInventory.player.getCommandSenderWorld().getBlockEntity( pPlayerInventory.player.getCommandSenderWorld().clip(new ClipContext( pPlayerInventory.player.getLookAngle(), pPlayerInventory.player.getLookAngle().add(5, 5, 5), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, pPlayerInventory.player)).getBlockPos());
// pMenu.setInstance(tempOwner instanceof CleanerBlockEntity ? (CleanerBlockEntity) tempOwner : null);
}
public CleanerScreen(CleanerMenu menu, Inventory inv, Component title, BlockEntity entity){
super(menu, inv, title);
this.itemRenderer = Minecraft.getInstance().getItemRenderer();
this.minecraft = Minecraft.getInstance();
this.itemRenderer = minecraft.getItemRenderer();
this.font = minecraft.font;
if(entity instanceof CleanerBlockEntity e)
menu.setInstance(e);
}
@Override
protected void renderBg(PoseStack pPoseStack, float pPartialTick, int pMouseX, int pMouseY) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShaderTexture(0, TEXTURE);
int i = this.leftPos;
int j = this.topPos;
this.blit(pPoseStack, i, j, 0, 0, 175, 165);
boolean isInstanceNull = menu.isInstanceNull();
//render progress bar
if(!isInstanceNull && this.menu.isCleaning()){
int progress = menu.getProgress();
this.blit(pPoseStack, 78, 34, progressBarXOffset, progressBarYOffset, progress, 16/*or 17 if it doesn't work thats why*/);
}
//render fluid amount
if(!isInstanceNull && this.menu.getAmountOfFluid() > 0){
int fluidHeight = this.menu.getAmountOfFluid()/49;
this.blit(pPoseStack, 47, 68, fluidBarXOffset, fluidBarYOffset, 4, fluidHeight);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment