mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-05 02:22:12 +01:00
Added MaterialData support for SAPPLING, POWERED_RAIL, and DETECTOR_RAIL.
By: sunkid <sunkid@iminurnetz.com>
This commit is contained in:
parent
24eb39b2e6
commit
314c53177e
7 changed files with 129 additions and 14 deletions
|
@ -18,7 +18,7 @@ public enum Material {
|
|||
DIRT(3),
|
||||
COBBLESTONE(4),
|
||||
WOOD(5),
|
||||
SAPLING(6, MaterialData.class),
|
||||
SAPLING(6, Tree.class),
|
||||
BEDROCK(7),
|
||||
WATER(8, MaterialData.class),
|
||||
STATIONARY_WATER(9, MaterialData.class),
|
||||
|
@ -39,8 +39,8 @@ public enum Material {
|
|||
SANDSTONE(24),
|
||||
NOTE_BLOCK(25),
|
||||
BED_BLOCK(26, Bed.class),
|
||||
POWERED_RAIL(27),
|
||||
DETECTOR_RAIL(28),
|
||||
POWERED_RAIL(27, PoweredRail.class),
|
||||
DETECTOR_RAIL(28, DetectorRail.class),
|
||||
WEB(30),
|
||||
WOOL(35, Wool.class),
|
||||
YELLOW_FLOWER(37),
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package org.bukkit.material;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
/**
|
||||
* Represents a detector rail
|
||||
*/
|
||||
public class DetectorRail extends ExtendedRails implements PressureSensor {
|
||||
public DetectorRail() {
|
||||
super(Material.DETECTOR_RAIL);
|
||||
}
|
||||
|
||||
public DetectorRail(final int type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
public DetectorRail(final Material type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
public DetectorRail(final int type, final byte data) {
|
||||
super(type, data);
|
||||
}
|
||||
|
||||
public DetectorRail(final Material type, final byte data) {
|
||||
super(type, data);
|
||||
}
|
||||
|
||||
public boolean isPressed() {
|
||||
return (getData() & 0x8) == 0x8;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package org.bukkit.material;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
/**
|
||||
* This is the superclass for the {@link DetectorRail} and {@link PoweredRail} classes
|
||||
*/
|
||||
public class ExtendedRails extends Rails {
|
||||
public ExtendedRails(final int type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
public ExtendedRails(final Material type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
public ExtendedRails(final int type, final byte data) {
|
||||
super(type, data);
|
||||
}
|
||||
|
||||
public ExtendedRails(final Material type, final byte data) {
|
||||
super(type, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurve() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte getConvertedData() {
|
||||
return (byte) (getData() & 0x7);
|
||||
}
|
||||
}
|
40
paper-api/src/main/java/org/bukkit/material/PoweredRail.java
Normal file
40
paper-api/src/main/java/org/bukkit/material/PoweredRail.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package org.bukkit.material;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
/**
|
||||
* Represents a powered rail
|
||||
*/
|
||||
public class PoweredRail extends ExtendedRails implements Redstone {
|
||||
public PoweredRail() {
|
||||
super(Material.POWERED_RAIL);
|
||||
}
|
||||
|
||||
public PoweredRail(final int type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
public PoweredRail(final Material type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
public PoweredRail(final int type, final byte data) {
|
||||
super(type, data);
|
||||
}
|
||||
|
||||
public PoweredRail(final Material type, final byte data) {
|
||||
super(type, data);
|
||||
}
|
||||
|
||||
public boolean isPowered() {
|
||||
return (getData() & 0x8) == 0x8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this PoweredRail should be powered or not.
|
||||
* @param isPowered whether or not the rail is powered
|
||||
*/
|
||||
public void setPowered(boolean isPowered) {
|
||||
setData((byte) (isPowered ? (getData() | 0x8) : (getData() & ~0x8)));
|
||||
}
|
||||
}
|
|
@ -4,14 +4,12 @@ import org.bukkit.Material;
|
|||
|
||||
/**
|
||||
* Represents a pressure plate
|
||||
* @author CelticMinstrel
|
||||
*
|
||||
*/
|
||||
public class PressurePlate extends MaterialData {
|
||||
public class PressurePlate extends MaterialData implements PressureSensor {
|
||||
public PressurePlate() {
|
||||
super(Material.WOOD_PLATE);
|
||||
}
|
||||
|
||||
|
||||
public PressurePlate(int type) {
|
||||
super(type);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package org.bukkit.material;
|
||||
|
||||
public interface PressureSensor {
|
||||
public boolean isPressed();
|
||||
}
|
|
@ -5,15 +5,13 @@ import org.bukkit.block.BlockFace;
|
|||
|
||||
/**
|
||||
* Represents minecart rails.
|
||||
*
|
||||
* @author sunkid
|
||||
*/
|
||||
public class Rails extends MaterialData {
|
||||
|
||||
public Rails() {
|
||||
super(Material.RAILS);
|
||||
}
|
||||
|
||||
|
||||
public Rails(final int type) {
|
||||
super(type);
|
||||
}
|
||||
|
@ -34,7 +32,7 @@ public class Rails extends MaterialData {
|
|||
* @return the whether this track is set on a slope
|
||||
*/
|
||||
public boolean isOnSlope() {
|
||||
byte d = getData();
|
||||
byte d = getConvertedData();
|
||||
return (d == 0x2 || d == 0x3 || d == 0x4 || d == 0x5);
|
||||
}
|
||||
|
||||
|
@ -42,7 +40,7 @@ public class Rails extends MaterialData {
|
|||
* @return the whether this track is set as a curve
|
||||
*/
|
||||
public boolean isCurve() {
|
||||
byte d = getData();
|
||||
byte d = getConvertedData();
|
||||
return (d == 0x6 || d == 0x7 || d == 0x8 || d == 0x9);
|
||||
}
|
||||
|
||||
|
@ -54,7 +52,7 @@ public class Rails extends MaterialData {
|
|||
* returned.
|
||||
*/
|
||||
public BlockFace getDirection() {
|
||||
byte d = getData();
|
||||
byte d = getConvertedData();
|
||||
switch (d) {
|
||||
case 0x0:
|
||||
default:
|
||||
|
@ -79,9 +77,17 @@ public class Rails extends MaterialData {
|
|||
return BlockFace.NORTH_WEST;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " facing " + getDirection() + (isCurve() ? " on a curve" : (isOnSlope() ? " on a slope" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data without the extended properties used by {@link PoweredRail} and {@link DetectorRail}. Overridden in {@link ExtendedRails}
|
||||
* @return the data without the extended part
|
||||
*/
|
||||
protected byte getConvertedData() {
|
||||
return getData();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue