Chest direction

Discussion in 'Plugin Development' started by RebzO1, Feb 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    RebzO1

    is there a way to make the chests face a certain direction in the following?
    Code:java
    1. loc.getBlock().getRelative(4, 1, -2).setType(Material.CHEST);
    2. loc.getBlock().getRelative(4, 1, 2).setType(Material.CHEST);
    3. loc.getBlock().getRelative(-4, 1, -2).setType(Material.CHEST);
    4. loc.getBlock().getRelative(-4, 1, 2).setType(Material.CHEST);
    5. loc.getBlock().getRelative(2, 1, -4).setType(Material.CHEST);
    6. loc.getBlock().getRelative(2, 1, 4).setType(Material.CHEST);
    7. loc.getBlock().getRelative(-2, 1, -4).setType(Material.CHEST);
    8. loc.getBlock().getRelative(-2, 1, 4).setType(Material.CHEST);
    9. loc.getBlock().getRelative(0, 1, -4).setType(Material.CHEST);
    10. loc.getBlock().getRelative(0, 1, 4).setType(Material.CHEST);
    11. loc.getBlock().getRelative(4, 1, 0).setType(Material.CHEST);
    12. loc.getBlock().getRelative(-4, 1, 0).setType(Material.CHEST);
     
  2. Offline

    xTrollxDudex

    RebzO1
    Cast BlockState to o.b.b.Chest and use setDirection
     
  3. Offline

    RebzO1

    xTrollxDudex
    i have imported org.bukkit.block.Chest
    but as for the rest im unsure what you mean
     
  4. Offline

    SourceForums

    RebzO1
    He means to create a BlockState that affects the chest and edit its direction using the setDirection() method.
     
  5. Offline

    RebzO1

    SourceForums
    I understand what he was telling me i need to do, i also understand the setDirection but creating a blockstate i dont have a clue i looked at jd.bukkit.org but i am still clueless
     
  6. Offline

    SourceForums

  7. Offline

    RebzO1

    SourceForums xTrollxDudex
    k ill have a look at those in a bit gotta go do that work thing

    hopefully ill get it working.
     
  8. Offline

    SourceForums

    RebzO1
    Judging from what I briefly read, I think you can use the following code to do what you're aiming to do:
    Code:java
    1. Block block = etc.
    2. BlockState state = (BlockState) block.getState();
    3. state.setDirection() //Direction

    Haven't tested though. :D
     
  9. Offline

    RebzO1

    SourceForums
    Ye, i saw something like that but where do i put it, in relation to what i have.
    sorry if it seems like a noob question.

    bleh nvm

    read through those pages and still have no clue i feel like a dumb ass now

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  10. Offline

    SourceForums

    RebzO1
    Well, you define the block (chest) and the blockstate at the start, then modify it. I'm not really sure what you're trying to ask here:
     
  11. Offline

    RebzO1

    SourceForums
    the code in the original post spawns my 12 chests all facing south and i need 3 facing in each direction my problem is that i don't know how to modify my code so it does it

    sorry i seem to be pretty bad at explaining myself
     
  12. Offline

    SourceForums

    RebzO1
    Could you please provide your current code? I'll give you an example with it. :D
    P.S. And no, it's not that you're bad at explaining - I'm just bad at understanding. :D
     
  13. Offline

    RebzO1

    SourceForums
    Code:java
    1. /**
    2. * CardinalCraft Diamond Dash By RebzO1
    3. */
    4. package me.rebz.diamonddash;
    5.  
    6. import net.minecraft.server.v1_7_R1.Block;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.Material;
    11. import org.bukkit.Sound;
    12. import org.bukkit.block.BlockFace;
    13. import org.bukkit.block.Chest;
    14. import org.bukkit.block.Sign;
    15. import org.bukkit.command.Command;
    16. import org.bukkit.command.CommandSender;
    17. import org.bukkit.Location;
    18. import org.bukkit.enchantments.Enchantment;
    19. import org.bukkit.entity.Player;
    20. import org.bukkit.event.EventHandler;
    21. import org.bukkit.event.Listener;
    22. import org.bukkit.event.block.Action;
    23. import org.bukkit.event.entity.EntityDeathEvent;
    24. import org.bukkit.event.player.PlayerInteractEvent;
    25. import org.bukkit.inventory.Inventory;
    26. import org.bukkit.inventory.ItemStack;
    27. import org.bukkit.material.MaterialData;
    28. import org.bukkit.plugin.java.JavaPlugin;
    29.  
    30. import java.util.logging.Logger;
    31.  
    32.  
    33. public class Main extends JavaPlugin implements Listener{
    34. public final Logger logger = Logger.getLogger("Minecraft");
    35. public int number = 5;
    36. public int time = 1805;
    37.  
    38. public void onEnable() {
    39. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    40. getLogger().info("CC-Diamond Dash Enabled!");
    41. }
    42. public void onDisable() {
    43. getLogger().info("CC-Diamond Dash Disabled!");
    44. }
    45. @EventHandler
    46. public void onDeath(EntityDeathEvent e){
    47. if (e.getEntity() instanceof Player){
    48. for (Player online : getServer().getOnlinePlayers()) {
    49. online.playSound(online.getLocation(), Sound.WOLF_HOWL, 1, 2);
    50. }
    51. }
    52. }
    53.  
    54. @SuppressWarnings("deprecation")
    55. public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args){
    56. Player p = (Player) sender;
    57.  
    58. if (CommandLabel.equalsIgnoreCase("kit")){
    59. if(args.length == 0){
    60. ItemStack pick = new ItemStack(Material.DIAMOND_PICKAXE, 1);
    61. pick.addEnchantment(Enchantment.SILK_TOUCH, 1);
    62. pick.addEnchantment(Enchantment.DIG_SPEED, 4);
    63. pick.addEnchantment(Enchantment.DURABILITY, 3);
    64. p.getInventory().addItem(pick);
    65. ItemStack[] items = {
    66. new ItemStack(Material.DIAMOND_SWORD),
    67. new ItemStack(Material.STONE_SPADE),
    68. new ItemStack(Material.GOLDEN_CARROT, 64),
    69. new ItemStack(Material.LOG, 64),
    70. new ItemStack(Material.DIAMOND_HELMET),
    71. new ItemStack(Material.DIAMOND_CHESTPLATE),
    72. new ItemStack(Material.DIAMOND_LEGGINGS),
    73. new ItemStack(Material.DIAMOND_BOOTS),
    74. new ItemStack(Material.SIGN)};
    75. p.getInventory().addItem(items);
    76. p.sendMessage(ChatColor.AQUA + "You are now ready to start!");
    77. return true;
    78. }
    79. }
    80. /* if (cmd.getName().equalsIgnoreCase("build")) {
    81. if (args.length == 4 && sender instanceof Player) {
    82. Player player = (Player) sender;
    83. int ylevel = Integer.parseInt(args[0]);
    84. int xradius = Integer.parseInt(args[1]);
    85. int zradius = Integer.parseInt(args[2]);
    86. int yhight = Integer.parseInt(args[3]); //changed this to make it easier
    87.  
    88. Location center = new Location(player.getWorld(), player.getLocation().getX(), ylevel, player.getLocation().getZ());
    89.  
    90. for (int y = 0; y <= yhight; y++){
    91. for (int x = -xradius; x <= xradius; x++ ){
    92. for (int z = -zradius; z <= zradius; z++) {
    93. if (y == 0) center.getBlock().getRelative(x, y, z).setType(Material.WOOD);
    94. else if (y == yhight) center.getBlock().getRelative(x, y, z).setType(Material.GLOWSTONE);
    95. else if (Math.abs(x) == xradius || Math.abs(z) == zradius) center.getBlock().getRelative(x,y,z).setType(Material.WOOD);
    96. else center.getBlock().getRelative(x,y,z).setType(Material.AIR);
    97. }
    98. }
    99. }
    100. }
    101. }*/
    102. if (cmd.getName().equalsIgnoreCase("build")) {
    103. if(args.length == 0){
    104. p.getWorld().setSpawnLocation(
    105. p.getLocation().getBlockX(),
    106. p.getLocation().getBlockY(),
    107. p.getLocation().getBlockZ());
    108.  
    109. Location loc = p.getLocation();
    110. loc .setY(11);
    111.  
    112. // base
    113. for (int x = -8; x < 9; ++x) {
    114. loc.getBlock().getRelative(x, 0, -8).setType(Material.HARD_CLAY);
    115. for (int z = -8; z < 9; ++z) {
    116. loc.getBlock().getRelative(x, 0, z).setType(Material.HARD_CLAY);
    117. }
    118. }
    119. //walls
    120. for (int x = -8; x < 9; ++x) {
    121. loc.getBlock().getRelative(x, 1, -8).setType(Material.SMOOTH_BRICK);
    122. for (int z = -8; z < 9; ++z) {
    123. loc.getBlock().getRelative(x, 1, z).setType(Material.SMOOTH_BRICK);
    124.  
    125. }
    126. }
    127. for (int x = -8; x < 9; ++x) {
    128. loc.getBlock().getRelative(x, 2, -8).setType(Material.SMOOTH_BRICK);
    129. for (int z = -8; z < 9; ++z) {
    130. loc.getBlock().getRelative(x, 2, z).setType(Material.SMOOTH_BRICK);
    131.  
    132. }
    133. }
    134. for (int x = -8; x < 9; ++x) {
    135. loc.getBlock().getRelative(x, 3, -8).setType(Material.SMOOTH_BRICK);
    136. for (int z = -8; z < 9; ++z) {
    137. loc.getBlock().getRelative(x, 3, z).setType(Material.SMOOTH_BRICK);
    138.  
    139. }
    140. }
    141. for (int x = -8; x < 9; ++x) {
    142. loc.getBlock().getRelative(x, 4, -8).setType(Material.SMOOTH_BRICK);
    143. for (int z = -8; z < 9; ++z) {
    144. loc.getBlock().getRelative(x, 4, z).setType(Material.SMOOTH_BRICK);
    145.  
    146. }
    147. }
    148. for (int x = -8; x < 9; ++x) {
    149. loc.getBlock().getRelative(x, 5, -8).setType(Material.SMOOTH_BRICK);
    150. for (int z = -8; z < 9; ++z) {
    151. loc.getBlock().getRelative(x, 5, z).setType(Material.SMOOTH_BRICK);
    152. }
    153. }
    154. // AIR
    155. for (int x = -7; x < 8; ++x) {
    156. loc.getBlock().getRelative(x, 1, -7).setType(Material.AIR);
    157. for (int z = -7; z < 8; ++z) {
    158. loc.getBlock().getRelative(x, 1, z).setType(Material.AIR);
    159. }
    160. }
    161. for (int x = -7; x < 8; ++x) {
    162. loc.getBlock().getRelative(x, 2, -7).setType(Material.AIR);
    163. for (int z = -7; z < 8; ++z) {
    164. loc.getBlock().getRelative(x, 2, z).setType(Material.AIR);
    165. }
    166. }
    167. for (int x = -7; x < 8; ++x) {
    168. loc.getBlock().getRelative(x, 3, -7).setType(Material.AIR);
    169. for (int z = -7; z < 8; ++z) {
    170. loc.getBlock().getRelative(x, 3, z).setType(Material.AIR);
    171. }
    172. }
    173. for (int x = -7; x < 8; ++x) {
    174. loc.getBlock().getRelative(x, 4, -7).setType(Material.AIR);
    175. for (int z = -7; z < 8; ++z) {
    176. loc.getBlock().getRelative(x, 4, z).setType(Material.AIR);
    177. }
    178. }
    179. loc.getBlock().getRelative(4, 1, -2).setType(Material.CHEST);
    180. loc.getBlock().getRelative(4, 1, 2).setType(Material.CHEST);
    181. loc.getBlock().getRelative(-4, 1, -2).setType(Material.CHEST);
    182. loc.getBlock().getRelative(-4, 1, 2).setType(Material.CHEST);
    183. loc.getBlock().getRelative(2, 1, -4).setType(Material.CHEST);
    184. loc.getBlock().getRelative(2, 1, 4).setType(Material.CHEST);
    185. loc.getBlock().getRelative(-2, 1, -4).setType(Material.CHEST);
    186. loc.getBlock().getRelative(-2, 1, 4).setType(Material.CHEST);
    187. loc.getBlock().getRelative(0, 1, -4).setType(Material.CHEST);
    188. loc.getBlock().getRelative(0, 1, 4).setType(Material.CHEST);
    189. loc.getBlock().getRelative(4, 1, 0).setType(Material.CHEST);
    190. loc.getBlock().getRelative(-4, 1, 0).setType(Material.CHEST);
    191. // loc.getBlock().getRelative(-4, 1, -4).setType(Material.CHEST);
    192. // loc.getBlock().getRelative(4, 1, 4).setType(Material.CHEST);
    193. // loc.getBlock().getRelative(4, 1, -4).setType(Material.CHEST);
    194. // loc.getBlock().getRelative(-4, 1, 4).setType(Material.CHEST);
    195.  
    196. loc.getBlock().getRelative(0, 5, 0).setType(Material.GLOWSTONE);
    197. loc.getBlock().getRelative(-4, 5, -4).setType(Material.GLOWSTONE);
    198. loc.getBlock().getRelative(-4, 5, 4).setType(Material.GLOWSTONE);
    199. loc.getBlock().getRelative(4, 5, -4).setType(Material.GLOWSTONE);
    200. loc.getBlock().getRelative(4, 5, 4).setType(Material.GLOWSTONE);
    201.  
    202. p.teleport(loc.add(0, 1, 0));
    203. p.getWorld().setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
    204.  
    205. Bukkit.dispatchCommand(Bukkit.getConsoleSender(),"say Start Room Built.");
    206. return true;
    207. }
    208. }
    209. if (CommandLabel.equalsIgnoreCase("spawn")){
    210. if (!sender.hasPermission("dd.spawn")) {
    211. return false;
    212. }
    213. if(args.length == 0){
    214. p.teleport(p.getWorld().getSpawnLocation());
    215. p.sendMessage(ChatColor.GOLD + "Teleporting to spawn..." );
    216. }
    217. return true;
    218. }
    219.  
    220. if (CommandLabel.equalsIgnoreCase("diamonds") && sender instanceof Player){
    221. if(args.length == 0){
    222. p.sendMessage(ChatColor.GRAY + "------------------------------" );
    223. p.sendMessage(ChatColor.AQUA + "You have 30 minutes to...");
    224. p.sendMessage(ChatColor.AQUA + "Find as many " + ChatColor.GOLD + "DIAMONDS " + ChatColor.AQUA + "as you can! ");
    225. p.sendMessage(ChatColor.AQUA + "No PVP & if you die you are out!");
    226. p.sendMessage(ChatColor.AQUA + "Winner takes everyones loot!");
    227. p.sendMessage(ChatColor.GRAY + "------------------------------" );
    228. return true;
    229. }
    230. }
    231. if (CommandLabel.equalsIgnoreCase("ores") && sender instanceof Player){
    232. if(args.length == 0){
    233. p.sendMessage(ChatColor.GRAY + "-----------------------------------" );
    234. p.sendMessage(ChatColor.AQUA + "You have 30 minutes to...");
    235. p.sendMessage(ChatColor.AQUA + "Find as many " + ChatColor.GOLD + "ORES " + ChatColor.AQUA + "as you can! ");
    236. p.sendMessage(ChatColor.AQUA + "1 Point for each" + ChatColor.GOLD + " Iron ore " + ChatColor.AQUA + " you find.");
    237. p.sendMessage(ChatColor.AQUA + "3 Points for each" + ChatColor.GOLD + " Gold ore " + ChatColor.AQUA + " you find.");
    238. p.sendMessage(ChatColor.AQUA + "5 Points for each" + ChatColor.GOLD + " Diamond ore " + ChatColor.AQUA + " you find.");
    239. p.sendMessage(ChatColor.AQUA + "5 Points for each" + ChatColor.GOLD + " Emerald ore " + ChatColor.AQUA + " you find.");
    240. p.sendMessage(ChatColor.AQUA + "No PVP & if you die you are out!");
    241. p.sendMessage(ChatColor.AQUA + "Winner takes everyones loot!");
    242. p.sendMessage(ChatColor.GRAY + "-----------------------------------" );
    243. return true;
    244. }
    245. }
    246. // Start Timers
    247. // This focuses on the start countdown and game countdown also the /time command
    248. if (CommandLabel.equalsIgnoreCase("start") && sender instanceof Player){
    249. this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable(){
    250. public void run(){
    251. if(number != -1){
    252. if(number != 0){
    253. Bukkit.broadcastMessage(ChatColor.AQUA + "" + number);
    254. number--;
    255. }else{
    256. Bukkit.broadcastMessage(ChatColor.AQUA + "Go! Go! Go!");
    257. number--;
    258. }
    259. }
    260. }
    261. }, 0L, 20L);
    262.  
    263. this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable(){
    264. public void run(){
    265. if(time != -1){
    266. if(time != 0){
    267. time--;
    268. }else{
    269. Bukkit.broadcastMessage(ChatColor.AQUA + "Times Up!");
    270. for(Player pl : Bukkit.getOnlinePlayers()) {
    271. pl.teleport(pl.getWorld().getSpawnLocation());
    272. }
    273. time--;
    274. }
    275. }
    276. }
    277. }, 0L, 20L);
    278. return true;
    279. }
    280.  
    281. if (CommandLabel.equalsIgnoreCase("time") && sender instanceof Player){
    282. if(args.length == 0){
    283. int minutes = time / 60;
    284. int seconds = time % 60;
    285. p.sendMessage(ChatColor.AQUA + "Time left: " + ChatColor.GRAY + minutes + ChatColor.AQUA + " minutes" + ChatColor.AQUA + " and " + ChatColor.GRAY + seconds + ChatColor.AQUA + " seconds.");
    286. return true;
    287. }
    288. }
    289. return false;
    290. }


    .

    SourceForums
    made a couple of changes

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  14. Offline

    RebzO1

    could still use help with this, i have tried but cannot get it working
     
  15. Offline

    SourceForums

    RebzO1
    Please provide your new code.
    EDIT: Could you please post only the relevant parts this time please?
     
  16. Offline

    RebzO1

    SourceForums
    Code:java
    1. loc.getBlock().getRelative(4, 1, -2).setType(Material.CHEST);
    2. loc.getBlock().getRelative(4, 1, 2).setType(Material.CHEST);
    3. loc.getBlock().getRelative(-4, 1, -2).setType(Material.CHEST);
    4. loc.getBlock().getRelative(-4, 1, 2).setType(Material.CHEST);
    5. loc.getBlock().getRelative(2, 1, -4).setType(Material.CHEST);
    6. loc.getBlock().getRelative(2, 1, 4).setType(Material.CHEST);
    7. loc.getBlock().getRelative(-2, 1, -4).setType(Material.CHEST);
    8. loc.getBlock().getRelative(-2, 1, 4).setType(Material.CHEST);
    9. loc.getBlock().getRelative(0, 1, -4).setType(Material.CHEST);
    10. loc.getBlock().getRelative(0, 1, 4).setType(Material.CHEST);
    11. loc.getBlock().getRelative(4, 1, 0).setType(Material.CHEST);
    12. loc.getBlock().getRelative(-4, 1, 0).setType(Material.CHEST);


    this part didn't change
    these are the chests that spawn 12 in a square i just need 3 pointing in each direction N, E, S & W.

    SourceForums
    If you need more of the code ill get that posted too

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  17. Offline

    SourceForums

Thread Status:
Not open for further replies.

Share This Page