-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
178 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.iung.fpv20; | ||
|
||
import com.iung.fpv20.config.Fpv20ConfigClientManual; | ||
import com.iung.fpv20.flying.GlobalFlying; | ||
import com.iung.fpv20.network.DroneExplosionPacket; | ||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; | ||
import net.minecraft.util.math.Vec3d; | ||
|
||
import java.util.Objects; | ||
|
||
import static com.iung.fpv20.flying.GlobalFlying.ZERO_SPEED; | ||
|
||
public class Explosion { | ||
public static boolean explosion_trig() { | ||
if (controller() || Fpv20Client.config1.explosion_config.always_explode) { | ||
if (Fpv20Client.config1.explosion_config.stop_fly_after_explosion) { | ||
GlobalFlying.setFlying(false); | ||
} | ||
// GlobalFlying.G.drone.set_speed(new Vec3d(0,0,0)); | ||
ClientPlayNetworking.send( | ||
new DroneExplosionPacket( | ||
Fpv20Client.config1.explosion_config.power, | ||
Fpv20Client.config1.explosion_config.stop_fly_after_explosion, | ||
GlobalFlying.start_fly_pos(), | ||
Fpv20Client.config1.explosion_config.teleport_after_explosion | ||
)); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public static boolean controller() { | ||
float e = Objects.requireNonNull(Fpv20Client.controller).get_value_by_name("expl"); | ||
return e > 0.5; | ||
} | ||
|
||
private static Fpv20ConfigClientManual.ExplosionConfig.Vec3d min_speed() { | ||
return Fpv20Client.config1.explosion_config.min_speed; | ||
} | ||
|
||
public static boolean handle_explosion(Vec3d last_speed, Vec3d now_speed) { | ||
boolean trig = false; | ||
if (Math.abs(last_speed.x) > min_speed().x() && Math.abs(now_speed.x) < ZERO_SPEED) { | ||
trig = true; | ||
} | ||
if (Math.abs(last_speed.y) > min_speed().y() && Math.abs(now_speed.y) < ZERO_SPEED) { | ||
trig = true; | ||
} | ||
if (Math.abs(last_speed.z) > min_speed().z() && Math.abs(now_speed.z) < ZERO_SPEED) { | ||
trig = true; | ||
} | ||
// Fpv20.LOGGER.info("he {} / {}", last_speed, now_speed); | ||
|
||
if (trig) { | ||
Fpv20.LOGGER.info("trigged"); | ||
|
||
return explosion_trig(); | ||
} | ||
return false; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/com/iung/fpv20/network/DroneExplosionPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.iung.fpv20.network; | ||
|
||
import com.iung.fpv20.Fpv20; | ||
import net.fabricmc.fabric.api.networking.v1.FabricPacket; | ||
import net.fabricmc.fabric.api.networking.v1.PacketType; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.math.GlobalPos; | ||
import net.minecraft.util.math.Vec3d; | ||
|
||
public class DroneExplosionPacket implements FabricPacket { | ||
|
||
public static final PacketType<DroneExplosionPacket> TYPE = PacketType.create(new Identifier(Fpv20.MOD_ID, "drone_explosion_packet"), DroneExplosionPacket::new); | ||
|
||
public float power; | ||
public boolean stop_fly; | ||
public Vec3d tele_pos; | ||
public boolean if_tele; | ||
|
||
private DroneExplosionPacket(PacketByteBuf buf) { | ||
this.power = buf.readFloat(); | ||
this.stop_fly = buf.readBoolean(); | ||
this.tele_pos = new Vec3d(buf.readDouble(), buf.readDouble(), buf.readDouble()); | ||
this.if_tele = buf.readBoolean(); | ||
} | ||
|
||
public DroneExplosionPacket(float power, boolean stop_fly, Vec3d tele_pos, boolean if_tele) { | ||
this.power = power; | ||
this.stop_fly = stop_fly; | ||
this.tele_pos = tele_pos; | ||
this.if_tele = if_tele; | ||
} | ||
|
||
|
||
@Override | ||
public void write(PacketByteBuf buf) { | ||
buf.writeFloat(this.power); | ||
buf.writeBoolean(this.stop_fly); | ||
buf.writeDouble(this.tele_pos.x); | ||
buf.writeDouble(this.tele_pos.y); | ||
buf.writeDouble(this.tele_pos.z); | ||
buf.writeBoolean(this.if_tele); | ||
} | ||
|
||
@Override | ||
public PacketType<?> getType() { | ||
return TYPE; | ||
} | ||
} |