LkS_

Mcreator Error

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