Advertisement
Guest User

bowcode

a guest
Jun 28th, 2021
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.30 KB | None | 0 0
  1.  
  2. package net.mcreator.chromiumplusforge.item;
  3.  
  4. import net.minecraftforge.registries.ObjectHolder;
  5. import net.minecraftforge.registries.ForgeRegistries;
  6. import net.minecraftforge.fml.network.NetworkHooks;
  7. import net.minecraftforge.fml.network.FMLPlayMessages;
  8. import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
  9. import net.minecraftforge.api.distmarker.OnlyIn;
  10. import net.minecraftforge.api.distmarker.Dist;
  11.  
  12. import net.minecraft.world.World;
  13. import net.minecraft.util.math.MathHelper;
  14. import net.minecraft.util.SoundCategory;
  15. import net.minecraft.util.ResourceLocation;
  16. import net.minecraft.util.Hand;
  17. import net.minecraft.util.ActionResultType;
  18. import net.minecraft.util.ActionResult;
  19. import net.minecraft.network.IPacket;
  20. import net.minecraft.item.UseAction;
  21. import net.minecraft.item.ShootableItem;
  22. import net.minecraft.item.Items;
  23. import net.minecraft.item.ItemStack;
  24. import net.minecraft.item.Item;
  25. import net.minecraft.item.BowItem;
  26. import net.minecraft.entity.projectile.AbstractArrowEntity;
  27. import net.minecraft.entity.player.ServerPlayerEntity;
  28. import net.minecraft.entity.player.PlayerEntity;
  29. import net.minecraft.entity.LivingEntity;
  30. import net.minecraft.entity.IRendersAsItem;
  31. import net.minecraft.entity.EntityType;
  32. import net.minecraft.entity.EntityClassification;
  33. import net.minecraft.entity.Entity;
  34.  
  35. import net.mcreator.chromiumplusforge.procedures.OmniBreakerWhileBulletFlyingTickProcedure;
  36. import net.mcreator.chromiumplusforge.procedures.OmniBreakerBulletHitsLivingEntityProcedure;
  37. import net.mcreator.chromiumplusforge.itemgroup.ChromiumPlusItemGroup;
  38. import net.mcreator.chromiumplusforge.entity.renderer.ApocalypsisRenderer;
  39. import net.mcreator.chromiumplusforge.ChromiumPlusForgeModElements;
  40.  
  41. import java.util.Random;
  42. import java.util.Map;
  43. import java.util.HashMap;
  44.  
  45. @ChromiumPlusForgeModElements.ModElement.Tag
  46. public class ApocalypsisItem extends ChromiumPlusForgeModElements.ModElement {
  47. @ObjectHolder("chromium_plus_forge:apocalypsis")
  48. public static final Item block = null;
  49. public static final EntityType arrow = (EntityType.Builder.<ArrowCustomEntity>create(ArrowCustomEntity::new, EntityClassification.MISC)
  50. .setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).setCustomClientFactory(ArrowCustomEntity::new)
  51. .size(0.5f, 0.5f)).build("entitybulletapocalypsis").setRegistryName("entitybulletapocalypsis");
  52. public ApocalypsisItem(ChromiumPlusForgeModElements instance) {
  53. super(instance, 317);
  54. FMLJavaModLoadingContext.get().getModEventBus().register(new ApocalypsisRenderer.ModelRegisterHandler());
  55. }
  56.  
  57. @Override
  58. public void initElements() {
  59. elements.items.add(() -> new ItemRanged());
  60. elements.entities.add(() -> arrow);
  61. }
  62. public static class ItemRanged extends BowItem {
  63. public ItemRanged() {
  64. super(new Item.Properties().group(ChromiumPlusItemGroup.tab).maxDamage(6182));
  65. setRegistryName("apocalypsis");
  66. }
  67. @Override
  68. public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity entity, Hand hand) {
  69. entity.setActiveHand(hand);
  70. return new ActionResult(ActionResultType.SUCCESS, entity.getHeldItem(hand));
  71. }
  72. @Override
  73. public UseAction getUseAction(ItemStack itemstack) {
  74. return UseAction.BOW;
  75. }
  76. @Override
  77. public int getUseDuration(ItemStack itemstack) {
  78. return 72000;
  79. }
  80. @Override
  81. public void onPlayerStoppedUsing(ItemStack itemstack, World world, LivingEntity entityLiving, int timeLeft) {
  82. if (!world.isRemote && entityLiving instanceof ServerPlayerEntity) {
  83. ServerPlayerEntity entity = (ServerPlayerEntity) entityLiving;
  84. double x = entity.getPosX();
  85. double y = entity.getPosY();
  86. double z = entity.getPosZ();
  87. boolean flag = entity.abilities.isCreativeMode;
  88. ItemStack stack = ShootableItem.getHeldAmmo(entity, e -> e.getItem() == new ItemStack(Items.ARROW, (int) (1)).getItem());
  89. int h = this.getUseDuration(itemstack) - timeLeft;
  90. h = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(itemstack, world, entity, h, flag || stack != ItemStack.EMPTY);
  91. if (h < 0)
  92. return;
  93. if (stack == ItemStack.EMPTY) {
  94. for (int i = 0; i < entity.inventory.mainInventory.size(); i++) {
  95. ItemStack teststack = entity.inventory.mainInventory.get(i);
  96. if (teststack != null && teststack.getItem() == new ItemStack(Items.ARROW, (int) (1)).getItem()) {
  97. stack = teststack;
  98. break;
  99. }
  100. }
  101. }
  102. if (flag || stack != ItemStack.EMPTY) {
  103. float j = getArrowVelocity(h);
  104. if (!((double) j < 0.1D)) {
  105. ArrowCustomEntity entityarrow = shoot(world, entity, random, 1f, 4, 0);
  106. itemstack.damageItem(1, entity, e -> e.sendBreakAnimation(entity.getActiveHand()));
  107. if (entity.abilities.isCreativeMode) {
  108. entityarrow.pickupStatus = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
  109. } else {
  110. if (new ItemStack(Items.ARROW, (int) (1)).isDamageable()) {
  111. if (stack.attemptDamageItem(1, random, entity)) {
  112. stack.shrink(1);
  113. stack.setDamage(0);
  114. if (stack.isEmpty())
  115. entity.inventory.deleteStack(stack);
  116. }
  117. } else {
  118. stack.shrink(1);
  119. if (stack.isEmpty())
  120. entity.inventory.deleteStack(stack);
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. @OnlyIn(value = Dist.CLIENT, _interface = IRendersAsItem.class)
  128. public static class ArrowCustomEntity extends AbstractArrowEntity implements IRendersAsItem {
  129. public ArrowCustomEntity(FMLPlayMessages.SpawnEntity packet, World world) {
  130. super(arrow, world);
  131. }
  132. public ArrowCustomEntity(EntityType<? extends ArrowCustomEntity> type, World world) {
  133. super(type, world);
  134. }
  135. public ArrowCustomEntity(EntityType<? extends ArrowCustomEntity> type, double x, double y, double z, World world) {
  136. super(type, x, y, z, world);
  137. }
  138. public ArrowCustomEntity(EntityType<? extends ArrowCustomEntity> type, LivingEntity entity, World world) {
  139. super(type, entity, world);
  140. }
  141. @Override
  142. public IPacket<?> createSpawnPacket() {
  143. return NetworkHooks.getEntitySpawningPacket(this);
  144. }
  145. @Override
  146. @OnlyIn(Dist.CLIENT)
  147. public ItemStack getItem() {
  148. return null;
  149. }
  150. @Override
  151. protected ItemStack getArrowStack() {
  152. return new ItemStack(Items.ARROW, (int) (1));
  153. }
  154. @Override
  155. protected void arrowHit(LivingEntity entity) {
  156. super.arrowHit(entity);
  157. entity.setArrowCountInEntity(entity.getArrowCountInEntity() - 1);
  158. Entity sourceentity = this.func_234616_v_();
  159. double x = this.getPosX();
  160. double y = this.getPosY();
  161. double z = this.getPosZ();
  162. World world = this.world;
  163. {
  164. Map<String, Object> $_dependencies = new HashMap<>();
  165. $_dependencies.put("entity", entity);
  166. $_dependencies.put("sourceentity", sourceentity);
  167. OmniBreakerBulletHitsLivingEntityProcedure.executeProcedure($_dependencies);
  168. }
  169. }
  170. @Override
  171. public void tick() {
  172. super.tick();
  173. double x = this.getPosX();
  174. double y = this.getPosY();
  175. double z = this.getPosZ();
  176. World world = this.world;
  177. Entity entity = this.func_234616_v_();
  178. {
  179. Map<String, Object> $_dependencies = new HashMap<>();
  180. $_dependencies.put("x", x);
  181. $_dependencies.put("y", y);
  182. $_dependencies.put("z", z);
  183. $_dependencies.put("world", world);
  184. OmniBreakerWhileBulletFlyingTickProcedure.executeProcedure($_dependencies);
  185. }
  186. if (this.inGround) {
  187. this.remove();
  188. }
  189. }
  190. }
  191. public static ArrowCustomEntity shoot(World world, LivingEntity entity, Random random, float power, double damage, int knockback) {
  192. ArrowCustomEntity entityarrow = new ArrowCustomEntity(arrow, entity, world);
  193. entityarrow.shoot(entity.getLookVec().x, entity.getLookVec().y, entity.getLookVec().z, power * 2, 0);
  194. entityarrow.setSilent(true);
  195. entityarrow.setIsCritical(false);
  196. entityarrow.setDamage(damage);
  197. entityarrow.setKnockbackStrength(knockback);
  198. world.addEntity(entityarrow);
  199. double x = entity.getPosX();
  200. double y = entity.getPosY();
  201. double z = entity.getPosZ();
  202. world.playSound((PlayerEntity) null, (double) x, (double) y, (double) z,
  203. (net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.blaze.shoot")),
  204. SoundCategory.PLAYERS, 1, 1f / (random.nextFloat() * 0.5f + 1) + (power / 2));
  205. return entityarrow;
  206. }
  207. public static ArrowCustomEntity shoot(LivingEntity entity, LivingEntity target) {
  208. ArrowCustomEntity entityarrow = new ArrowCustomEntity(arrow, entity, entity.world);
  209. double d0 = target.getPosY() + (double) target.getEyeHeight() - 1.1;
  210. double d1 = target.getPosX() - entity.getPosX();
  211. double d3 = target.getPosZ() - entity.getPosZ();
  212. entityarrow.shoot(d1, d0 - entityarrow.getPosY() + (double) MathHelper.sqrt(d1 * d1 + d3 * d3) * 0.2F, d3, 1.4000000000000001f * 2, 12.0F);
  213. entityarrow.setSilent(true);
  214. entityarrow.setDamage(14);
  215. entityarrow.setKnockbackStrength(0);
  216. entityarrow.setIsCritical(false);
  217. entity.world.addEntity(entityarrow);
  218. double x = entity.getPosX();
  219. double y = entity.getPosY();
  220. double z = entity.getPosZ();
  221. entity.world.playSound((PlayerEntity) null, (double) x, (double) y, (double) z,
  222. (net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.blaze.shoot")),
  223. SoundCategory.PLAYERS, 1, 1f / (new Random().nextFloat() * 0.5f + 1));
  224. return entityarrow;
  225. }
  226. }
  227.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement