SHARE
TWEET

ClientModContext.java

GorgeousFreeman Dec 12th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.vicmatskiv.weaponlib;
  2.  
  3. import com.vicmatskiv.weaponlib.AttachmentManager;
  4. import com.vicmatskiv.weaponlib.ClientEventHandler;
  5. import com.vicmatskiv.weaponlib.ClientWeaponTicker;
  6. import com.vicmatskiv.weaponlib.CommonModContext;
  7. import com.vicmatskiv.weaponlib.CustomGui;
  8. import com.vicmatskiv.weaponlib.FireManager;
  9. import com.vicmatskiv.weaponlib.KeyBindings;
  10. import com.vicmatskiv.weaponlib.ModContext;
  11. import com.vicmatskiv.weaponlib.ModelSourceRenderer;
  12. import com.vicmatskiv.weaponlib.ReloadManager;
  13. import com.vicmatskiv.weaponlib.RenderingRegistry;
  14. import com.vicmatskiv.weaponlib.SafeGlobals;
  15. import com.vicmatskiv.weaponlib.SpawnEntityRenderer;
  16. import com.vicmatskiv.weaponlib.Weapon;
  17. import com.vicmatskiv.weaponlib.WeaponClientStorageManager;
  18. import com.vicmatskiv.weaponlib.WeaponEventHandler;
  19. import com.vicmatskiv.weaponlib.WeaponRenderer;
  20. import com.vicmatskiv.weaponlib.WeaponResourcePack;
  21. import com.vicmatskiv.weaponlib.WeaponSpawnEntity;
  22. import java.util.List;
  23. import java.util.Queue;
  24. import java.util.concurrent.LinkedBlockingQueue;
  25. import java.util.concurrent.locks.Lock;
  26. import java.util.concurrent.locks.ReentrantLock;
  27. import net.minecraft.client.Minecraft;
  28. import net.minecraft.client.entity.EntityPlayerSP;
  29. import net.minecraft.client.renderer.entity.Render;
  30. import net.minecraft.client.renderer.entity.RenderManager;
  31. import net.minecraft.entity.player.EntityPlayer;
  32. import net.minecraft.item.Item;
  33. import net.minecraftforge.client.model.ICustomModelLoader;
  34. import net.minecraftforge.client.model.ModelLoaderRegistry;
  35. import net.minecraftforge.common.MinecraftForge;
  36. import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
  37. import net.minecraftforge.fml.common.eventhandler.EventBus;
  38. import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
  39. import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
  40. import net.minecraftforge.fml.common.registry.EntityRegistry;
  41.  
  42. public class ClientModContext
  43. extends CommonModContext {
  44.     private ClientEventHandler clientEventHandler;
  45.     private Lock mainLoopLock = new ReentrantLock();
  46.     private int modEntityID;
  47.     private WeaponClientStorageManager weaponClientStorageManager;
  48.     private Queue runInClientThreadQueue = new LinkedBlockingQueue<Runnable>();
  49.     private RenderingRegistry rendererRegistry;
  50.  
  51.     @Override
  52.     public void init(Object mod, String modId, SimpleNetworkWrapper channel) {
  53.         super.init(mod, modId, channel);
  54.         rendererRegistry = new RenderingRegistry(modId);
  55.         ModelLoaderRegistry.registerLoader((ICustomModelLoader)rendererRegistry);
  56.         List defaultResourcePacks = (List)ObfuscationReflectionHelper.getPrivateValue(Minecraft.class, Minecraft.getMinecraft(), (String[])new String[]{"defaultResourcePacks", "defaultResourcePacks"});
  57.         defaultResourcePacks.add(new WeaponResourcePack());
  58.         weaponClientStorageManager = new WeaponClientStorageManager();
  59.         SafeGlobals safeGlobals = new SafeGlobals();
  60.         MinecraftForge.EVENT_BUS.register(new CustomGui(Minecraft.getMinecraft(), this.attachmentManager));
  61.         MinecraftForge.EVENT_BUS.register(new WeaponEventHandler(safeGlobals));
  62.         KeyBindings.init();
  63.         ClientWeaponTicker clientWeaponTicker = new ClientWeaponTicker(safeGlobals, this.fireManager, this.reloadManager);
  64.         Runtime.getRuntime().addShutdownHook(new Thread(() -> {
  65.             clientWeaponTicker.shutdown();
  66.         }
  67.         ));
  68.         //clientWeaponTicker.start();
  69.         clientEventHandler = new ClientEventHandler(this, mainLoopLock, safeGlobals, runInClientThreadQueue);
  70.         MinecraftForge.EVENT_BUS.register(this.clientEventHandler);
  71.         MinecraftForge.EVENT_BUS.register(this.rendererRegistry);
  72.         EntityRegistry.registerModEntity(WeaponSpawnEntity.class, (String)("Ammo" + this.modEntityID), (int)this.modEntityID++, mod, (int)64, (int)10, (boolean)true);
  73.         //net.minecraftforge.fml.client.registry.RenderingRegistry.registerEntityRenderingHandler(WeaponSpawnEntity.class, (Render)new SpawnEntityRenderer(Minecraft.getMinecraft().getRenderManager()));
  74.     }
  75.  
  76.     @Override
  77.     public void registerWeapon(String name, Weapon weapon) {
  78.         super.registerWeapon(name, weapon);
  79.         this.rendererRegistry.register(weapon, weapon.getName(), weapon.getRenderer());
  80.     }
  81.  
  82.     @Override
  83.     public void registerRenderableItem(String name, Item item, ModelSourceRenderer renderer) {
  84.         this.rendererRegistry.register(item, name, renderer);
  85.     }
  86.  
  87.     @Override
  88.     protected EntityPlayer getPlayer(MessageContext ctx) {
  89.         return Minecraft.getMinecraft().thePlayer;
  90.     }
  91.  
  92.     @Override
  93.     public void runSyncTick(Runnable runnable) {
  94.         this.mainLoopLock.lock();
  95.         try {
  96.             runnable.run();
  97.         }
  98.         finally {
  99.             this.mainLoopLock.unlock();
  100.         }
  101.     }
  102.  
  103.     @Override
  104.     public void runInMainThread(Runnable runnable) {
  105.         this.runInClientThreadQueue.add(runnable);
  106.     }
  107.  
  108.     @Override
  109.     public WeaponClientStorageManager getWeaponClientStorageManager() {
  110.         return this.weaponClientStorageManager;
  111.     }
  112. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top