-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows command rune run some command after a delay.
Took 3 hours 36 minutes
- Loading branch information
Showing
16 changed files
with
354 additions
and
81 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
127 changes: 127 additions & 0 deletions
127
src/main/java/org/teacon/powertool/client/gui/widget/DelayCommandList.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,127 @@ | ||
package org.teacon.powertool.client.gui.widget; | ||
|
||
import net.minecraft.MethodsReturnNonnullByDefault; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.components.Button; | ||
import net.minecraft.client.gui.components.ContainerObjectSelectionList; | ||
import net.minecraft.client.gui.components.events.GuiEventListener; | ||
import net.minecraft.client.gui.narration.NarratableEntry; | ||
import net.minecraft.network.chat.Component; | ||
import org.teacon.powertool.client.gui.SetCommandScreen; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@ParametersAreNonnullByDefault | ||
@MethodsReturnNonnullByDefault | ||
public class DelayCommandList extends ContainerObjectSelectionList<DelayCommandList.CommandEntry> { | ||
|
||
private final SetCommandScreen screen; | ||
private int id = 0; | ||
|
||
public DelayCommandList(SetCommandScreen screen,int width,int y) { | ||
super(Minecraft.getInstance(), width,100,y,45); | ||
this.screen = screen; | ||
this.setX((int) (screen.width*0.3)); | ||
this.setRenderHeader(true,24); | ||
for(var data : screen.delayedCommands){ | ||
this.addEntry(new CommandEntry(id,data.delay(), data.command())); | ||
id++; | ||
} | ||
this.resize(); | ||
//this.addEntry(new AppendEntry()); | ||
} | ||
|
||
public void resize(){ | ||
this.setHeight(getHeight_()); | ||
this.updateSizeAndPosition(width,height,getY()); | ||
this.setX((int) (screen.width*0.3)); | ||
} | ||
|
||
public int getHeight_(){ | ||
return (int) Math.min(Math.max(100,24+45*id),screen.height*0.6); | ||
} | ||
|
||
public List<CommandEntry> entries(){ | ||
return children(); | ||
} | ||
|
||
public void appendEntry(){ | ||
this.addEntry(new CommandEntry(id,0,"")); | ||
id++; | ||
} | ||
|
||
public void removeEntry(int id){ | ||
var newEntries = new ArrayList<CommandEntry>(); | ||
int nid = 0; | ||
for(var entry : children()){ | ||
if(entry.id!=id){ | ||
newEntries.add(new CommandEntry(nid, entry.delay(),entry.command())); | ||
nid++; | ||
} | ||
} | ||
this.replaceEntries(newEntries); | ||
screen.refreshContentPos(); | ||
} | ||
|
||
@Override | ||
public int getRowWidth() { | ||
return width-4; | ||
} | ||
|
||
|
||
public class CommandEntry extends ContainerObjectSelectionList.Entry<CommandEntry> { | ||
public final int id; | ||
public final ObjectInputBox<Integer> delay_; | ||
public final ObjectInputBox<String> command_; | ||
protected final Button remove; | ||
|
||
public CommandEntry(int id,int delay,String command) { | ||
this.id = id; | ||
var box_l = (int)Math.max(100,DelayCommandList.this.screen.width*0.4); | ||
this.delay_ = new ObjectInputBox<>(Minecraft.getInstance().font,-1,-1,(box_l-20)/2,20,Component.literal("delay"),ObjectInputBox.INT_VALIDATOR,ObjectInputBox.INT_RESPONDER); | ||
this.delay_.setMaxLength(4); | ||
this.delay_.setValue(String.valueOf(delay)); | ||
this.command_ = new ObjectInputBox<>(Minecraft.getInstance().font,-1,-1,box_l-20,20,Component.literal("command"),ObjectInputBox.PASS_VALIDATOR,ObjectInputBox.PASS_RESPONDER); | ||
this.command_.setMaxLength(114514); | ||
this.command_.setRenderState(false); | ||
this.command_.setValue(command); | ||
this.remove = Button.builder(Component.literal("-"),(b) -> { | ||
DelayCommandList.this.removeEntry(id); | ||
} ).size(20,20).build(); | ||
} | ||
|
||
|
||
@Override | ||
public List<? extends NarratableEntry> narratables() { | ||
return List.of(delay_,command_,remove); | ||
} | ||
|
||
@Override | ||
public void render(GuiGraphics guiGraphics, int index, int top, int left, int width, int height, int mouseX, int mouseY, boolean hovering, float partialTick) { | ||
var sx = DelayCommandList.this.getX(); | ||
this.delay_.setPosition(sx+20,top); | ||
this.delay_.render(guiGraphics, mouseX, mouseY, partialTick); | ||
this.command_.setPosition(sx+20,top+20); | ||
this.command_.render(guiGraphics, mouseX, mouseY, partialTick); | ||
this.remove.setPosition(sx+DelayCommandList.this.getWidth()-50,top); | ||
this.remove.render(guiGraphics, mouseX, mouseY, partialTick); | ||
} | ||
|
||
@Override | ||
public List<? extends GuiEventListener> children() { | ||
return List.of(delay_,command_,remove); | ||
} | ||
|
||
public int delay(){ | ||
return Objects.requireNonNullElse(this.delay_.get(),0); | ||
} | ||
|
||
public String command(){ | ||
return Objects.requireNonNullElse(this.command_.get(),""); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.