개인 자료란 (JE)

  서버 커뮤니티

Profile 하이퍼MC 대표칭호 없음

Krouda d9df1a84ba404d5c81fabfcdd1672982

Profile

질문하기 플러그인

블럭 1000번 클릭하면 죽이기

2022.10.30 조회 수 225 추천 수 0
이해도 초보자 
게임버전 (JE) 관련없음 
게임버전 (BE) 관련없음 

@EventHandler
public void onClick(PlayerInteractEvent e) {
    Location loc1 = new Location(e.getPlayer().getWorld(), 50, 73, 50);
    if (e.getAction().name().contains("LEFT_")) {
        if (e.getClickedBlock().getLocation() == loc1) {
            if (e.getClickedBlock().getType().name().contains("Obsidian")) {
                e.getPlayer().sendMessage("you left clicked obsidian");
            }
        }
    } else {
        return;
    }
}

특정 구역에 있는 옵시디언을 왼클하면 정해진 체력 1000에서 -1을 해서 체력이 0이 되면 아이템을 지급하도록 하려는데요

블럭한테 1000이라는 체력을 주는 방법을 모르겠네요

도와주세요





5개의 댓글

0reo
2022.10.30
HashMap<Location, Integer> map = new HashMap<>();
@EventHandler
public void onClick(PlayerInteractEvent e) {
    Location loc = new Location(e.getPlayer().getWorld(), 0, 0, 0);
    if (e.getAction().equals(Action.LEFT_CLICK_BLOCK) && e.getClickedBlock() != null && e.getClickedBlock().getLocation().equals(loc)) {
        if (e.getClickedBlock().getType().equals(Material.OBSIDIAN)) {
            if (!map.containsKey(loc)) {
                map.put(loc, 999);
            } else {
                map.replace(loc, map.get(loc) - 1);
                if (map.get(loc) == 0) {
                    e.getPlayer().getInventory().addItem(new ItemStack(Material.DIAMOND_AXE));
                    map.remove(loc);
                    return;
                }
            }
            e.getPlayer().sendMessage("cnt : " + map.get(loc));
            e.setCancelled(true);
        }
    }
}

될수도?

0reo
2022.10.30
@0reo
private int cnt = 1000;
@EventHandler
public void onTouch(PlayerInteractEvent e) {
    Location loc = new Location(e.getPlayer().getWorld(), 0, 0, 0);
    if (e.getAction().equals(Action.LEFT_CLICK_BLOCK) && e.getClickedBlock() != null && e.getClickedBlock().getLocation().equals(loc)) {
        if (e.getClickedBlock().getType().equals(Material.OBSIDIAN)) {
            cnt--;
            e.getPlayer().sendMessage("cnt : " + cnt);
            if (cnt == 0) {
                e.getPlayer().getInventory().addItem(new ItemStack(Material.DIAMOND_AXE));
                return;
            }
            e.setCancelled(true);
        }
    }
}

쉬운버전

하이퍼MC
2022.10.30
@0reo

아이고 감사합니다 <333

qsef1256
2022.10.30
@하이퍼MC

별개로, 블록에 체력이란 개념은 없어요. 저건 임의로 변수를 정의해서 만들어준거에요

하이퍼MC
2022.11.16
@qsef1256

네네 블럭에 체력없는건 아는데 제가 설명을 제대로 못했네요

뉴스 및 창작물
/files/thumbnails/268/789/003/262x150.crop.jpg?20240515192032

레드스톤

벌레먹은 돌 빠르게 제거하는 법

GlassesFilm

2024-05-15

0

/files/thumbnails/797/788/003/262x150.crop.jpg?20240515090924

건축

마인크래프트로 구현한 카르카손 보드게임

Warak

2024-05-15

1

/files/thumbnails/487/784/003/262x150.crop.jpg?20240508233607

모드

Windows Borderless 모드에서 악성코드 발견 3

학교가기싫다

2024-05-08

1

/files/thumbnails/384/778/003/262x150.crop.jpg?20240512002324

업데이트

마인크래프트 자바 에디션 스냅샷 24w18a

학교가기싫다

2024-05-06

0

/files/thumbnails/855/781/003/262x150.crop.jpg?20240505141129

레드스톤

레이저 클리너

GlassesFilm

2024-05-05

1