Files
src
build.gradle
Code
3 167
src/main/java/com/kodari/steelfurnace/SteelFurnacePlugin.java
package com.kodari.steelfurnace;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.BlockDisplay;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Transformation;
import org.joml.Quaternionf;
import org.joml.Vector3f;
public final class SteelFurnacePlugin extends JavaPlugin implements CommandExecutor {
private static final String FURNACE_TAG = "kodari_steel_furnace";
@Override
public void onEnable() {
getCommand("steelfurnace").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage(ChatColor.RED + "This command can only be used in-game.");
return true;
}
String action = args.length == 0 ? "spawn" : args[0].toLowerCase();
if (action.equals("spawn")) {
Block target = player.getTargetBlockExact(8);
if (target == null) {
player.sendMessage(ChatColor.RED + "Look at a block within 8 blocks to place the furnace.");
return true;
}
spawnFurnace(target);
player.sendMessage(ChatColor.GREEN + "Steel furnace created.");
return true;
}
if (action.equals("remove")) {
int removed = removeNearbyFurnaces(player);
player.sendMessage(ChatColor.GREEN + "Removed " + removed + " steel furnace part(s).");
return true;
}
player.sendMessage(ChatColor.YELLOW + "Usage: /steelfurnace <spawn|remove>");
return true;
}
private void spawnFurnace(Block target) {
World world = target.getWorld();
Location origin = target.getLocation().add(0.5, 1, 0.5);
cube(world, origin, "DEEPSLATE_BRICKS", -0.52, 0.02, -0.38, 1.04, 0.13, 0.76);
cube(world, origin, "GRAY_CONCRETE", -0.47, 0.15, -0.33, 0.94, 0.62, 0.66);
cube(world, origin, "DEEPSLATE_TILES", -0.49, 0.70, -0.35, 0.98, 0.13, 0.70);
cube(world, origin, "LIGHT_GRAY_CONCRETE", -0.49, 0.18, -0.38, 0.08, 0.55, 0.06);
cube(world, origin, "LIGHT_GRAY_CONCRETE", 0.41, 0.18, -0.38, 0.08, 0.55, 0.06);
cube(world, origin, "IRON_BLOCK", -0.29, 0.17, -0.405, 0.58, 0.37, 0.07);
cube(world, origin, "BLACKSTONE", -0.23, 0.23, -0.44, 0.46, 0.25, 0.04);
cube(world, origin, "GLOWSTONE", -0.19, 0.27, -0.465, 0.38, 0.17, 0.025);
cube(world, origin, "ORANGE_CONCRETE", -0.17, 0.29, -0.49, 0.34, 0.12, 0.025);
cube(world, origin, "YELLOW_CONCRETE", -0.12, 0.30, -0.515, 0.24, 0.07, 0.02);
cube(world, origin, "YELLOW_CONCRETE", -0.07, 0.28, -0.54, 0.08, 0.11, 0.02);
cube(world, origin, "IRON_BLOCK", -0.50, 0.08, -0.29, 0.07, 0.67, 0.10);
cube(world, origin, "IRON_BLOCK", 0.43, 0.08, -0.29, 0.07, 0.67, 0.10);
cube(world, origin, "BROWN_CONCRETE", -0.49, 0.16, 0.28, 0.08, 0.47, 0.08);
cube(world, origin, "COPPER_BLOCK", -0.43, 0.22, 0.33, 0.035, 0.035, 0.035);
buildTopPipes(world, origin);
buildChimney(world, origin);
}
private void buildTopPipes(World world, Location origin) {
cube(world, origin, "LIGHT_GRAY_CONCRETE", -0.36, 0.82, -0.22, 0.10, 0.33, 0.10);
cube(world, origin, "POLISHED_ANDESITE", -0.38, 1.10, -0.23, 0.44, 0.09, 0.09);
cube(world, origin, "IRON_BLOCK", -0.05, 0.82, -0.19, 0.09, 0.29, 0.09);
cube(world, origin, "LIGHT_GRAY_CONCRETE", -0.02, 1.02, -0.20, 0.28, 0.08, 0.08);
cube(world, origin, "IRON_BLOCK", 0.17, 0.82, -0.22, 0.09, 0.22, 0.09);
cube(world, origin, "IRON_BARS", -0.31, 0.81, 0.04, 0.22, 0.18, 0.17);
cube(world, origin, "LIGHT_GRAY_CONCRETE", -0.32, 0.99, 0.07, 0.24, 0.05, 0.11);
cube(world, origin, "GOLD_BLOCK", -0.24, 0.90, -0.04, 0.06, 0.06, 0.06);
cube(world, origin, "IRON_BLOCK", -0.21, 0.91, -0.09, 0.12, 0.035, 0.035);
cube(world, origin, "POLISHED_ANDESITE", -0.32, 0.77, -0.12, 0.10, 0.08, 0.10);
}
private void buildChimney(World world, Location origin) {
cube(world, origin, "DEEPSLATE_BRICKS", 0.23, 0.80, 0.10, 0.30, 0.20, 0.30);
cube(world, origin, "GRAY_CONCRETE", 0.27, 0.99, 0.14, 0.22, 0.53, 0.22);
cube(world, origin, "LIGHT_GRAY_CONCRETE", 0.25, 1.07, 0.12, 0.26, 0.055, 0.26);
cube(world, origin, "LIGHT_GRAY_CONCRETE", 0.25, 1.32, 0.12, 0.26, 0.055, 0.26);
cube(world, origin, "IRON_BLOCK", 0.25, 1.51, 0.12, 0.26, 0.09, 0.26);
cube(world, origin, "BLACKSTONE", 0.29, 1.60, 0.16, 0.18, 0.035, 0.18);
cube(world, origin, "LIGHT_GRAY_CONCRETE", 0.49, 0.86, 0.16, 0.08, 0.26, 0.08);
cube(world, origin, "IRON_BLOCK", 0.51, 1.09, 0.17, 0.055, 0.06, 0.055);
}
private void cube(World world, Location origin, String materialName,
double x, double y, double z, double width, double height, double depth) {
Location location = origin.clone().add(x, y, z);
BlockDisplay display = world.spawn(location, BlockDisplay.class);
display.setBlock(XMaterial.matchXMaterial(materialName)
.map(XMaterial::parseMaterial)
.orElseThrow(() -> new IllegalArgumentException("Unknown material: " + materialName))
.createBlockData());
display.setTransformation(new Transformation(
new Vector3f(),
new Quaternionf(),
new Vector3f((float) width, (float) height, (float) depth),
new Quaternionf()));
display.setInvulnerable(true);
display.addScoreboardTag(FURNACE_TAG);
}
private int removeNearbyFurnaces(Player player) {
int removed = 0;
for (Entity entity : player.getWorld().getNearbyEntities(player.getLocation(), 24, 24, 24)) {
if (entity.getScoreboardTags().contains(FURNACE_TAG)) {
entity.remove();
removed++;
}
}
return removed;
}
}