| 1 | package net.encode.wurmesp.feature.hook; |
| 2 | |
| 3 | import java.lang.reflect.Field; |
| 4 | import java.util.logging.Level; |
| 5 | |
| 6 | import org.gotti.wurmunlimited.modloader.ReflectionUtil; |
| 7 | |
| 8 | import com.wurmonline.client.renderer.GroundItemData; |
| 9 | |
| 10 | import net.encode.wurmesp.Unit; |
| 11 | import net.encode.wurmesp.WurmEspMod; |
| 12 | |
| 13 | public class GroundItemCellRenderableRemove |
| 14 | extends Hook { |
| 15 | public GroundItemCellRenderableRemove() { |
| 16 | this.prepareHook("com.wurmonline.client.renderer.cell.GroundItemCellRenderable", "removed", "(Z)V", () -> (proxy, method, args) -> { |
| 17 | method.invoke(proxy, args); |
| 18 | Class<?> cls = proxy.getClass(); |
| 19 | GroundItemData item = (GroundItemData)ReflectionUtil.getPrivateField((Object)proxy, (Field)ReflectionUtil.getField(cls, (String)"item")); |
| 20 | for (Unit unit : WurmEspMod.pickableUnits) { |
| 21 | if (unit.getId() != item.getId()) continue; |
| 22 | WurmEspMod.toRemove.add(unit); |
| 23 | } |
| 24 | for (Unit unit : WurmEspMod.toRemove) { |
| 25 | if (unit.getId() != item.getId()) continue; |
| 26 | WurmEspMod.pickableUnits.remove(unit); |
| 27 | } |
| 28 | WurmEspMod.toRemove.clear(); |
| 29 | return null; |
| 30 | }); |
| 31 | WurmEspMod.logger.log(Level.INFO, "[WurmEspMod] GroundItemCellRenderable.removed hooked"); |
| 32 | } |
| 33 | } |
| 34 | |