Skip to content

Commit 64c7d1f

Browse files
Initial commit
0 parents  commit 64c7d1f

File tree

10 files changed

+1026
-0
lines changed

10 files changed

+1026
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.gradle
2+
gradle*
3+
eclipse
4+
.idea
5+
*.iml
6+
build
7+
classes
8+
run
9+
10+
workspace-1.12.2/src

LICENSE.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <http://unlicense.org>

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SimpleTabs
2+
3+
A minecraft mod adding easy-to-use chat tabs.
4+
5+
Project page: (Pending)
6+
7+
The default minecraft mechanics select a random item from your equipment that has the
8+
enchantment mending when you pickup experience orbs. However, the selected item might
9+
be fully repaired. If this is the case the collected experience is added to your
10+
experience bar and nothing is repaired.
11+
12+
This mod fixes this behavior by only selecting items which need to be repaired.
13+
14+
This mod requires Forge. It was tested with build #2623.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package nge.lk.mods.simpletabs;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
import net.minecraft.client.Minecraft;
6+
import net.minecraft.client.gui.GuiNewChat;
7+
import net.minecraft.util.text.ITextComponent;
8+
9+
import java.util.regex.Matcher;
10+
import java.util.regex.Pattern;
11+
12+
/**
13+
* Represents a chat tab.
14+
*/
15+
public class ChatTab extends GuiNewChat {
16+
17+
/**
18+
* The filter which selects the messages to accept.
19+
*/
20+
private Matcher filter;
21+
22+
/**
23+
* Whether this tab has unread messages.
24+
*/
25+
@Getter private boolean unread;
26+
27+
/**
28+
* The pattern string, for saving.
29+
*/
30+
@Getter private String pattern;
31+
32+
/**
33+
* Whether the pattern is literal, for saving.
34+
*/
35+
@Getter private boolean literal;
36+
37+
/**
38+
* The prefix for sent messages in this tab.
39+
*/
40+
@Getter @Setter private String prefix;
41+
42+
/**
43+
* Constructor.
44+
*
45+
* @param mc The minecraft reference.
46+
*/
47+
public ChatTab(final Minecraft mc, final String pattern, final boolean literal, final String prefix) {
48+
super(mc);
49+
this.pattern = pattern;
50+
this.literal = literal;
51+
this.prefix = prefix;
52+
filter = Pattern.compile(pattern, literal ? Pattern.LITERAL : 0).matcher("");
53+
}
54+
55+
/**
56+
* Updates the filter pattern.
57+
*
58+
* @param pattern The new pattern.
59+
* @param literal Whether the pattern will be escaped.
60+
*/
61+
public void updatePattern(final String pattern, final boolean literal) {
62+
this.pattern = pattern;
63+
this.literal = literal;
64+
filter = Pattern.compile(pattern, literal ? Pattern.LITERAL : 0).matcher("");
65+
}
66+
67+
@Override
68+
public void printChatMessageWithOptionalDeletion(final ITextComponent chatComponent, final int chatLineId) {
69+
super.printChatMessageWithOptionalDeletion(chatComponent, chatLineId);
70+
unread = true;
71+
}
72+
73+
/**
74+
* Whether this tab accepts the given message for display.
75+
*
76+
* @param message The message.
77+
*
78+
* @return Whether it is accepted.
79+
*/
80+
public boolean acceptsMessage(final CharSequence message) {
81+
filter.reset(message);
82+
return filter.find();
83+
}
84+
85+
/**
86+
* Marks this tab as read.
87+
*/
88+
public void markRead() {
89+
unread = false;
90+
}
91+
92+
/**
93+
* Returns the export part of this tab.
94+
*
95+
* @return The export string.
96+
*/
97+
public String getExport() {
98+
return pattern + "§" + Boolean.toString(literal) + "§" + prefix;
99+
}
100+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package nge.lk.mods.simpletabs;
2+
3+
import net.minecraft.client.Minecraft;
4+
import net.minecraft.client.gui.GuiNewChat;
5+
import net.minecraft.client.renderer.GlStateManager;
6+
import net.minecraft.util.text.ITextComponent;
7+
8+
import javax.annotation.Nullable;
9+
10+
/**
11+
* A chat with configurable tabs.
12+
*/
13+
public class GuiTabChat extends GuiNewChat {
14+
15+
/**
16+
* The tab manager.
17+
*/
18+
private final TabManager tabManager;
19+
20+
/**
21+
* Constructor.
22+
*
23+
* @param mc The minecraft instance.
24+
*/
25+
public GuiTabChat(final Minecraft mc, final TabManager tabManager) {
26+
super(mc);
27+
this.tabManager = tabManager;
28+
}
29+
30+
@Override
31+
public void drawChat(final int updateCounter) {
32+
tabManager.updateTabs(getChatScale());
33+
tabManager.getActiveChat().drawChat(updateCounter);
34+
35+
GlStateManager.pushMatrix();
36+
GlStateManager.translate(2.0F, 8.0F, 0.0F);
37+
GlStateManager.scale(getChatScale(), getChatScale(), 1.0f);
38+
39+
if (getChatOpen()) {
40+
tabManager.drawTabLabels();
41+
}
42+
43+
GlStateManager.popMatrix();
44+
}
45+
46+
@Override
47+
public void clearChatMessages(final boolean clearSent) {
48+
tabManager.getAllChats().forEach(chat -> chat.clearChatMessages(clearSent));
49+
}
50+
51+
@Override
52+
public void printChatMessageWithOptionalDeletion(final ITextComponent chatComponent, final int chatLineId) {
53+
tabManager.printChatMessageWithOptionalDeletion(chatComponent, chatLineId);
54+
}
55+
56+
@Override
57+
public void refreshChat() {
58+
tabManager.getAllChats().forEach(GuiNewChat::refreshChat);
59+
}
60+
61+
@Override
62+
public void addToSentMessages(String message) {
63+
final String prefix = tabManager.getActiveChat().getPrefix();
64+
65+
// Remove any artificially added prefix.
66+
if (!prefix.isEmpty() && message.startsWith(prefix)) {
67+
message = message.substring(prefix.length());
68+
}
69+
70+
super.addToSentMessages(message);
71+
}
72+
73+
@Override
74+
public void resetScroll() {
75+
tabManager.getAllChats().forEach(GuiNewChat::resetScroll);
76+
}
77+
78+
@Override
79+
public void scroll(final int amount) {
80+
tabManager.getActiveChat().scroll(amount);
81+
}
82+
83+
@Nullable
84+
@Override
85+
public ITextComponent getChatComponent(final int mouseX, final int mouseY) {
86+
return tabManager.getActiveChat().getChatComponent(mouseX, mouseY);
87+
}
88+
}

0 commit comments

Comments
 (0)