좀비 소환
2025. 3. 27. 22:28ㆍ마인크래프트
@EventHandler
public void onPlaceZombieBlock(BlockPlaceEvent event) {
Player player = event.getPlayer();
ItemStack item = event.getItemInHand();
if (item.getType() == Material.DIAMOND_BLOCK && item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();
if (meta != null && "Zombie".equals(ChatColor.stripColor(meta.getDisplayName()))) {
// Normalize location manually
Block placedBlock = event.getBlockPlaced();
Location blockLoc = new Location(
placedBlock.getWorld(),
placedBlock.getX(),
placedBlock.getY(),
placedBlock.getZ()
);
Location spawnLoc = blockLoc.clone().add(0.5, 1, 0.5);
Zombie zombie = (Zombie) spawnLoc.getWorld().spawnEntity(spawnLoc, EntityType.ZOMBIE);
zombie.setCustomName("Block Guardian");
zombie.setCustomNameVisible(true);
zombie.setPersistent(true);
zombie.setAdult();
zombie.setCanPickupItems(true);
zombie.setRemoveWhenFarAway(false);
zombie.setMetadata("owner", new FixedMetadataValue(this, player.getUniqueId().toString()));
guardianZombies.put(blockLoc, zombie);
// Restore saved gear
ItemStack[] gear = latestZombieGear;
if (gear != null) {
EntityEquipment eq = zombie.getEquipment();
if (eq != null) {
if (gear[0] != null) eq.setItemInMainHand(gear[0]);
if (gear[1] != null) eq.setHelmet(gear[1]);
if (gear[2] != null) eq.setChestplate(gear[2]);
if (gear[3] != null) eq.setLeggings(gear[3]);
if (gear[4] != null) eq.setBoots(gear[4]);
eq.setItemInMainHandDropChance(0f);
eq.setHelmetDropChance(0f);
eq.setChestplateDropChance(0f);
eq.setLeggingsDropChance(0f);
eq.setBootsDropChance(0f);
}
}
player.sendMessage(ChatColor.GREEN + "Guardian summoned.");
}
}
}
@EventHandler
public void onBreakZombieBlock(BlockBreakEvent event) {
Block block = event.getBlock();
Location loc = new Location(block.getWorld(), block.getX(), block.getY(), block.getZ());
if (block.getType() == Material.DIAMOND_BLOCK && guardianZombies.containsKey(loc)) {
event.setDropItems(false);
event.setExpToDrop(0);
// Drop the named diamond block
ItemStack drop = new ItemStack(Material.DIAMOND_BLOCK);
ItemMeta meta = drop.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.GREEN + "Zombie");
meta.setLore(Collections.singletonList(ChatColor.GRAY + "Summons your guardian"));
drop.setItemMeta(meta);
}
block.getWorld().dropItemNaturally(loc, drop);
// Save zombie gear
Zombie z = guardianZombies.remove(loc);
if (z != null && !z.isDead()) {
EntityEquipment eq = z.getEquipment();
if (eq != null) {
ItemStack[] gear = new ItemStack[5];
gear[0] = eq.getItemInMainHand();
gear[1] = eq.getHelmet();
gear[2] = eq.getChestplate();
gear[3] = eq.getLeggings();
gear[4] = eq.getBoots();
latestZombieGear = gear;
}
z.remove();
}
event.getPlayer().sendMessage(ChatColor.RED + "Guardian vanished. Gear stored.");
}
}
'마인크래프트' 카테고리의 다른 글
Minecraft OST (0) | 2025.03.29 |
---|---|
몹의 공격 데미지가 0이되게 하기 (0) | 2025.03.28 |
실행 및 종료 스크립트 (0) | 2025.03.23 |
다른 몹이 나를 공격하면, 그 몹을 공격하는 좀비 코딩 (0) | 2025.03.19 |
블록을 깨면 나를 따라오지만, 공격하지 않는 좀비 코딩 (0) | 2025.03.19 |