mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-22 08:57:35 +01:00
Make CraftBlockState use BlockPosition
This commit is contained in:
parent
89ab488721
commit
fc1024944e
@ -1,7 +1,5 @@
|
|||||||
package org.bukkit.craftbukkit.block;
|
package org.bukkit.craftbukkit.block;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import net.minecraft.server.EnumColor;
|
|
||||||
import net.minecraft.server.TileEntityBed;
|
import net.minecraft.server.TileEntityBed;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
@ -21,22 +21,17 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.minecraft.server.GeneratorAccess;
|
import net.minecraft.server.GeneratorAccess;
|
||||||
import net.minecraft.server.IBlockData;
|
import net.minecraft.server.IBlockData;
|
||||||
import org.bukkit.craftbukkit.util.CraftLegacy;
|
|
||||||
|
|
||||||
public class CraftBlockState implements BlockState {
|
public class CraftBlockState implements BlockState {
|
||||||
private final CraftWorld world;
|
private final CraftWorld world;
|
||||||
private final CraftChunk chunk;
|
private final CraftChunk chunk;
|
||||||
private final int x;
|
protected final BlockPosition position;
|
||||||
private final int y;
|
|
||||||
private final int z;
|
|
||||||
protected IBlockData data;
|
protected IBlockData data;
|
||||||
protected int flag;
|
protected int flag;
|
||||||
|
|
||||||
public CraftBlockState(final Block block) {
|
public CraftBlockState(final Block block) {
|
||||||
this.world = (CraftWorld) block.getWorld();
|
this.world = (CraftWorld) block.getWorld();
|
||||||
this.x = block.getX();
|
this.position = ((CraftBlock) block).getPosition();
|
||||||
this.y = block.getY();
|
|
||||||
this.z = block.getZ();
|
|
||||||
this.data = ((CraftBlock) block).getNMS();
|
this.data = ((CraftBlock) block).getNMS();
|
||||||
this.chunk = (CraftChunk) block.getChunk();
|
this.chunk = (CraftChunk) block.getChunk();
|
||||||
this.flag = 3;
|
this.flag = 3;
|
||||||
@ -51,7 +46,7 @@ public class CraftBlockState implements BlockState {
|
|||||||
world = null;
|
world = null;
|
||||||
data = CraftMagicNumbers.getBlock(material).getBlockData();
|
data = CraftMagicNumbers.getBlock(material).getBlockData();
|
||||||
chunk = null;
|
chunk = null;
|
||||||
x = y = z = 0;
|
position = BlockPosition.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CraftBlockState getBlockState(GeneratorAccess world, net.minecraft.server.BlockPosition pos) {
|
public static CraftBlockState getBlockState(GeneratorAccess world, net.minecraft.server.BlockPosition pos) {
|
||||||
@ -68,15 +63,15 @@ public class CraftBlockState implements BlockState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getX() {
|
public int getX() {
|
||||||
return x;
|
return position.getX();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getY() {
|
public int getY() {
|
||||||
return y;
|
return position.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getZ() {
|
public int getZ() {
|
||||||
return z;
|
return position.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chunk getChunk() {
|
public Chunk getChunk() {
|
||||||
@ -149,7 +144,7 @@ public class CraftBlockState implements BlockState {
|
|||||||
|
|
||||||
public CraftBlock getBlock() {
|
public CraftBlock getBlock() {
|
||||||
requirePlaced();
|
requirePlaced();
|
||||||
return (CraftBlock) world.getBlockAt(x, y, z);
|
return CraftBlock.at(world.getHandle(), position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean update() {
|
public boolean update() {
|
||||||
@ -172,11 +167,10 @@ public class CraftBlockState implements BlockState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockPosition pos = new BlockPosition(x, y, z);
|
|
||||||
IBlockData newBlock = this.data;
|
IBlockData newBlock = this.data;
|
||||||
block.setTypeAndData(newBlock, applyPhysics);
|
block.setTypeAndData(newBlock, applyPhysics);
|
||||||
world.getHandle().notify(
|
world.getHandle().notify(
|
||||||
pos,
|
position,
|
||||||
block.getNMS(),
|
block.getNMS(),
|
||||||
newBlock,
|
newBlock,
|
||||||
3
|
3
|
||||||
@ -184,7 +178,7 @@ public class CraftBlockState implements BlockState {
|
|||||||
|
|
||||||
// Update levers etc
|
// Update levers etc
|
||||||
if (false && applyPhysics && getData() instanceof Attachable) { // Call does not map to new API
|
if (false && applyPhysics && getData() instanceof Attachable) { // Call does not map to new API
|
||||||
world.getHandle().applyPhysics(pos.shift(CraftBlock.blockFaceToNotch(((Attachable) getData()).getAttachedFace())), newBlock.getBlock());
|
world.getHandle().applyPhysics(position.shift(CraftBlock.blockFaceToNotch(((Attachable) getData()).getAttachedFace())), newBlock.getBlock());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -195,15 +189,15 @@ public class CraftBlockState implements BlockState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
return new Location(world, x, y, z);
|
return new Location(world, getX(), getY(), getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation(Location loc) {
|
public Location getLocation(Location loc) {
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
loc.setWorld(world);
|
loc.setWorld(world);
|
||||||
loc.setX(x);
|
loc.setX(getX());
|
||||||
loc.setY(y);
|
loc.setY(getY());
|
||||||
loc.setZ(z);
|
loc.setZ(getZ());
|
||||||
loc.setYaw(0);
|
loc.setYaw(0);
|
||||||
loc.setPitch(0);
|
loc.setPitch(0);
|
||||||
}
|
}
|
||||||
@ -227,13 +221,7 @@ public class CraftBlockState implements BlockState {
|
|||||||
if (this.world != other.world && (this.world == null || !this.world.equals(other.world))) {
|
if (this.world != other.world && (this.world == null || !this.world.equals(other.world))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.x != other.x) {
|
if (this.position != other.position && (this.position == null || !this.position.equals(other.position))) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.y != other.y) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.z != other.z) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.data != other.data && (this.data == null || !this.data.equals(other.data))) {
|
if (this.data != other.data && (this.data == null || !this.data.equals(other.data))) {
|
||||||
@ -246,9 +234,7 @@ public class CraftBlockState implements BlockState {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hash = 7;
|
int hash = 7;
|
||||||
hash = 73 * hash + (this.world != null ? this.world.hashCode() : 0);
|
hash = 73 * hash + (this.world != null ? this.world.hashCode() : 0);
|
||||||
hash = 73 * hash + this.x;
|
hash = 73 * hash + (this.position != null ? this.position.hashCode() : 0);
|
||||||
hash = 73 * hash + this.y;
|
|
||||||
hash = 73 * hash + this.z;
|
|
||||||
hash = 73 * hash + (this.data != null ? this.data.hashCode() : 0);
|
hash = 73 * hash + (this.data != null ? this.data.hashCode() : 0);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
@ -47,13 +47,10 @@ public class CraftChest extends CraftLootable<TileEntityChest> implements Chest
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The logic here is basically identical to the logic in BlockChest.interact
|
// The logic here is basically identical to the logic in BlockChest.interact
|
||||||
int x = this.getX();
|
|
||||||
int y = this.getY();
|
|
||||||
int z = this.getZ();
|
|
||||||
CraftWorld world = (CraftWorld) this.getWorld();
|
CraftWorld world = (CraftWorld) this.getWorld();
|
||||||
|
|
||||||
BlockChest blockChest = (BlockChest) (this.getType() == Material.CHEST ? Blocks.CHEST : Blocks.TRAPPED_CHEST);
|
BlockChest blockChest = (BlockChest) (this.getType() == Material.CHEST ? Blocks.CHEST : Blocks.TRAPPED_CHEST);
|
||||||
ITileInventory nms = blockChest.getInventory(data, world.getHandle(), new BlockPosition(x, y, z), true);
|
ITileInventory nms = blockChest.getInventory(data, world.getHandle(), position, true);
|
||||||
|
|
||||||
if (nms instanceof InventoryLargeChest) {
|
if (nms instanceof InventoryLargeChest) {
|
||||||
inventory = new CraftInventoryDoubleChest((InventoryLargeChest) nms);
|
inventory = new CraftInventoryDoubleChest((InventoryLargeChest) nms);
|
||||||
|
@ -32,13 +32,9 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
|
|||||||
CraftWorld world = (CraftWorld) this.getWorld();
|
CraftWorld world = (CraftWorld) this.getWorld();
|
||||||
Material record = this.getPlaying();
|
Material record = this.getPlaying();
|
||||||
if (record == Material.AIR) {
|
if (record == Material.AIR) {
|
||||||
world.getHandle().setTypeAndData(new BlockPosition(this.getX(), this.getY(), this.getZ()),
|
world.getHandle().setTypeAndData(position, Blocks.JUKEBOX.getBlockData().set(BlockJukeBox.HAS_RECORD, false), 3);
|
||||||
Blocks.JUKEBOX.getBlockData()
|
|
||||||
.set(BlockJukeBox.HAS_RECORD, false), 3);
|
|
||||||
} else {
|
} else {
|
||||||
world.getHandle().setTypeAndData(new BlockPosition(this.getX(), this.getY(), this.getZ()),
|
world.getHandle().setTypeAndData(position, Blocks.JUKEBOX.getBlockData().set(BlockJukeBox.HAS_RECORD, true), 3);
|
||||||
Blocks.JUKEBOX.getBlockData()
|
|
||||||
.set(BlockJukeBox.HAS_RECORD, true), 3);
|
|
||||||
}
|
}
|
||||||
world.playEffect(this.getLocation(), Effect.RECORD_PLAY, Item.getId(CraftMagicNumbers.getItem((Material) record)));
|
world.playEffect(this.getLocation(), Effect.RECORD_PLAY, Item.getId(CraftMagicNumbers.getItem((Material) record)));
|
||||||
}
|
}
|
||||||
@ -83,7 +79,7 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
|
|||||||
TileEntityJukeBox jukebox = (TileEntityJukeBox) tileEntity;
|
TileEntityJukeBox jukebox = (TileEntityJukeBox) tileEntity;
|
||||||
boolean result = !jukebox.getRecord().isEmpty();
|
boolean result = !jukebox.getRecord().isEmpty();
|
||||||
CraftWorld world = (CraftWorld) this.getWorld();
|
CraftWorld world = (CraftWorld) this.getWorld();
|
||||||
((BlockJukeBox) Blocks.JUKEBOX).dropRecord(world.getHandle(), new BlockPosition(getX(), getY(), getZ()));
|
((BlockJukeBox) Blocks.JUKEBOX).dropRecord(world.getHandle(), position);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user