use of me.deecaad.weaponmechanics.weapon.projectile.HitBox in project MechanicsMain by WeaponMechanics.
the class WeaponMechanics method writeFiles.
void writeFiles() {
// Create files
if (!getDataFolder().exists() || getDataFolder().listFiles() == null || getDataFolder().listFiles().length == 0) {
debug.info("Copying files from jar (This process may take up to 30 seconds during the first load!)");
try {
FileUtil.copyResourcesTo(getClassLoader().getResource("WeaponMechanics"), getDataFolder().toPath());
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
try {
// TODO bad programmars comment out broken code
// FileUtil.ensureDefaults(getClassLoader(), "WeaponMechanics/config.yml", new File(getDataFolder(), "config.yml"));
} catch (YAMLException e) {
debug.error("WeaponMechanics jar corruption... This is most likely caused by using /reload after building jar!");
}
// Fill config.yml mappings
File configyml = new File(getDataFolder(), "config.yml");
if (configyml.exists()) {
List<IValidator> validators = new ArrayList<>();
// No need for other validators here as this is only for config.yml
validators.add(new HitBox());
FileReader basicConfigurationReader = new FileReader(debug, null, validators);
Configuration filledMap = basicConfigurationReader.fillOneFile(configyml);
basicConfiguration = basicConfigurationReader.usePathToSerializersAndValidators(filledMap);
} else {
// Just creates empty map to prevent other issues
basicConfiguration = new LinkedConfig();
debug.log(LogLevel.WARN, "Could not locate config.yml?", "Make sure it exists in path " + getDataFolder() + "/config.yml");
}
// Ensure that the resource pack exists in the folder
if (basicConfiguration.getBool("Resource_Pack_Download.Enabled")) {
String link = basicConfiguration.getString("Resource_Pack_Download.Link");
int connection = basicConfiguration.getInt("Resource_Pack_Download.Connection_Timeout");
int read = basicConfiguration.getInt("Resource_Pack_Download.Read_Timeout");
File pack = new File(getDataFolder(), "WeaponMechanicsResourcePack.zip");
if (!pack.exists()) {
FileUtil.downloadFile(pack, link, connection, read);
}
}
}
use of me.deecaad.weaponmechanics.weapon.projectile.HitBox in project MechanicsMain by WeaponMechanics.
the class RayTraceCommand method execute.
@Override
public void execute(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "This command is only available for players.");
return;
}
Player player = (Player) sender;
boolean onlyHitPosition = args.length > 0 && Boolean.parseBoolean(args[0]);
int distance = (args.length > 1) ? Integer.parseInt(args[1]) : 5;
if (distance < 1) {
sender.sendMessage(ChatColor.RED + "Distance was less than 1");
return;
}
int time = (args.length > 2) ? Integer.parseInt(args[2]) : 200;
sender.sendMessage(ChatColor.GREEN + "Showing hitboxes in distance " + distance + " for " + time + " ticks");
IWeaponCompatibility weaponCompatibility = WeaponCompatibilityAPI.getWeaponCompatibility();
new BukkitRunnable() {
int ticker = 0;
@Override
public void run() {
Location location = player.getEyeLocation();
Vector direction = location.getDirection();
BlockIterator blocks = new BlockIterator(player.getWorld(), location.toVector(), direction, 0.0, distance);
while (blocks.hasNext()) {
Block block = blocks.next();
HitBox blockBox = weaponCompatibility.getHitBox(block);
if (blockBox == null)
continue;
RayTraceResult rayTraceResult = blockBox.rayTrace(location.toVector(), direction);
if (rayTraceResult == null)
continue;
if (onlyHitPosition) {
rayTraceResult.outlineOnlyHitPosition(player);
} else {
blockBox.outlineAllBoxes(player);
}
player.sendMessage("Block: " + block.getType());
break;
}
Collection<Entity> entities = player.getWorld().getNearbyEntities(location, distance, distance, distance);
if (!entities.isEmpty()) {
for (Entity entity : entities) {
if (!(entity instanceof LivingEntity) || entity.getEntityId() == player.getEntityId())
continue;
HitBox entityBox = weaponCompatibility.getHitBox(entity);
if (entityBox == null)
continue;
RayTraceResult rayTraceResult = entityBox.rayTrace(location.toVector(), direction);
if (rayTraceResult == null)
continue;
if (onlyHitPosition) {
rayTraceResult.outlineOnlyHitPosition(player);
} else {
entityBox.outlineAllBoxes(player);
}
player.sendMessage("Entity: " + entity.getType());
break;
}
}
if (++ticker >= time) {
cancel();
}
}
}.runTaskTimer(WeaponMechanics.getPlugin(), 0, 0);
}
use of me.deecaad.weaponmechanics.weapon.projectile.HitBox in project MechanicsMain by WeaponMechanics.
the class v1_10_R1 method getHitBox.
@Override
public HitBox getHitBox(org.bukkit.entity.Entity entity) {
if (entity.isInvulnerable() || !entity.getType().isAlive() || entity.isDead())
return null;
AxisAlignedBB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
HitBox hitBox = new HitBox(aabb.a, aabb.b, aabb.c, aabb.d, aabb.e, aabb.f);
hitBox.setLivingEntity((LivingEntity) entity);
if (entity instanceof ComplexLivingEntity && WeaponMechanics.getBasicConfigurations().getBool("Check_Accurate_Hitboxes", true)) {
for (ComplexEntityPart entityPart : ((ComplexLivingEntity) entity).getParts()) {
AxisAlignedBB boxPart = ((CraftEntity) entityPart).getHandle().getBoundingBox();
hitBox.addVoxelShapePart(new HitBox(boxPart.a, boxPart.b, boxPart.c, boxPart.d, boxPart.e, boxPart.f));
}
}
return hitBox;
}
use of me.deecaad.weaponmechanics.weapon.projectile.HitBox in project MechanicsMain by WeaponMechanics.
the class v1_10_R1 method getHitBox.
@Override
public HitBox getHitBox(org.bukkit.block.Block block) {
if (block.isEmpty() || block.isLiquid())
return null;
WorldServer worldServer = ((CraftWorld) block.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
IBlockData blockData = worldServer.getType(blockPosition);
Block nmsBlock = blockData.getBlock();
// Passable block check -> false means passable (thats why !)
if (!(blockData.d(worldServer, blockPosition) != Block.k && nmsBlock.a(blockData, false)))
return null;
AxisAlignedBB aabb = blockData.c(worldServer, blockPosition);
// 1.12 -> e
// 1.11 -> d
// 1.9 - 1.10 -> c
int x = blockPosition.getX(), y = blockPosition.getY(), z = blockPosition.getZ();
HitBox hitBox = new HitBox(x + aabb.a, y + aabb.b, z + aabb.c, x + aabb.d, y + aabb.e, z + aabb.f);
hitBox.setBlockHitBox(block);
return hitBox;
}
use of me.deecaad.weaponmechanics.weapon.projectile.HitBox in project MechanicsMain by WeaponMechanics.
the class v1_11_R1 method getHitBox.
@Override
public HitBox getHitBox(org.bukkit.block.Block block) {
if (block.isEmpty() || block.isLiquid())
return null;
WorldServer worldServer = ((CraftWorld) block.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
IBlockData blockData = worldServer.getType(blockPosition);
Block nmsBlock = blockData.getBlock();
// Passable block check -> false means passable (thats why !)
if (!(blockData.d(worldServer, blockPosition) != Block.k && nmsBlock.a(blockData, false)))
return null;
AxisAlignedBB aabb = blockData.d(worldServer, blockPosition);
// 1.12 -> e
// 1.11 -> d
// 1.9 - 1.10 -> c
int x = blockPosition.getX(), y = blockPosition.getY(), z = blockPosition.getZ();
HitBox hitBox = new HitBox(x + aabb.a, y + aabb.b, z + aabb.c, x + aabb.d, y + aabb.e, z + aabb.f);
hitBox.setBlockHitBox(block);
return hitBox;
}
Aggregations