/
ToolsModule.java
234 lines (233 loc) · 10.7 KB
/
ToolsModule.java
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package com.lothrazar.cyclicmagic.module;
import com.lothrazar.cyclicmagic.ModMain;
import com.lothrazar.cyclicmagic.gui.wand.InventoryWand;
import com.lothrazar.cyclicmagic.item.ItemCyclicWand;
import com.lothrazar.cyclicmagic.item.ItemSleepingBag;
import com.lothrazar.cyclicmagic.item.ItemToolHarvest;
import com.lothrazar.cyclicmagic.item.ItemToolPearlReuse;
import com.lothrazar.cyclicmagic.item.ItemToolPush;
import com.lothrazar.cyclicmagic.item.ItemToolSpawnInspect;
import com.lothrazar.cyclicmagic.net.PacketSpellShiftLeft;
import com.lothrazar.cyclicmagic.net.PacketSpellShiftRight;
import com.lothrazar.cyclicmagic.registry.ItemRegistry;
import com.lothrazar.cyclicmagic.registry.SoundRegistry;
import com.lothrazar.cyclicmagic.registry.SpellRegistry;
import com.lothrazar.cyclicmagic.spell.ISpell;
import com.lothrazar.cyclicmagic.util.Const;
import com.lothrazar.cyclicmagic.util.UtilSound;
import com.lothrazar.cyclicmagic.util.UtilSpellCaster;
import com.lothrazar.cyclicmagic.util.UtilTextureRender;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ToolsModule extends BaseModule {
private static SpellHud spellHud;
private boolean enableSleepingMat;
private boolean enableToolPush;
private boolean enableHarvestLeaves;
private boolean enableToolHarvest;
private boolean enableHarvestWeeds;
private boolean enablePearlReuse;
private boolean enableSpawnInspect;
private boolean enableCyclicWand;
@Override
public void onInit() {
if (enableSpawnInspect) {
ItemRegistry.tool_spawn_inspect = new ItemToolSpawnInspect();
ItemRegistry.addItem(ItemRegistry.tool_spawn_inspect, "tool_spawn_inspect");
}
if (enablePearlReuse) {
ItemRegistry.ender_pearl_reuse = new ItemToolPearlReuse();
ItemRegistry.addItem(ItemRegistry.ender_pearl_reuse, "ender_pearl_reuse");
}
if (enableHarvestWeeds) {
ItemRegistry.tool_harvest_weeds = new ItemToolHarvest(ItemToolHarvest.HarvestType.WEEDS);
ItemRegistry.addItem(ItemRegistry.tool_harvest_weeds, "tool_harvest_weeds");
}
if (enableToolHarvest) {
ItemRegistry.tool_harvest_crops = new ItemToolHarvest(ItemToolHarvest.HarvestType.CROPS);
ItemRegistry.addItem(ItemRegistry.tool_harvest_crops, "tool_harvest_crops");
}
if (enableHarvestLeaves) {
ItemRegistry.tool_harvest_leaves = new ItemToolHarvest(ItemToolHarvest.HarvestType.LEAVES);
ItemRegistry.addItem(ItemRegistry.tool_harvest_leaves, "tool_harvest_leaves");
}
if (enableToolPush) {
ItemRegistry.tool_push = new ItemToolPush();
ItemRegistry.addItem(ItemRegistry.tool_push, "tool_push");
ModMain.instance.events.addEvent(ItemRegistry.tool_push);
}
if (enableSleepingMat) {
ItemRegistry.sleeping_mat = new ItemSleepingBag();
ItemRegistry.addItem(ItemRegistry.sleeping_mat, "sleeping_mat");
ModMain.instance.events.addEvent(ItemRegistry.sleeping_mat);
}
if (enableCyclicWand) {
ItemRegistry.cyclic_wand_build = new ItemCyclicWand();
ItemRegistry.addItem(ItemRegistry.cyclic_wand_build, "cyclic_wand_build");
SpellRegistry.register();
spellHud = new SpellHud();
ModMain.instance.events.addEvent(this);
}
}
@Override
public void syncConfig(Configuration config) {
ItemSleepingBag.doPotions = config.getBoolean("SleepingMatPotions", Const.ConfigCategory.items, true, "False will disable the potion effects given by the Sleeping Mat");
enableSpawnInspect = config.getBoolean("SpawnDetector", Const.ConfigCategory.content, true, Const.ConfigCategory.contentDefaultText);
enablePearlReuse = config.getBoolean("EnderOrb", Const.ConfigCategory.content, true, Const.ConfigCategory.contentDefaultText);
enableHarvestWeeds = config.getBoolean("BrushScythe", Const.ConfigCategory.content, true, Const.ConfigCategory.contentDefaultText);
enableToolHarvest = config.getBoolean("HarvestScythe", Const.ConfigCategory.content, true, Const.ConfigCategory.contentDefaultText);
enableHarvestLeaves = config.getBoolean("TreeScythe", Const.ConfigCategory.content, true, Const.ConfigCategory.contentDefaultText);
enableToolPush = config.getBoolean("PistonScepter", Const.ConfigCategory.content, true, Const.ConfigCategory.contentDefaultText);
enableSleepingMat = config.getBoolean("SleepingMat", Const.ConfigCategory.content, true, Const.ConfigCategory.contentDefaultText);
enableCyclicWand = config.getBoolean("CyclicWand", Const.ConfigCategory.content, true, Const.ConfigCategory.contentDefaultText);
}
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onMouseInput(MouseEvent event) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (!player.isSneaking() || event.getDwheel() == 0) { return; }
ItemStack wand = UtilSpellCaster.getPlayerWandIfHeld(player);
if (wand == null) { return; }
//if theres only one spell, do nothing
if (SpellRegistry.getSpellbook(wand) == null || SpellRegistry.getSpellbook(wand).size() <= 1) { return; }
if (event.getDwheel() < 0) {
ModMain.network.sendToServer(new PacketSpellShiftRight());
event.setCanceled(true);
UtilSound.playSound(player, player.getPosition(), SoundRegistry.bip);
}
else if (event.getDwheel() > 0) {
ModMain.network.sendToServer(new PacketSpellShiftLeft());
event.setCanceled(true);
UtilSound.playSound(player, player.getPosition(), SoundRegistry.bip);
}
}
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onRenderTextOverlay(RenderGameOverlayEvent.Text event) {
ItemStack wand = UtilSpellCaster.getPlayerWandIfHeld(Minecraft.getMinecraft().thePlayer);
// special new case: no hud for this type
if (wand != null) {
spellHud.drawSpellWheel(wand);
}
}
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onRender(RenderGameOverlayEvent.Post event) {
if (event.isCanceled() || event.getType() != ElementType.EXPERIENCE) { return; }
EntityPlayer effectivePlayer = Minecraft.getMinecraft().thePlayer;
ItemStack heldWand = UtilSpellCaster.getPlayerWandIfHeld(effectivePlayer);
if (heldWand == null) { return; }
RenderItem itemRender = Minecraft.getMinecraft().getRenderItem();
GlStateManager.color(1, 1, 1, 1);
RenderHelper.enableStandardItemLighting();
RenderHelper.enableGUIStandardItemLighting();
int itemSlot = ItemCyclicWand.BuildType.getSlot(heldWand);
ItemStack current = InventoryWand.getFromSlot(heldWand, itemSlot);
if (current != null) {
itemRender.renderItemAndEffectIntoGUI(current,
SpellHud.xoffset - 1, SpellHud.ymain + SpellHud.spellSize * 2);
}
RenderHelper.disableStandardItemLighting();
}
private class SpellHud {
private static final int xoffset = 14;//was 30 if manabar is showing
private static final int ymain = 6;
private static final int spellSize = 16;
private int xmain;
@SideOnly(Side.CLIENT)
public void drawSpellWheel(ItemStack wand) {
if (SpellRegistry.renderOnLeft) {
xmain = xoffset;
}
else {
ScaledResolution res = new ScaledResolution(Minecraft.getMinecraft());
xmain = res.getScaledWidth() - xoffset;
}
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
ISpell spellCurrent = UtilSpellCaster.getPlayerCurrentISpell(player);
//if theres only one spell, do not do the rest eh
if (SpellRegistry.getSpellbook(wand) == null || SpellRegistry.getSpellbook(wand).size() <= 1) { return; }
drawCurrentSpell(player, spellCurrent);
drawNextSpells(player, spellCurrent);
drawPrevSpells(player, spellCurrent);
}
private void drawCurrentSpell(EntityPlayer player, ISpell spellCurrent) {
UtilTextureRender.drawTextureSquare(spellCurrent.getIconDisplay(), xmain, ymain, spellSize);
}
private void drawPrevSpells(EntityPlayer player, ISpell spellCurrent) {
ItemStack wand = UtilSpellCaster.getPlayerWandIfHeld(player);
ISpell prev = SpellRegistry.prev(wand, spellCurrent);
if (prev != null) {
int x = xmain + 9;
int y = ymain + spellSize;
int dim = spellSize / 2;
UtilTextureRender.drawTextureSquare(prev.getIconDisplay(), x, y, dim);
prev = SpellRegistry.prev(wand, prev);
if (prev != null) {
x += 5;
y += 14;
dim -= 2;
UtilTextureRender.drawTextureSquare(prev.getIconDisplay(), x, y, dim);
prev = SpellRegistry.prev(wand, prev);
if (prev != null) {
x += 3;
y += 10;
dim -= 2;
UtilTextureRender.drawTextureSquare(prev.getIconDisplay(), x, y, dim);
prev = SpellRegistry.prev(wand, prev);
if (prev != null) {
x += 2;
y += 10;
dim -= 1;
UtilTextureRender.drawTextureSquare(prev.getIconDisplay(), x, y, dim);
}
}
}
}
}
private void drawNextSpells(EntityPlayer player, ISpell spellCurrent) {
ItemStack wand = UtilSpellCaster.getPlayerWandIfHeld(player);
ISpell next = SpellRegistry.next(wand, spellCurrent);
if (next != null) {
int x = xmain - 5;
int y = ymain + spellSize;
int dim = spellSize / 2;
UtilTextureRender.drawTextureSquare(next.getIconDisplay(), x, y, dim);
ISpell next2 = SpellRegistry.next(wand, next);
if (next2 != null) {
x -= 2;
y += 14;
dim -= 2;
UtilTextureRender.drawTextureSquare(next2.getIconDisplay(), x, y, dim);
ISpell next3 = SpellRegistry.next(wand, next2);
if (next3 != null) {
x -= 2;
y += 10;
dim -= 2;
UtilTextureRender.drawTextureSquare(next3.getIconDisplay(), x, y, dim);
ISpell next4 = SpellRegistry.next(wand, next3);
if (next4 != null) {
x -= 2;
y += 10;
dim -= 1;
UtilTextureRender.drawTextureSquare(next4.getIconDisplay(), x, y, dim);
}
}
}
}
}
}
}