Advertisement
SparkyFox95

ServerMod Classes

Feb 23rd, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.50 KB | None | 0 0
  1. =================================================================================================================================================================================================== CLIENT PROXY =========================================================
  2. =====================================================================================================================================
  3.  
  4.  
  5. package mod.sparkyfox.servermod;
  6.  
  7. import mod.sparkyfox.servermod.entity.EntitySMGRounds;
  8. import mod.sparkyfox.servermod.init.ModItems;
  9. import mod.sparkyfox.servermod.render.RenderSMGRounds;
  10. import net.minecraft.client.Minecraft;
  11. import net.minecraft.client.renderer.entity.Render;
  12. import net.minecraft.client.renderer.entity.RenderManager;
  13. import net.minecraftforge.fml.client.registry.IRenderFactory;
  14. import net.minecraftforge.fml.client.registry.RenderingRegistry;
  15. import net.minecraftforge.fml.common.event.FMLInitializationEvent;
  16. import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
  17. import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
  18.  
  19.  
  20. public class ClientProxy extends CommonProxy {
  21.  
  22.  
  23. @Override
  24. public void preInit(FMLPreInitializationEvent event) {
  25. super.preInit(event);
  26. RenderingRegistry.registerEntityRenderingHandler(EntitySMGRounds.class, new IRenderFactory<EntitySMGRounds>() {
  27. @Override
  28. public Render<? super EntitySMGRounds> createRenderFor(RenderManager manager) {
  29. return new RenderSMGRounds(manager);
  30. }
  31. });
  32.  
  33. }
  34.  
  35. @Override
  36. public void init(FMLInitializationEvent event) {
  37. super.init(event);
  38. ModItems.initClient(Minecraft.getMinecraft().getRenderItem().getItemModelMesher());
  39.  
  40. }
  41.  
  42. @Override
  43. public void postInit(FMLPostInitializationEvent event) {
  44. super.postInit(event);
  45.  
  46. }
  47.  
  48.  
  49. }
  50.  
  51.  
  52.  
  53.  
  54. =================================================================================================================================================================================================== COMMON PROXY =========================================================
  55. =====================================================================================================================================
  56.  
  57.  
  58. package mod.sparkyfox.servermod;
  59.  
  60. import mod.sparkyfox.servermod.init.ModEntities;
  61. import mod.sparkyfox.servermod.init.ModItems;
  62. import net.minecraftforge.fml.common.event.FMLInitializationEvent;
  63. import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
  64. import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
  65.  
  66. public class CommonProxy {
  67.  
  68. public void preInit(FMLPreInitializationEvent event) {
  69. ModItems.init();
  70. ModEntities.init();
  71.  
  72. }
  73.  
  74. public void init(FMLInitializationEvent event) {
  75. ModItems.initRecipes();
  76.  
  77.  
  78.  
  79. }
  80.  
  81. public void postInit(FMLPostInitializationEvent event) {
  82.  
  83. }
  84.  
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. =================================================================================================================================================================================================== SERVER MOD ===========================================================
  93. =====================================================================================================================================
  94.  
  95.  
  96. package mod.sparkyfox.servermod;
  97.  
  98. import java.util.Random;
  99.  
  100. import mod.sparkyfox.servermod.init.ModEntities;
  101. import mod.sparkyfox.servermod.init.ModSoundEvent;
  102. import net.minecraft.client.audio.Sound;
  103. import net.minecraft.entity.Entity;
  104. import net.minecraft.item.Item.ToolMaterial;
  105. import net.minecraftforge.common.util.EnumHelper;
  106. import net.minecraftforge.fml.common.Mod;
  107. import net.minecraftforge.fml.common.Mod.EventHandler;
  108. import net.minecraftforge.fml.common.Mod.Instance;
  109. import net.minecraftforge.fml.common.SidedProxy;
  110. import net.minecraftforge.fml.common.event.FMLInitializationEvent;
  111. import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
  112. import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
  113.  
  114. @Mod(modid = ServerMod.MOD_ID,
  115. name = ServerMod.MOD_NAME,
  116. version = ServerMod.VERSION)
  117. public class ServerMod {
  118.  
  119.  
  120. // Constants
  121. public static final String MOD_ID = "servermod";
  122. public static final String MOD_NAME = "Sparky's Mod";
  123. public static final String VERSION = "ALPHA";
  124. public static final String RESOURCE_PREFIX = MOD_ID.toLowerCase() + ":"; // servermod:
  125.  
  126. @Instance(MOD_ID)
  127. public static ServerMod INSTANCE = new ServerMod();
  128.  
  129.  
  130. // Variables
  131. public static Random random = new Random();
  132.  
  133. @Instance(MOD_ID)
  134. public static ServerMod instance;
  135.  
  136. @SidedProxy(clientSide = "mod.sparkyfox.servermod.ClientProxy", serverSide = "mod.sparkyfox.servermod.CommonProxy")
  137. public static CommonProxy proxy;
  138. @SuppressWarnings("unused")
  139. private ModSoundEvent sounds;
  140.  
  141.  
  142.  
  143. @EventHandler
  144. public void preInit(FMLPreInitializationEvent event) {
  145. proxy.preInit(event);
  146. sounds = new ModSoundEvent();
  147.  
  148.  
  149.  
  150. }
  151. @EventHandler
  152. public void init(FMLInitializationEvent event) {
  153. proxy.init(event);
  154.  
  155.  
  156.  
  157.  
  158. }
  159. @EventHandler
  160. public void PostInit(FMLPostInitializationEvent event) {
  161. proxy.postInit(event);
  162.  
  163.  
  164. }
  165.  
  166. }
  167.  
  168.  
  169.  
  170.  
  171.  
  172. =================================================================================================================================================================================================== Render SMGRounds =====================================================
  173. =====================================================================================================================================
  174.  
  175.  
  176. package mod.sparkyfox.servermod.render;
  177.  
  178. import java.util.Random;
  179.  
  180. import net.minecraft.client.renderer.GlStateManager;
  181. import net.minecraft.client.renderer.Tessellator;
  182. import net.minecraft.client.renderer.VertexBuffer;
  183. import net.minecraft.client.renderer.entity.Render;
  184. import net.minecraft.client.renderer.entity.RenderManager;
  185. import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
  186. import net.minecraft.entity.projectile.EntityArrow;
  187. import net.minecraft.util.ResourceLocation;
  188. import net.minecraft.util.math.MathHelper;
  189. import net.minecraft.util.math.Vec3d;
  190. import net.minecraftforge.fml.relauncher.Side;
  191. import net.minecraftforge.fml.relauncher.SideOnly;
  192.  
  193. @SideOnly(Side.CLIENT)
  194. public class RenderSMGRounds<T extends EntityArrow> extends Render<T> {
  195.  
  196. private static final ResourceLocation arrowTextures = new ResourceLocation("textures/entity/smgrounds.png");
  197.  
  198. private static final Random rand = new Random();
  199.  
  200. public RenderSMGRounds(RenderManager renderManager) {
  201. super(renderManager);
  202. }
  203.  
  204. /**
  205. * Renders the desired {@code T} type Entity.
  206. */
  207. public void doRender(T entity, double x, double y, double z, float entityYaw, float partialTicks) {
  208. this.bindEntityTexture(entity);
  209. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  210. GlStateManager.pushMatrix();
  211. GlStateManager.disableLighting();
  212. GlStateManager.translate((float) x, (float) y, (float) z);
  213. GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks - 90.0F, 0.0F, 1.0F, 0.0F);
  214. GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, 0.0F, 0.0F, 1.0F);
  215. Tessellator tessellator = Tessellator.getInstance();
  216. VertexBuffer vertexbuffer = tessellator.getBuffer();
  217. int i = 0;
  218. float f = 0.0F;
  219. float f1 = 0.5F;
  220. float f2 = 0.0F;
  221. float f3 = 0.15625F;
  222. float f4 = 0.0F;
  223. float f5 = 0.15625F;
  224. float f6 = 0.15625F;
  225. float f7 = 0.3125F;
  226. float f8 = 0.05625F;
  227. GlStateManager.enableRescaleNormal();
  228. float f9 = (float) entity.arrowShake - partialTicks;
  229.  
  230. if (f9 > 0.0F) {
  231. float f10 = -MathHelper.sin(f9 * 3.0F) * f9;
  232. GlStateManager.rotate(f10, 0.0F, 0.0F, 1.0F);
  233. }
  234.  
  235. GlStateManager.rotate(45.0F, 1.0F, 0.0F, 0.0F);
  236. GlStateManager.scale(0.05625F, 0.05625F, 0.05625F);
  237. GlStateManager.translate(-4.0F, 0.0F, 0.0F);
  238.  
  239. if (this.renderOutlines) {
  240. GlStateManager.enableColorMaterial();
  241. GlStateManager.enableOutlineMode(this.getTeamColor(entity));
  242. }
  243.  
  244. GlStateManager.glNormal3f(0.05625F, 0.0F, 0.0F);
  245. vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
  246. vertexbuffer.pos(-7.0D, -2.0D, -2.0D).tex(0.0D, 0.15625D).endVertex();
  247. vertexbuffer.pos(-7.0D, -2.0D, 2.0D).tex(0.15625D, 0.15625D).endVertex();
  248. vertexbuffer.pos(-7.0D, 2.0D, 2.0D).tex(0.15625D, 0.3125D).endVertex();
  249. vertexbuffer.pos(-7.0D, 2.0D, -2.0D).tex(0.0D, 0.3125D).endVertex();
  250. tessellator.draw();
  251. GlStateManager.glNormal3f(-0.05625F, 0.0F, 0.0F);
  252. vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
  253. vertexbuffer.pos(-7.0D, 2.0D, -2.0D).tex(0.0D, 0.15625D).endVertex();
  254. vertexbuffer.pos(-7.0D, 2.0D, 2.0D).tex(0.15625D, 0.15625D).endVertex();
  255. vertexbuffer.pos(-7.0D, -2.0D, 2.0D).tex(0.15625D, 0.3125D).endVertex();
  256. vertexbuffer.pos(-7.0D, -2.0D, -2.0D).tex(0.0D, 0.3125D).endVertex();
  257. tessellator.draw();
  258.  
  259. for (int j = 0; j < 4; ++j) {
  260. GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);
  261. GlStateManager.glNormal3f(0.0F, 0.0F, 0.05625F);
  262. vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
  263. vertexbuffer.pos(-8.0D, -2.0D, 0.0D).tex(0.0D, 0.0D).endVertex();
  264. vertexbuffer.pos(8.0D, -2.0D, 0.0D).tex(0.5D, 0.0D).endVertex();
  265. vertexbuffer.pos(8.0D, 2.0D, 0.0D).tex(0.5D, 0.15625D).endVertex();
  266. vertexbuffer.pos(-8.0D, 2.0D, 0.0D).tex(0.0D, 0.15625D).endVertex();
  267. tessellator.draw();
  268. }
  269.  
  270. if (this.renderOutlines) {
  271. GlStateManager.disableOutlineMode();
  272. GlStateManager.disableColorMaterial();
  273. }
  274.  
  275. GlStateManager.disableRescaleNormal();
  276. GlStateManager.enableLighting();
  277. GlStateManager.popMatrix();
  278. super.doRender(entity, x, y, z, entityYaw, partialTicks);
  279. Vec3d vec = entity.getLook(1.0F);
  280. for (int index = 0; index < 20; index++);
  281.  
  282. }
  283.  
  284. @Override
  285. protected ResourceLocation getEntityTexture(T entity) {
  286. return arrowTextures;
  287. }
  288. }
  289.  
  290.  
  291. =================================================================================================================================================================================================== Item SMGRounds ======================================================
  292. =====================================================================================================================================
  293.  
  294.  
  295. package mod.sparkyfox.servermod.item;
  296.  
  297. import javax.annotation.Nonnull;
  298.  
  299. import mod.sparkyfox.servermod.ServerMod;
  300. import mod.sparkyfox.servermod.entity.EntitySMGRounds;
  301. import mod.sparkyfox.servermod.lib.ModNames;
  302. import net.minecraft.creativetab.CreativeTabs;
  303. import net.minecraft.entity.EntityLivingBase;
  304. import net.minecraft.entity.player.EntityPlayer;
  305. import net.minecraft.entity.projectile.EntityArrow;
  306. import net.minecraft.entity.projectile.EntityTippedArrow;
  307. import net.minecraft.init.Blocks;
  308. import net.minecraft.init.Items;
  309. import net.minecraft.item.ItemArrow;
  310. import net.minecraft.item.ItemStack;
  311. import net.minecraft.world.World;
  312. import net.minecraftforge.fml.common.registry.GameRegistry;
  313.  
  314. public class ItemSMGRounds extends ItemArrow {
  315.  
  316.  
  317.  
  318.  
  319. @Override
  320. public String getUnlocalizedName(ItemStack stack) {
  321.  
  322. return "SMGRounds" + ServerMod.RESOURCE_PREFIX + ModNames.SMGRounds;
  323.  
  324. }
  325.  
  326. public ItemSMGRounds()
  327. {
  328. this.setCreativeTab(CreativeTabs.COMBAT);
  329. }
  330.  
  331. public EntityArrow createArrow(@Nonnull World world, @Nonnull ItemStack itemstack, EntityLivingBase shooter) {
  332. return new EntitySMGRounds(world, shooter);
  333. }
  334.  
  335.  
  336. public boolean isInfinite(ItemStack stack, ItemStack bow, net.minecraft.entity.player.EntityPlayer player)
  337. {
  338. int enchant = net.minecraft.enchantment.EnchantmentHelper.getEnchantmentLevel(net.minecraft.init.Enchantments.INFINITY, bow);
  339. return enchant <= 0 ? false : this.getClass() == ItemSMGRounds.class;
  340. }
  341.  
  342.  
  343.  
  344. //Crafting Recipe\\
  345.  
  346.  
  347. public void addRecipes() {
  348. GameRegistry.addShapedRecipe(new ItemStack(this), " ", "III", "DDD", 'D', Items.GUNPOWDER, 'I',
  349. new ItemStack(Items.IRON_INGOT));
  350. }
  351.  
  352. }
  353.  
  354.  
  355.  
  356. =================================================================================================================================================================================================== Mod Entity ===========================================================
  357. =====================================================================================================================================
  358.  
  359.  
  360. package mod.sparkyfox.servermod.init;
  361.  
  362. import net.minecraft.entity.EnumCreatureType;
  363. import net.minecraft.init.Biomes;
  364. import net.minecraft.util.ResourceLocation;
  365. import net.minecraft.world.storage.loot.LootTableList;
  366. import net.minecraftforge.fml.common.registry.EntityRegistry;
  367. import net.minecraftforge.fml.relauncher.Side;
  368. import net.minecraftforge.fml.relauncher.SideOnly;
  369. import static net.minecraftforge.fml.client.registry.RenderingRegistry.registerEntityRenderingHandler;
  370. import static net.minecraftforge.fml.common.registry.EntityRegistry.addSpawn;
  371. import static net.minecraftforge.fml.common.registry.EntityRegistry.registerModEntity;
  372. import mod.sparkyfox.servermod.ServerMod;
  373. import mod.sparkyfox.servermod.entity.EntitySMGRounds;
  374. import mod.sparkyfox.servermod.render.RenderSMGRounds;
  375.  
  376.  
  377. public class ModEntities {
  378.  
  379. //Arrows ID 0 to 5
  380. private static final int SMGRounds = 0;
  381.  
  382.  
  383. public static void init() {
  384. // Every entity in ArmorPlus has an ID (local to this mod)
  385. registerModEntity(setResourceLocation("smgrounds"), EntitySMGRounds.class, "smgrounds", SMGRounds, ServerMod.instance, 64, 1, true);
  386.  
  387. }
  388.  
  389. private static ResourceLocation setResourceLocation(String string) {
  390. return null;
  391. }
  392.  
  393. @SideOnly(Side.CLIENT)
  394. public static void initModels() {
  395. //Mobs
  396.  
  397. //Arrows
  398. registerEntityRenderingHandler(EntitySMGRounds.class, RenderSMGRounds::new);
  399. }
  400. }
  401.  
  402.  
  403. =================================================================================================================================================================================================== Entity SMGRounds =====================================================
  404. =====================================================================================================================================
  405.  
  406.  
  407. package mod.sparkyfox.servermod.entity;
  408.  
  409. import io.netty.buffer.ByteBuf;
  410. import mod.sparkyfox.servermod.damage.DamageSourceSMGRounds;
  411. import mod.sparkyfox.servermod.init.ModSoundEvent;
  412.  
  413. import java.util.List;
  414.  
  415. import javax.annotation.Nullable;
  416.  
  417. import com.google.common.base.Predicate;
  418. import com.google.common.base.Predicates;
  419.  
  420. import net.minecraft.block.Block;
  421. import net.minecraft.block.material.Material;
  422. import net.minecraft.block.state.IBlockState;
  423. import net.minecraft.client.Minecraft;
  424. import net.minecraft.enchantment.EnchantmentHelper;
  425. import net.minecraft.entity.Entity;
  426. import net.minecraft.entity.EntityLivingBase;
  427. import net.minecraft.entity.IProjectile;
  428. import net.minecraft.entity.monster.EntityEnderman;
  429. import net.minecraft.entity.player.EntityPlayer;
  430. import net.minecraft.entity.player.EntityPlayerMP;
  431. import net.minecraft.entity.projectile.EntityArrow;
  432. import net.minecraft.init.SoundEvents;
  433. import net.minecraft.item.ItemStack;
  434. import net.minecraft.nbt.NBTTagCompound;
  435. import net.minecraft.network.datasync.DataParameter;
  436. import net.minecraft.network.datasync.DataSerializers;
  437. import net.minecraft.network.datasync.EntityDataManager;
  438. import net.minecraft.network.play.server.SPacketChangeGameState;
  439. import net.minecraft.util.DamageSource;
  440. import net.minecraft.util.EntitySelectors;
  441. import net.minecraft.util.EnumParticleTypes;
  442. import net.minecraft.util.ResourceLocation;
  443. import net.minecraft.util.math.AxisAlignedBB;
  444. import net.minecraft.util.math.BlockPos;
  445. import net.minecraft.util.math.MathHelper;
  446. import net.minecraft.util.math.RayTraceResult;
  447. import net.minecraft.util.math.Vec3d;
  448. import net.minecraft.world.World;
  449. import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
  450. import net.minecraftforge.fml.relauncher.Side;
  451. import net.minecraftforge.fml.relauncher.SideOnly;
  452.  
  453. public class EntitySMGRounds extends EntityArrow implements IProjectile, IEntityAdditionalSpawnData{
  454.  
  455. private static final Predicate<Entity> ARROW_TARGETS = Predicates.and(
  456. new Predicate[] {
  457. EntitySelectors.NOT_SPECTATING, EntitySelectors.IS_ALIVE, new Predicate<Entity>(){
  458. public boolean apply(@Nullable Entity p_apply_1_){
  459. return p_apply_1_.canBeCollidedWith();
  460. }
  461. }
  462. }
  463. );
  464. private int xTile;
  465. private int yTile;
  466. private int zTile;
  467. private Block inTile;
  468. private int inData;
  469. protected boolean inGround;
  470. protected int timeInGround;
  471. /** Seems to be some sort of timer for animating an arrow. */
  472. public int arrowShake;
  473. /** The owner of this arrow. */
  474. public Entity shootingEntity;
  475. private int ticksInGround;
  476. private int ticksInAir;
  477. private double damage;
  478. /** The amount of knockback an arrow applies when it hits a mob. */
  479. private int knockbackStrength;
  480.  
  481. private double speed = 0.3D;
  482. private float range = 0.4F;
  483.  
  484. public EntitySMGRounds(World worldIn){
  485. super(worldIn);
  486. this.xTile = -1;
  487. this.yTile = -1;
  488. this.zTile = -1;
  489. this.pickupStatus = EntityArrow.PickupStatus.DISALLOWED;
  490. this.damage = 2.0D;
  491. this.setSize(0.5F, 0.5F);
  492. }
  493.  
  494. public EntitySMGRounds(World worldIn, EntityLivingBase shooter, float p_i1756_3_){
  495. super(worldIn);
  496. this.shootingEntity = shooter;
  497.  
  498. this.setLocationAndAngles(shooter.posX, shooter.posY + (double)shooter.getEyeHeight(), shooter.posZ, shooter.rotationYaw, shooter.rotationPitch);
  499. this.posX -= (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F);
  500. this.posY -= 0.10000000149011612D;
  501. this.posZ -= (double)(MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F);
  502. this.setPosition(this.posX, this.posY, this.posZ);
  503. this.motionX = (double)(-MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI));
  504. this.motionZ = (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI));
  505. this.motionY = (double)(-MathHelper.sin(this.rotationPitch / 180.0F * (float)Math.PI));
  506. this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, p_i1756_3_ * 1.5F, 1.0F);
  507. }
  508.  
  509. @Override
  510. public void writeSpawnData(ByteBuf buffer) {
  511. buffer.writeDouble(posX);
  512. buffer.writeDouble(posY);
  513. buffer.writeDouble(posZ);
  514. }
  515.  
  516. @Override
  517. public void readSpawnData(ByteBuf additionalData) {
  518. this.setPosition(additionalData.readDouble(), additionalData.readDouble(), additionalData.readDouble());
  519. }
  520.  
  521. @Override
  522. protected void entityInit(){
  523.  
  524. }
  525.  
  526. /**
  527. * Called to update the entity's position/logic.
  528. */
  529. @Override
  530. public void onUpdate(){
  531. //super.onUpdate();
  532.  
  533.  
  534. if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F){
  535. float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  536. this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
  537. this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f) * 180.0D / Math.PI);
  538. }
  539.  
  540. BlockPos blockpos = new BlockPos(this.xTile, this.yTile, this.zTile);
  541. IBlockState iblockstate = this.world.getBlockState(blockpos);
  542. Block block = iblockstate.getBlock();
  543.  
  544. if(iblockstate.getMaterial() != Material.AIR){//check if hit block
  545. AxisAlignedBB axisalignedbb = iblockstate.getCollisionBoundingBox(this.world, blockpos);
  546. if (axisalignedbb != Block.NULL_AABB && axisalignedbb.offset(blockpos).isVecInside(new Vec3d(this.posX, this.posY, this.posZ))){
  547. this.inGround = true;
  548. }
  549. }
  550.  
  551. if (this.arrowShake > 0){
  552. --this.arrowShake;
  553. }
  554.  
  555. if (this.inGround){//inGround stuff, kills the entity here
  556. int j = block.getMetaFromState(iblockstate);
  557.  
  558. if (block == this.inTile && j == this.inData){
  559. ++this.ticksInGround;
  560.  
  561. if (this.ticksInGround == 1200){
  562. this.setDead();
  563. }
  564. }else{
  565. this.inGround = false;
  566. this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
  567. this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
  568. this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
  569. this.ticksInGround = 0;
  570. this.ticksInAir = 0;
  571. }
  572. ++this.timeInGround;
  573. this.setDead();
  574. }else{ //Traveling
  575. this.timeInGround = 0;
  576. ++this.ticksInAir;
  577. Vec3d vec3d1 = new Vec3d(this.posX, this.posY, this.posZ);
  578. Vec3d vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  579. RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d1, vec3d, false, true, false);
  580. vec3d1 = new Vec3d(this.posX, this.posY, this.posZ);
  581. vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  582.  
  583. if(raytraceresult != null){
  584. vec3d = new Vec3d(raytraceresult.hitVec.xCoord, raytraceresult.hitVec.yCoord, raytraceresult.hitVec.zCoord);
  585. }
  586.  
  587. Entity entity = this.findEntityOnPath(vec3d1, vec3d);
  588.  
  589. if (entity != null){
  590. raytraceresult = new RayTraceResult(entity);
  591. }
  592.  
  593. if (raytraceresult != null && raytraceresult.entityHit != null && raytraceresult.entityHit instanceof EntityPlayer){
  594. EntityPlayer entityplayer = (EntityPlayer)raytraceresult.entityHit;
  595.  
  596. if (this.shootingEntity instanceof EntityPlayer && !((EntityPlayer)this.shootingEntity).canAttackPlayer(entityplayer)){
  597. raytraceresult = null;
  598. }
  599. }
  600.  
  601. if (raytraceresult != null){
  602. this.onHit(raytraceresult);
  603. }
  604.  
  605. if (this.getIsCritical()){
  606. for (int k = 0; k < 4; ++k){
  607. this.world.spawnParticle(EnumParticleTypes.CRIT, this.posX + this.motionX * (double)k / 4.0D, this.posY + this.motionY * (double)k / 4.0D, this.posZ + this.motionZ * (double)k / 4.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ, new int[0]);
  608. }
  609. }
  610.  
  611. this.posX += this.motionX * speed;
  612. this.posY += this.motionY * speed;
  613. this.posZ += this.motionZ * speed;
  614. float f4 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  615. this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
  616.  
  617. for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f4) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F){
  618. ;
  619. }
  620.  
  621. while (this.rotationPitch - this.prevRotationPitch >= 180.0F){
  622. this.prevRotationPitch += 360.0F;
  623. }
  624.  
  625. while (this.rotationYaw - this.prevRotationYaw < -180.0F){
  626. this.prevRotationYaw -= 360.0F;
  627. }
  628.  
  629. while (this.rotationYaw - this.prevRotationYaw >= 180.0F){
  630. this.prevRotationYaw += 360.0F;
  631. }
  632.  
  633. this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
  634. this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
  635. float f1 = 0.99F;
  636. float f2 = range;
  637.  
  638. if (this.isInWater()){
  639. for (int l = 0; l < 4; ++l){
  640. f4 = 0.25F;
  641. this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * (double)f4, this.posY - this.motionY * (double)f4, this.posZ - this.motionZ * (double)f4, this.motionX, this.motionY, this.motionZ);
  642. }
  643. f1 = 0.8F;
  644. }
  645.  
  646. if (this.isWet()){
  647. this.extinguish();
  648. }
  649.  
  650. this.motionX *= (double)f1;
  651. this.motionY *= (double)f1;
  652. this.motionZ *= (double)f1;
  653. this.motionY -= (double)f2;
  654. this.setPosition(this.posX, this.posY, this.posZ);
  655. this.doBlockCollisions();
  656. }
  657.  
  658.  
  659. }
  660.  
  661. @Override
  662. protected void onHit(RayTraceResult raytraceResultIn){
  663. Entity entity = raytraceResultIn.entityHit;
  664.  
  665. if (entity != null){
  666. float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
  667. int i = MathHelper.ceil((double)f * this.damage);
  668.  
  669. if (this.getIsCritical()){
  670. i += this.rand.nextInt(i / 2 + 2);
  671. }
  672.  
  673. DamageSource damagesource = new DamageSourceSMGRounds();
  674.  
  675. if (this.isBurning() && !(entity instanceof EntityEnderman)){
  676. entity.setFire(5);
  677. }
  678.  
  679. if (entity.attackEntityFrom(damagesource, (float)i)){
  680. if (entity instanceof EntityLivingBase){
  681. EntityLivingBase entitylivingbase = (EntityLivingBase)entity;
  682.  
  683. if (!this.world.isRemote){
  684. entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1);
  685. }
  686.  
  687. if (this.knockbackStrength > 0){
  688. float f1 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  689.  
  690. if (f1 > 0.0F){
  691. entitylivingbase.addVelocity(this.motionX * (double)this.knockbackStrength * 0.6000000238418579D / (double)f1, 0.1D, this.motionZ * (double)this.knockbackStrength * 0.6000000238418579D / (double)f1);
  692. }
  693. }
  694.  
  695. if (this.shootingEntity instanceof EntityLivingBase){
  696. //EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
  697. //EnchantmentHelper.applyArthropodEnchantments((EntityLivingBase)this.shootingEntity, entitylivingbase);
  698. }
  699.  
  700. this.arrowHit(entitylivingbase);
  701.  
  702. if (this.shootingEntity != null && entitylivingbase != this.shootingEntity && entitylivingbase instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP){
  703. ((EntityPlayerMP)this.shootingEntity).connection.sendPacket(new SPacketChangeGameState(6, 0.0F));
  704. }
  705. }
  706.  
  707. this.playSound(ModSoundEvent.impact, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
  708.  
  709. if (!(entity instanceof EntityEnderman)){
  710. this.setDead();
  711. }
  712. }else{
  713. this.motionX *= -0.10000000149011612D;
  714. this.motionY *= -0.10000000149011612D;
  715. this.motionZ *= -0.10000000149011612D;
  716. this.rotationYaw += 180.0F;
  717. this.prevRotationYaw += 180.0F;
  718. this.ticksInAir = 0;
  719.  
  720. if (!this.world.isRemote && this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ < 0.0010000000474974513D){
  721. if (this.pickupStatus == EntityArrow.PickupStatus.ALLOWED){
  722. this.entityDropItem(this.getArrowStack(), 0.1F);
  723. }
  724.  
  725. this.setDead();
  726. }
  727. }
  728. }else{
  729. BlockPos blockpos = raytraceResultIn.getBlockPos();
  730. this.xTile = blockpos.getX();
  731. this.yTile = blockpos.getY();
  732. this.zTile = blockpos.getZ();
  733. IBlockState iblockstate = this.world.getBlockState(blockpos);
  734. this.inTile = iblockstate.getBlock();
  735. this.inData = this.inTile.getMetaFromState(iblockstate);
  736. this.motionX = (double)((float)(raytraceResultIn.hitVec.xCoord - this.posX));
  737. this.motionY = (double)((float)(raytraceResultIn.hitVec.yCoord - this.posY));
  738. this.motionZ = (double)((float)(raytraceResultIn.hitVec.zCoord - this.posZ));
  739. float f2 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
  740. this.posX -= this.motionX / (double)f2 * 0.05000000074505806D;
  741. this.posY -= this.motionY / (double)f2 * 0.05000000074505806D;
  742. this.posZ -= this.motionZ / (double)f2 * 0.05000000074505806D;
  743. this.playSound(ModSoundEvent.impact, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
  744. this.inGround = true;
  745. this.arrowShake = 7;
  746. this.setIsCritical(false);
  747.  
  748. if (iblockstate.getMaterial() != Material.AIR){
  749. this.inTile.onEntityCollidedWithBlock(this.world, blockpos, iblockstate, this);
  750. }
  751. }
  752. }
  753.  
  754.  
  755.  
  756. /**
  757. * (abstract) Protected helper method to write subclass entity data to NBT.
  758. */
  759. @Override
  760. public void writeEntityToNBT(NBTTagCompound compound){
  761. compound.setInteger("xTile", this.xTile);
  762. compound.setInteger("yTile", this.yTile);
  763. compound.setInteger("zTile", this.zTile);
  764. compound.setShort("life", (short)this.ticksInGround);
  765. ResourceLocation resourcelocation = (ResourceLocation)Block.REGISTRY.getNameForObject(this.inTile);
  766. compound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString());
  767. compound.setByte("inData", (byte)this.inData);
  768. compound.setByte("shake", (byte)this.arrowShake);
  769. compound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
  770. compound.setByte("pickup", (byte)this.pickupStatus.ordinal());
  771. compound.setDouble("damage", this.damage);
  772. }
  773.  
  774.  
  775.  
  776. /**
  777. * (abstract) Protected helper method to read subclass entity data from NBT.
  778. */
  779. @Override
  780. public void readEntityFromNBT(NBTTagCompound compound){
  781. this.xTile = compound.getInteger("xTile");
  782. this.yTile = compound.getInteger("yTile");
  783. this.zTile = compound.getInteger("zTile");
  784. this.ticksInGround = compound.getShort("life");
  785.  
  786. if (compound.hasKey("inTile", 8)){
  787. this.inTile = Block.getBlockFromName(compound.getString("inTile"));
  788. }else{
  789. this.inTile = Block.getBlockById(compound.getByte("inTile") & 255);
  790. }
  791.  
  792. this.inData = compound.getByte("inData") & 255;
  793. this.arrowShake = compound.getByte("shake") & 255;
  794. this.inGround = compound.getByte("inGround") == 1;
  795.  
  796. if (compound.hasKey("damage", 99)){
  797. this.damage = compound.getDouble("damage");
  798. }
  799.  
  800. if (compound.hasKey("pickup", 99)){
  801. this.pickupStatus = EntityArrow.PickupStatus.getByOrdinal(compound.getByte("pickup"));
  802. }else if (compound.hasKey("player", 99)){
  803. this.pickupStatus = compound.getBoolean("player") ? EntityArrow.PickupStatus.ALLOWED : EntityArrow.PickupStatus.DISALLOWED;
  804. }
  805. }
  806.  
  807. /**
  808. * Called by a player entity when they collide with an entity
  809. */
  810. @Override
  811. public void onCollideWithPlayer(EntityPlayer p_70100_1_){
  812.  
  813. }
  814.  
  815. public void setDamageRangeSpeed(double d, float r, double s){
  816. damage = d;
  817. range = r;
  818. speed = s;
  819. }
  820.  
  821. @Override
  822. protected ItemStack getArrowStack() {
  823. return ItemStack.EMPTY;
  824. }
  825. }
  826.  
  827.  
  828.  
  829.  
  830. =====================================================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement