Merge branch 'proto_1.12.2' into event
This commit is contained in:
@@ -24,10 +24,10 @@ public class CoreEventListener {
|
||||
log.trace("(GameLoop) playerMoveEventHandler()");
|
||||
|
||||
Chunk chunk;
|
||||
chunk = event.getPlayer().getWorld().getChunk(event.getOldLocation()); // Old chunk
|
||||
chunk = event.getPlayer().getWorld().getChunk(event.getOldLocation().toBlockLocation()); // Old chunk
|
||||
int ccX = chunk.getX();
|
||||
int ccZ = chunk.getZ();
|
||||
chunk = event.getPlayer().getWorld().getChunk(event.getNewLocation()); // Next chunk
|
||||
chunk = event.getPlayer().getWorld().getChunk(event.getNewLocation().toBlockLocation()); // Next chunk
|
||||
int ncX = chunk.getX();
|
||||
int ncZ = chunk.getZ();
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package mc.core;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import mc.core.world.block.BlockLocation;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@@ -32,15 +34,19 @@ public class EntityLocation implements Cloneable {
|
||||
}
|
||||
|
||||
public int getBlockX() {
|
||||
return Double.valueOf(Math.floor(x)).intValue();
|
||||
return (int) Math.floor(x);
|
||||
}
|
||||
|
||||
public int getBlockY() {
|
||||
return Double.valueOf(Math.floor(y)).intValue();
|
||||
return (int) Math.floor(y);
|
||||
}
|
||||
|
||||
public int getBlockZ() {
|
||||
return Double.valueOf(Math.floor(z)).intValue();
|
||||
return (int) Math.floor(z);
|
||||
}
|
||||
|
||||
public BlockLocation toBlockLocation() {
|
||||
return new BlockLocation(getBlockX(), getBlockY(), getBlockZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,7 +55,7 @@ public class EntityLocation implements Cloneable {
|
||||
return (EntityLocation) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
return ZERO();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package mc.core.nbt;
|
||||
|
||||
import com.flowpowered.nbt.Tag;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface Taggable {
|
||||
Tag<?> getTag(String name);
|
||||
void setTag(Tag<?> tag);
|
||||
Stream<Tag<?>> tagStream();
|
||||
}
|
||||
@@ -1,22 +1,23 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-07-25
|
||||
*/
|
||||
package mc.core.network;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class NetInputStream {
|
||||
public abstract class NetInputStream extends InputStream {
|
||||
@Getter
|
||||
@Setter
|
||||
private int dataSize;
|
||||
|
||||
public abstract boolean readBoolean();
|
||||
public abstract byte readByte();
|
||||
public abstract void readBytes(byte[] buffer);
|
||||
public int readBytes(byte[] buffer) {
|
||||
return readBytes(buffer, 0, buffer.length);
|
||||
}
|
||||
public abstract int readBytes(byte[] buffer, int offset, int length);
|
||||
public abstract int readUnsignedByte();
|
||||
public abstract int readUnsignedShort();
|
||||
public abstract short readShort();
|
||||
@@ -30,4 +31,25 @@ public abstract class NetInputStream {
|
||||
public abstract UUID readUUID();
|
||||
|
||||
public abstract void skipBytes(int count);
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return readByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b) throws IOException {
|
||||
return readBytes(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
return readBytes(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long skip(long n) throws IOException {
|
||||
skipBytes((int) n);
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-07-25
|
||||
*/
|
||||
package mc.core.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class NetOutputStream {
|
||||
public abstract class NetOutputStream extends OutputStream {
|
||||
public abstract void writeBoolean(boolean value);
|
||||
public abstract void writeByte(int value);
|
||||
public abstract void writeUnsignedByte(int value);
|
||||
public abstract void writeBytes(byte[] buffer);
|
||||
public void writeBytes(byte[] buffer) {
|
||||
writeBytes(buffer, 0, buffer.length);
|
||||
}
|
||||
public abstract void writeBytes(byte[] buffer, int offset, int lengtn);
|
||||
public abstract void writeShort(int value);
|
||||
public abstract void writeInt(int value);
|
||||
public abstract void writeVarInt(int value);
|
||||
@@ -19,4 +20,19 @@ public abstract class NetOutputStream {
|
||||
public abstract void writeDouble(double value);
|
||||
public abstract void writeString(String value);
|
||||
public abstract void writeUUID(UUID uuid);
|
||||
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
writeByte(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b) throws IOException {
|
||||
writeBytes(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
writeBytes(b, off, len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,57 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-04-15
|
||||
*/
|
||||
package mc.core.world;
|
||||
|
||||
import mc.core.EntityLocation;
|
||||
import mc.core.world.block.Block;
|
||||
import mc.core.world.block.BlockLocation;
|
||||
import mc.core.world.chunk.Chunk;
|
||||
|
||||
public interface World {
|
||||
String getName();
|
||||
WorldType getWorldType();
|
||||
WorldType getType();
|
||||
|
||||
EntityLocation getSpawn();
|
||||
|
||||
void setSpawn(EntityLocation location);
|
||||
|
||||
default void setSpawn(double x, double y, double z, float yaw, float pitch) {
|
||||
setSpawn(new EntityLocation(x, y, z, yaw, pitch));
|
||||
}
|
||||
|
||||
default void setSpawn(double x, double y, double z) {
|
||||
setSpawn(x, y, z, 0f, 0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить чанк по его координатам
|
||||
* @param x chunk X
|
||||
* @param z chunk Z
|
||||
* @return {@link Chunk}
|
||||
*/
|
||||
Chunk getChunk(int x, int z);
|
||||
void setChunk(int x, int z, Chunk chunkSection);
|
||||
|
||||
/**
|
||||
* Получить чанк по глобальным координатам блока
|
||||
* @param location {@link BlockLocation}
|
||||
* @return {@link Chunk}
|
||||
*/
|
||||
default Chunk getChunk(BlockLocation location) {
|
||||
return getChunk(location.getX() >> 4, location.getZ() >> 4);
|
||||
}
|
||||
|
||||
default Chunk getChunk(EntityLocation location) {
|
||||
return getChunk(location.getBlockX() >> 4, location.getBlockZ() >> 4);
|
||||
void setChunk(int x, int z, Chunk chunk);
|
||||
|
||||
/**
|
||||
* Получить блок по его координатам
|
||||
* @param x X
|
||||
* @param y Y
|
||||
* @param z Z
|
||||
* @return {@link Block}
|
||||
*/
|
||||
Block getBlock(int x, int y, int z);
|
||||
|
||||
default Block getBlock(BlockLocation location) {
|
||||
return getBlock(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
void setBlock(Block block);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
package mc.core.world.block;
|
||||
|
||||
import com.flowpowered.nbt.Tag;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class AbstractBlock implements Block {
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -15,11 +10,10 @@ public abstract class AbstractBlock implements Block {
|
||||
@Getter
|
||||
private int light = 0;
|
||||
@Getter
|
||||
private final BlockType blockType;
|
||||
private final Map<String, Tag<?>> nbtTagsMap = new HashMap<>();
|
||||
private final BlockType type;
|
||||
|
||||
protected AbstractBlock(BlockType type) {
|
||||
this.blockType = type;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -28,19 +22,4 @@ public abstract class AbstractBlock implements Block {
|
||||
else if (light < 0) this.light = 0;
|
||||
else this.light = light;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag<?> getTag(String name) {
|
||||
return nbtTagsMap.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTag(Tag<?> tag) {
|
||||
nbtTagsMap.put(tag.getName(), tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<Tag<?>> tagStream() {
|
||||
return nbtTagsMap.values().stream();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package mc.core.world.block;
|
||||
|
||||
import mc.core.nbt.Taggable;
|
||||
|
||||
public interface Block extends Taggable{
|
||||
public interface Block {
|
||||
int getLight();
|
||||
void setLight(int light);
|
||||
BlockType getBlockType();
|
||||
BlockType getType();
|
||||
BlockLocation getLocation();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class BlockLocation implements Cloneable {
|
||||
return (BlockLocation) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
return ZERO();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mc.core.world.chunk;
|
||||
|
||||
import mc.core.world.Biome;
|
||||
import mc.core.world.block.Block;
|
||||
|
||||
public interface Chunk {
|
||||
int getX();
|
||||
@@ -9,6 +10,28 @@ public interface Chunk {
|
||||
ChunkSection getChunkSection(int height);
|
||||
void setChunkSection(int height, ChunkSection chunkSection);
|
||||
|
||||
Biome getBiome(int localX, int localZ);
|
||||
void setBiome(int localX, int localZ, Biome biome);
|
||||
/**
|
||||
* Получить блок по глобальным координатам секции чанка
|
||||
* @param x global X
|
||||
* @param y global Y
|
||||
* @param z global Z
|
||||
* @return {@link Block}
|
||||
*/
|
||||
Block getBlock(int x, int y, int z);
|
||||
void setBlock(Block block);
|
||||
|
||||
int getSkyLight(int x, int y, int z);
|
||||
void setSkyLight(int x, int y, int z, int lightLevel);
|
||||
|
||||
int getAddition(int x, int y, int z);
|
||||
void setAddition(int x, int y, int z, int value);
|
||||
|
||||
/**
|
||||
* Получить тип биома по глобальным координатам
|
||||
* @param x global X
|
||||
* @param z global Z
|
||||
* @return
|
||||
*/
|
||||
Biome getBiome(int x, int z);
|
||||
void setBiome(int x, int z, Biome biome);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,29 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-04-15
|
||||
*/
|
||||
package mc.core.world.chunk;
|
||||
|
||||
import mc.core.world.Biome;
|
||||
import mc.core.world.block.Block;
|
||||
|
||||
/* 16x16x16 */
|
||||
/**
|
||||
* Секция чанка размером 16x16x16 блоков
|
||||
*/
|
||||
public interface ChunkSection {
|
||||
int getX();
|
||||
Chunk getParent();
|
||||
void setParent(Chunk chunk);
|
||||
|
||||
int getY();
|
||||
int getZ();
|
||||
|
||||
/**
|
||||
* Получить блок по локальным координатам секции чанка
|
||||
* @param localX local X (0-15)
|
||||
* @param localY local Y (0-15)
|
||||
* @param localZ local Z (0-15)
|
||||
* @return {@link Block}
|
||||
*/
|
||||
Block getBlock(int localX, int localY, int localZ);
|
||||
void setBlock(Block block);
|
||||
Block getBlock(int x, int y, int z);
|
||||
|
||||
int getSkyLight(int x, int y, int z);
|
||||
void setSkyLight(int x, int y, int z, int lightLevel);
|
||||
int getSkyLight(int localX, int localY, int localZ);
|
||||
void setSkyLight(int localX, int localY, int localZ, int lightLevel);
|
||||
|
||||
int getAddition(int x, int y, int z);
|
||||
void setAddition(int x, int y, int z, int value);
|
||||
|
||||
Biome getBiome(int localX, int localZ);
|
||||
int getAddition(int localX, int localY, int localZ);
|
||||
void setAddition(int localX, int localY, int localZ, int value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user