Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.mcreator.chromiumplusforge.item;
- import net.minecraftforge.registries.ObjectHolder;
- import net.minecraftforge.registries.ForgeRegistries;
- import net.minecraftforge.fml.network.NetworkHooks;
- import net.minecraftforge.fml.network.FMLPlayMessages;
- import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
- import net.minecraftforge.api.distmarker.OnlyIn;
- import net.minecraftforge.api.distmarker.Dist;
- import net.minecraft.world.World;
- import net.minecraft.util.math.MathHelper;
- import net.minecraft.util.SoundCategory;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.Hand;
- import net.minecraft.util.ActionResultType;
- import net.minecraft.util.ActionResult;
- import net.minecraft.network.IPacket;
- import net.minecraft.item.UseAction;
- import net.minecraft.item.ShootableItem;
- import net.minecraft.item.Items;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.Item;
- import net.minecraft.item.BowItem;
- import net.minecraft.entity.projectile.AbstractArrowEntity;
- import net.minecraft.entity.player.ServerPlayerEntity;
- import net.minecraft.entity.player.PlayerEntity;
- import net.minecraft.entity.LivingEntity;
- import net.minecraft.entity.IRendersAsItem;
- import net.minecraft.entity.EntityType;
- import net.minecraft.entity.EntityClassification;
- import net.minecraft.entity.Entity;
- import net.mcreator.chromiumplusforge.procedures.OmniBreakerWhileBulletFlyingTickProcedure;
- import net.mcreator.chromiumplusforge.procedures.OmniBreakerBulletHitsLivingEntityProcedure;
- import net.mcreator.chromiumplusforge.itemgroup.ChromiumPlusItemGroup;
- import net.mcreator.chromiumplusforge.entity.renderer.ApocalypsisRenderer;
- import net.mcreator.chromiumplusforge.ChromiumPlusForgeModElements;
- import java.util.Random;
- import java.util.Map;
- import java.util.HashMap;
- @ChromiumPlusForgeModElements.ModElement.Tag
- public class ApocalypsisItem extends ChromiumPlusForgeModElements.ModElement {
- @ObjectHolder("chromium_plus_forge:apocalypsis")
- public static final Item block = null;
- public static final EntityType arrow = (EntityType.Builder.<ArrowCustomEntity>create(ArrowCustomEntity::new, EntityClassification.MISC)
- .setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).setCustomClientFactory(ArrowCustomEntity::new)
- .size(0.5f, 0.5f)).build("entitybulletapocalypsis").setRegistryName("entitybulletapocalypsis");
- public ApocalypsisItem(ChromiumPlusForgeModElements instance) {
- super(instance, 317);
- FMLJavaModLoadingContext.get().getModEventBus().register(new ApocalypsisRenderer.ModelRegisterHandler());
- }
- @Override
- public void initElements() {
- elements.items.add(() -> new ItemRanged());
- elements.entities.add(() -> arrow);
- }
- public static class ItemRanged extends BowItem {
- public ItemRanged() {
- super(new Item.Properties().group(ChromiumPlusItemGroup.tab).maxDamage(6182));
- setRegistryName("apocalypsis");
- }
- @Override
- public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity entity, Hand hand) {
- entity.setActiveHand(hand);
- return new ActionResult(ActionResultType.SUCCESS, entity.getHeldItem(hand));
- }
- @Override
- public UseAction getUseAction(ItemStack itemstack) {
- return UseAction.BOW;
- }
- @Override
- public int getUseDuration(ItemStack itemstack) {
- return 72000;
- }
- @Override
- public void onPlayerStoppedUsing(ItemStack itemstack, World world, LivingEntity entityLiving, int timeLeft) {
- if (!world.isRemote && entityLiving instanceof ServerPlayerEntity) {
- ServerPlayerEntity entity = (ServerPlayerEntity) entityLiving;
- double x = entity.getPosX();
- double y = entity.getPosY();
- double z = entity.getPosZ();
- boolean flag = entity.abilities.isCreativeMode;
- ItemStack stack = ShootableItem.getHeldAmmo(entity, e -> e.getItem() == new ItemStack(Items.ARROW, (int) (1)).getItem());
- int h = this.getUseDuration(itemstack) - timeLeft;
- h = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(itemstack, world, entity, h, flag || stack != ItemStack.EMPTY);
- if (h < 0)
- return;
- if (stack == ItemStack.EMPTY) {
- for (int i = 0; i < entity.inventory.mainInventory.size(); i++) {
- ItemStack teststack = entity.inventory.mainInventory.get(i);
- if (teststack != null && teststack.getItem() == new ItemStack(Items.ARROW, (int) (1)).getItem()) {
- stack = teststack;
- break;
- }
- }
- }
- if (flag || stack != ItemStack.EMPTY) {
- float j = getArrowVelocity(h);
- if (!((double) j < 0.1D)) {
- ArrowCustomEntity entityarrow = shoot(world, entity, random, 1f, 4, 0);
- itemstack.damageItem(1, entity, e -> e.sendBreakAnimation(entity.getActiveHand()));
- if (entity.abilities.isCreativeMode) {
- entityarrow.pickupStatus = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
- } else {
- if (new ItemStack(Items.ARROW, (int) (1)).isDamageable()) {
- if (stack.attemptDamageItem(1, random, entity)) {
- stack.shrink(1);
- stack.setDamage(0);
- if (stack.isEmpty())
- entity.inventory.deleteStack(stack);
- }
- } else {
- stack.shrink(1);
- if (stack.isEmpty())
- entity.inventory.deleteStack(stack);
- }
- }
- }
- }
- }
- }
- @OnlyIn(value = Dist.CLIENT, _interface = IRendersAsItem.class)
- public static class ArrowCustomEntity extends AbstractArrowEntity implements IRendersAsItem {
- public ArrowCustomEntity(FMLPlayMessages.SpawnEntity packet, World world) {
- super(arrow, world);
- }
- public ArrowCustomEntity(EntityType<? extends ArrowCustomEntity> type, World world) {
- super(type, world);
- }
- public ArrowCustomEntity(EntityType<? extends ArrowCustomEntity> type, double x, double y, double z, World world) {
- super(type, x, y, z, world);
- }
- public ArrowCustomEntity(EntityType<? extends ArrowCustomEntity> type, LivingEntity entity, World world) {
- super(type, entity, world);
- }
- @Override
- public IPacket<?> createSpawnPacket() {
- return NetworkHooks.getEntitySpawningPacket(this);
- }
- @Override
- @OnlyIn(Dist.CLIENT)
- public ItemStack getItem() {
- return null;
- }
- @Override
- protected ItemStack getArrowStack() {
- return new ItemStack(Items.ARROW, (int) (1));
- }
- @Override
- protected void arrowHit(LivingEntity entity) {
- super.arrowHit(entity);
- entity.setArrowCountInEntity(entity.getArrowCountInEntity() - 1);
- Entity sourceentity = this.func_234616_v_();
- double x = this.getPosX();
- double y = this.getPosY();
- double z = this.getPosZ();
- World world = this.world;
- {
- Map<String, Object> $_dependencies = new HashMap<>();
- $_dependencies.put("entity", entity);
- $_dependencies.put("sourceentity", sourceentity);
- OmniBreakerBulletHitsLivingEntityProcedure.executeProcedure($_dependencies);
- }
- }
- @Override
- public void tick() {
- super.tick();
- double x = this.getPosX();
- double y = this.getPosY();
- double z = this.getPosZ();
- World world = this.world;
- Entity entity = this.func_234616_v_();
- {
- Map<String, Object> $_dependencies = new HashMap<>();
- $_dependencies.put("x", x);
- $_dependencies.put("y", y);
- $_dependencies.put("z", z);
- $_dependencies.put("world", world);
- OmniBreakerWhileBulletFlyingTickProcedure.executeProcedure($_dependencies);
- }
- if (this.inGround) {
- this.remove();
- }
- }
- }
- public static ArrowCustomEntity shoot(World world, LivingEntity entity, Random random, float power, double damage, int knockback) {
- ArrowCustomEntity entityarrow = new ArrowCustomEntity(arrow, entity, world);
- entityarrow.shoot(entity.getLookVec().x, entity.getLookVec().y, entity.getLookVec().z, power * 2, 0);
- entityarrow.setSilent(true);
- entityarrow.setIsCritical(false);
- entityarrow.setDamage(damage);
- entityarrow.setKnockbackStrength(knockback);
- world.addEntity(entityarrow);
- double x = entity.getPosX();
- double y = entity.getPosY();
- double z = entity.getPosZ();
- world.playSound((PlayerEntity) null, (double) x, (double) y, (double) z,
- (net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.blaze.shoot")),
- SoundCategory.PLAYERS, 1, 1f / (random.nextFloat() * 0.5f + 1) + (power / 2));
- return entityarrow;
- }
- public static ArrowCustomEntity shoot(LivingEntity entity, LivingEntity target) {
- ArrowCustomEntity entityarrow = new ArrowCustomEntity(arrow, entity, entity.world);
- double d0 = target.getPosY() + (double) target.getEyeHeight() - 1.1;
- double d1 = target.getPosX() - entity.getPosX();
- double d3 = target.getPosZ() - entity.getPosZ();
- entityarrow.shoot(d1, d0 - entityarrow.getPosY() + (double) MathHelper.sqrt(d1 * d1 + d3 * d3) * 0.2F, d3, 1.4000000000000001f * 2, 12.0F);
- entityarrow.setSilent(true);
- entityarrow.setDamage(14);
- entityarrow.setKnockbackStrength(0);
- entityarrow.setIsCritical(false);
- entity.world.addEntity(entityarrow);
- double x = entity.getPosX();
- double y = entity.getPosY();
- double z = entity.getPosZ();
- entity.world.playSound((PlayerEntity) null, (double) x, (double) y, (double) z,
- (net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.blaze.shoot")),
- SoundCategory.PLAYERS, 1, 1f / (new Random().nextFloat() * 0.5f + 1));
- return entityarrow;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement