1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/*
* KubaTech - Gregtech Addon Copyright (C) 2022 - 2023 kuba6000 This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later version. This library is distributed in
* the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have
* received a copy of the GNU Lesser General Public License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
package kubatech.loaders.item.items;
import java.text.NumberFormat;
import kubatech.api.enums.ItemList;
import kubatech.api.utils.ModUtils;
import kubatech.api.utils.StringUtils;
import kubatech.loaders.item.IItemProxyGUI;
import kubatech.savedata.PlayerData;
import kubatech.savedata.PlayerDataManager;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import com.gtnewhorizons.modularui.api.ModularUITextures;
import com.gtnewhorizons.modularui.api.drawable.IDrawable;
import com.gtnewhorizons.modularui.api.drawable.ItemDrawable;
import com.gtnewhorizons.modularui.api.drawable.Text;
import com.gtnewhorizons.modularui.api.math.Color;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.widget.Widget;
import com.gtnewhorizons.modularui.common.widget.*;
public class TeaUltimate extends TeaCollection implements IItemProxyGUI {
public TeaUltimate() {
super("ultimate_tea");
}
private static String name = "";
private static long timeCounter = 0;
private static int colorCounter = 0;
public static String getUltimateTeaDisplayName(String displayName) {
long current = System.currentTimeMillis();
if (current - timeCounter > 100) {
timeCounter = current;
name = StringUtils.applyRainbow(
"ULTIMATE",
colorCounter++,
EnumChatFormatting.BOLD.toString() + EnumChatFormatting.OBFUSCATED);
}
return String.format(displayName, name + EnumChatFormatting.RESET);
}
@Override
public String getDisplayName(ItemStack stack) {
if (!ModUtils.isClientSided) return super.getDisplayName(stack);
if (checkTeaOwner(stack, Minecraft.getMinecraft().thePlayer.getCommandSenderName())) {
return getUltimateTeaDisplayName(super.getDisplayName(stack));
}
return EnumChatFormatting.GOLD + "" + EnumChatFormatting.BOLD + "" + EnumChatFormatting.ITALIC + "???????";
}
@Override
public ModularWindow createWindow(ItemStack stack, EntityPlayer player) {
ModularWindow.Builder builder = ModularWindow.builder(200, 150);
builder.setBackground(ModularUITextures.VANILLA_BACKGROUND);
final PlayerData playerData = PlayerDataManager.getPlayer(player.getCommandSenderName());
IDrawable tab1 = new ItemDrawable(ItemList.LegendaryUltimateTea.get(1)).withFixedSize(18, 18, 4, 6);
IDrawable tab2 = new ItemDrawable(new ItemStack(Blocks.crafting_table)).withFixedSize(18, 18, 4, 6);
IDrawable tab3 = new ItemDrawable(new ItemStack(Items.golden_apple)).withFixedSize(18, 18, 4, 6);
builder.widget(
new TabContainer()
.setButtonSize(
28,
32)
.addTabButton(
new TabButton(0)
.setBackground(
false,
ModularUITextures.VANILLA_TAB_TOP_START.getSubArea(0, 0, 1f, 0.5f),
tab1)
.setBackground(
true,
ModularUITextures.VANILLA_TAB_TOP_START.getSubArea(0, 0.5f, 1f, 1f),
tab1)
.setPos(0, -28))
.addTabButton(
new TabButton(1)
.setBackground(
false,
ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f),
tab2)
.setBackground(
true,
ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f),
tab2)
.setPos(28, -28))
.addTabButton(
new TabButton(2)
.setBackground(
false,
ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f),
tab3)
.setBackground(
true,
ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f),
tab3)
.setPos(56, -28))
.addPage(
new MultiChildWidget()
.addChild(
new TextWidget(
new Text("STATUS").format(EnumChatFormatting.BOLD)
.format(EnumChatFormatting.GOLD).shadow())
.setPos(10, 5))
.addChild(
new DynamicTextWidget(
() -> new Text(
"Tea: " + (playerData == null ? "ERROR"
: NumberFormat.getInstance()
.format(playerData.teaAmount)))
.color(Color.GREEN.normal))
.setPos(20, 20)))
.addPage(
new MultiChildWidget()
.addChild(
new TextWidget(
new Text("EXCHANGE").format(EnumChatFormatting.BOLD)
.format(EnumChatFormatting.GOLD).shadow())
.setPos(10, 5))
.addChild(
new ButtonWidget()
.setOnClick((Widget.ClickData clickData, Widget widget) -> {
if (!(player instanceof EntityPlayerMP)) return;
if (playerData == null || playerData.teaAmount < 50_000L)
return;
playerData.teaAmount -= 50_000L;
playerData.markDirty();
if (player.inventory.addItemStackToInventory(
ItemList.TeaAcceptorResearchNote.get(1)))
return;
player.entityDropItem(
ItemList.TeaAcceptorResearchNote.get(1),
0.5f);
})
.setBackground(
new ItemDrawable().setItem(
ItemList.TeaAcceptorResearchNote.get(1)))
.addTooltip("Tea Acceptor Research Note")
.addTooltip(
new Text(
"Cost: " + NumberFormat.getInstance()
.format(50_000) + " Tea")
.color(Color.GRAY.normal))
.setPos(20, 20)))
.addPage(
new MultiChildWidget().addChild(
new TextWidget(
new Text("BENEFITS").format(EnumChatFormatting.BOLD)
.format(EnumChatFormatting.GOLD).shadow()).setPos(10, 5))
/*
* .addChild(new ButtonWidget() .setOnClick((Widget.ClickData clickData, Widget widget) -> { if
* (!(player instanceof EntityPlayerMP)) return; if (playerData == null) return;
* playerData.autoRegen = !playerData.autoRegen; playerData.markDirty(); }) .setBackground(new
* ItemDrawable().setItem(new ItemStack(Items.potionitem, 1, 8193)))
* .addTooltip("Regeneration I") .addTooltip("For 1 minute") .addTooltip(new Text("Cost: " +
* NumberFormat.getInstance().format(75_000) + " Tea") .color(Color.GRAY.normal)) //
* .addTooltip( //Find a way to run that on server, or different approach // new
* Text("Autobuy: " + (playerData == null ? "ERROR" : playerData.autoRegen)) //
* .color(Color.GREY.normal)) .setPos(20, 20))
*/ ));
return builder.build();
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer entity) {
if (world.isRemote) return stack;
if (!(entity instanceof EntityPlayerMP)) return stack;
if (!checkTeaOwner(stack, entity.getCommandSenderName())) return stack;
openHeldItemGUI(entity);
return stack;
}
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isCurrentItem) {
if (world.isRemote) return;
if (!(entity instanceof EntityPlayerMP)) return;
super.onUpdate(stack, world, entity, slot, isCurrentItem);
if (checkTeaOwner(stack, entity.getCommandSenderName())) {
PlayerData playerData = PlayerDataManager.getPlayer(entity.getCommandSenderName());
if (playerData == null) return;
playerData.teaAmount++;
playerData.markDirty();
if (playerData.autoRegen && playerData.teaAmount > 75_000) {
if (((EntityPlayerMP) entity).getActivePotionEffect(Potion.regeneration) == null) {
((EntityPlayerMP) entity).addPotionEffect(new PotionEffect(Potion.regeneration.id, 1200, 0, true));
playerData.teaAmount -= 75_000;
}
}
}
}
}
|