Clean
[esp.git] / src / net / encode / wurmesp / feature / hook / GroundItemCellRenderableInit.java
CommitLineData
82327c1d 1package net.encode.wurmesp.feature.hook;
2
3import com.wurmonline.client.renderer.GroundItemData;
4import com.wurmonline.client.renderer.PickableUnit;
5import com.wurmonline.client.renderer.cell.CellRenderable;
6
7import java.lang.reflect.Field;
8import java.util.logging.Level;
9import net.encode.wurmesp.Unit;
10import net.encode.wurmesp.WurmEspMod;
11import net.encode.wurmesp.util.SoundUtils;
12import org.gotti.wurmunlimited.modloader.ReflectionUtil;
13
14public class GroundItemCellRenderableInit
15extends Hook {
16 public GroundItemCellRenderableInit() {
17 this.prepareHook("com.wurmonline.client.renderer.cell.GroundItemCellRenderable", "initialize", "()V", () -> (proxy, method, args) -> {
18 method.invoke(proxy, args);
19 Class<?> cls = proxy.getClass();
20 PickableUnit pUnit = (PickableUnit)proxy;
21 GroundItemData item = (GroundItemData)ReflectionUtil.getPrivateField((Object)proxy, (Field)ReflectionUtil.getField(cls, (String)"item"));
22 Unit unit = new Unit(CellRenderable.world, item.getId(), pUnit, item.getModelName().toString(), ((PickableUnit)proxy).getHoverName());
23 if (unit.isSpecial()) {
24 WurmEspMod.pickableUnits.add(unit);
25 if (WurmEspMod.specials && WurmEspMod.playsoundspecial) {
26 SoundUtils.playSound(WurmEspMod.soundspecial);
27 }
28 } else if (unit.isSpotted()) {
29 WurmEspMod.pickableUnits.add(unit);
30 if (WurmEspMod.items && WurmEspMod.playsounditem) {
31 SoundUtils.playSound(WurmEspMod.sounditem);
32 }
33 }
34 return null;
35 });
36 WurmEspMod.logger.log(Level.INFO, "[WurmEspMod] GroundItemCellRenderable.initialize hooked");
37 }
38}
39