Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Additions for improved BlockType-system (adds hay, ender-portal-frame, improved lever-facing) #60

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/org/bukkit/Material.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public enum Material {
BREWING_STAND(117, MaterialData.class),
CAULDRON(118, Cauldron.class),
ENDER_PORTAL(119),
ENDER_PORTAL_FRAME(120),
ENDER_PORTAL_FRAME(120, EnderPortalFrame.class),
ENDER_STONE(121),
DRAGON_EGG(122),
REDSTONE_LAMP_OFF(123),
Expand Down Expand Up @@ -187,7 +187,7 @@ public enum Material {
IRON_TRAP_DOOR(167, TrapDoor.class),
PRISMARINE(168, Prismarine.class),
SEA_LANTERN(169),
HAY_BLOCK(170),
HAY_BLOCK(170, Hay.class),
CARPET(171),
HARD_CLAY(172),
COAL_BLOCK(173),
Expand Down
108 changes: 108 additions & 0 deletions src/main/java/org/bukkit/material/EnderPortalFrame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package org.bukkit.material;

import org.bukkit.block.BlockFace;
import org.bukkit.Material;

/**
* Represents an EnderPortalFrame
*/
public class EnderPortalFrame extends MaterialData implements Directional {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing javadocs

public EnderPortalFrame() {
super(Material.ENDER_PORTAL_FRAME);
}

/**
* @deprecated magic value
*/
public EnderPortalFrame(int type) {
super(type);
}

public EnderPortalFrame(Material type) {
super(type);
}

/**
* @deprecated magic value
*/
public EnderPortalFrame(int type, byte data) {
super(type, data);
}

/**
* @deprecated magic value
*/
public EnderPortalFrame(Material type, byte data) {
super(type, data);
}

/**
* Gets whether an EYE_OF_ENDER was placed in this block
* @return true if an EYE_OF_ENDER was placed in this block, false otherwise
*/
public boolean hasEye() {
return getData() > 3;
}

/**
* Sets whether an EYE_OF_ENDER was placed in this block
* @param hasEye whether an EYE_OF_ENDER was placed in this block
*/
public void setEye(boolean hasEye) {
byte data = getData();
if (hasEye)
data |= 0x4;
else
data &= 0x3;
setData(data);
}

@Override
public void setFacingDirection(BlockFace face) {
byte data = (byte) (getData() & 0x4);

switch (face) {
case SOUTH:
data |= 0x0;
break;
case WEST:
data |= 0x1;
break;
case NORTH:
data |= 0x2;
break;
case EAST:
default:
data |= 0x3;
break;
}

setData(data);
}

@Override
public BlockFace getFacing() {
switch (getData() & 0x3) {
case 0:
return BlockFace.SOUTH;
case 1:
return BlockFace.WEST;
case 2:
return BlockFace.NORTH;
case 3:
return BlockFace.EAST;
}

return null;
}

@Override
public EnderPortalFrame clone() {
return (EnderPortalFrame) super.clone();
}

@Override
public String toString() {
return super.toString() + " with" + (hasEye() ? "" : "out") + " eye of ender facing " + getFacing();
}
}
75 changes: 75 additions & 0 deletions src/main/java/org/bukkit/material/Hay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.bukkit.material;

import org.bukkit.block.BlockFace;
import org.bukkit.Material;

/**
* Represents a hay block
*/
public class Hay extends MaterialData implements Directional {
/**
* @deprecated magic value
*/
public Hay(int type) {
super(type);
}

public Hay(Material type) {
super(type);
}

/**
* @deprecated magic value
*/
public Hay(int type, byte data) {
super(type, data);
}

/**
* @deprecated magic value
*/
public Hay(Material type, byte data) {
super(type, data);
}

@Override
public void setFacingDirection(BlockFace face) {
switch (face) {
case NORTH:
case SOUTH:
setData((byte) 8);
break;
case WEST:
case EAST:
setData((byte) 4);
break;
case UP:
case DOWN:
setData((byte) 0);
break;
}
}

@Override
public BlockFace getFacing() {
switch (getData()) {
case 8:
return BlockFace.NORTH;
case 4:
return BlockFace.EAST;
case 0:
default:
return BlockFace.UP;
}
}

@Override
public String toString() {
return super.toString() + " facing " + getFacing();
}

@Override
public Hay clone() {
return (Hay) super.clone();
}
}
35 changes: 35 additions & 0 deletions src/main/java/org/bukkit/material/Lever.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,41 @@ public void setFacingDirection(BlockFace face) {
byte data = (byte) (getData() & 0x8);
BlockFace attach = getAttachedFace();

if (face == BlockFace.UP) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is going on here? There appears to be several changes that do not need to be made

switch (attach) {
case NORTH:
case SOUTH:
data |= 0x5;
break;

case EAST:
case WEST:
default:
data |= 0x6;
break;

}

setData(data);
return;
} else if (face == BlockFace.DOWN) {
switch (attach) {
case EAST:
case WEST:
data |= 0x0;
break;

case NORTH:
case SOUTH:
default:
data |= 0x7;
break;
}

setData(data);
return;
}

if (attach == BlockFace.DOWN) {
switch (face) {
case SOUTH:
Expand Down