/*
 * This file is part of TechReborn, licensed under the MIT License (MIT).
 *
 * Copyright (c) 2020 TechReborn
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package techreborn.entities;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.TntEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import reborncore.common.explosion.RebornExplosion;
import techreborn.config.TechRebornConfig;

/**
 * Created by Mark on 13/03/2016.
 */
public class EntityNukePrimed extends TntEntity {

	public EntityNukePrimed(EntityType<EntityNukePrimed> entityType,  World world) {
		super(entityType, world);
		setFuse(TechRebornConfig.nukeFuseTime);
	}

	public EntityNukePrimed(World world, double x, double y, double z, LivingEntity tntPlacedBy) {
		super(world, x, y, z, tntPlacedBy);
		setFuse(TechRebornConfig.nukeFuseTime);
	}

	@Override
	public void tick() {
		this.prevX = this.getX();
		this.prevY = this.getY();
		this.prevZ = this.getZ();

		Vec3d velocity = getVelocity();
		double motionX = velocity.x;
		double motionY = velocity.y;
		double motionZ = velocity.z;

		if (!this.hasNoGravity()) {
			this.setVelocity(this.getVelocity().add(0.0D, -0.04D, 0.0D));
		}

		this.move(MovementType.SELF, this.getVelocity());
		this.setVelocity(this.getVelocity().multiply(0.98D));
		if (this.onGround) {
			this.setVelocity(this.getVelocity().multiply(0.7D, -0.5D, 0.7D));
		}

		setVelocity(new Vec3d(motionX, motionZ, motionY));

		setFuse(getFuseTimer() - 1);

		if (getFuseTimer() <= 0) {
			this.remove();
			if (!this.world.isClient) {
				explodeNuke();
			}
		} else {
			this.updateWaterState();
			this.world.addParticle(ParticleTypes.SMOKE, this.getX(), this.getY() + 0.5D, this.getZ(), 0.0D, 0.0D, 0.0D);
		}
	}

	public void explodeNuke() {
		if (!TechRebornConfig.nukeEnabled) {
			return;
		}
		RebornExplosion nukeExplosion = new RebornExplosion(getBlockPos(), world, TechRebornConfig.nukeRadius);
		nukeExplosion.setLivingBase(getCausingEntity());
		nukeExplosion.explode();
	}
}

@@ -1371,32 +1371,136 @@
 tity.TntEntity;%0A
+import net.minecraft.network.Packet;%0Aimport net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;%0A
 import net.minec
@@ -1652,16 +1652,54 @@
 losion;%0A
+import team.reborn.energy.EnergyTier;%0A
 import t
@@ -1732,16 +1732,90 @@
 nConfig;
+%0Aimport techreborn.init.TRBlockEntities;%0Aimport techreborn.init.TRContent;
 %0A%0A/**%0A *
@@ -2274,221 +2274,8 @@
 ) %7B%0A
-%09%09this.prevX = this.getX();%0A%09%09this.prevY = this.getY();%0A%09%09this.prevZ = this.getZ();%0A%0A%09%09Vec3d velocity = getVelocity();%0A%09%09double motionX = velocity.x;%0A%09%09double motionY = velocity.y;%0A%09%09double motionZ = velocity.z;%0A%0A
 %09%09if
@@ -2579,62 +2579,8 @@
 %09%7D%0A%0A
-%09%09setVelocity(new Vec3d(motionX, motionZ, motionY));%0A%0A
 %09%09se
@@ -2606,23 +2606,27 @@
 ) - 1);%0A
-%0A
 %09%09if (
+this.
 getFuseT
@@ -2693,16 +2693,21 @@
 ) %7B%0A%09%09%09%09
+this.
 explodeN
@@ -2757,16 +2757,47 @@
 tate();%0A
+%09%09%09if (this.world.isClient) %7B%0A%09
 %09%09%09this.
@@ -2900,16 +2900,21 @@
  0.0D);%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%7D%0A%0A

Fix Nuke flying away when lit