Compare commits
22 Commits
g1/master
...
g1/dev/tes
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b91ca72c5 | |||
| 6057746178 | |||
| ce962f5896 | |||
| 82fa03a8e7 | |||
| 3f062b9873 | |||
| fa2e992c3d | |||
| cade216ff4 | |||
| d5b2557104 | |||
| 1e6e9500c1 | |||
| 63b68c481b | |||
| 74f725eec4 | |||
| 96a69f1bca | |||
| 3a25bc34f4 | |||
| b95dd2dfdc | |||
| 441e0e91d2 | |||
| d4a3a49b47 | |||
| 667ea373b8 | |||
| 50d4da653c | |||
| d47fb586ca | |||
| f08190fba7 | |||
| c89f3e9356 | |||
| 4a7790cd72 |
@@ -1,7 +1,6 @@
|
||||
package com.flowpowered.nbt;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public enum TagType {
|
||||
|
||||
@@ -7,7 +7,6 @@ import mc.core.world.chunk.Chunk;
|
||||
import mc.core.world.chunk.ChunkProvider;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@@ -20,7 +19,7 @@ public class AnvilChunkProvider implements ChunkProvider {
|
||||
|
||||
public AnvilChunkProvider(String mapPath) {
|
||||
Path pathMap = Paths.get(mapPath);
|
||||
if (Files.exists(pathMap)) {
|
||||
if (pathMap.toFile().exists()) {
|
||||
log.info("Use Anvil map from \"{}\"", pathMap);
|
||||
this.setRegionManager(new RegionManager(pathMap.resolve("region")));
|
||||
} else {
|
||||
|
||||
@@ -2,7 +2,6 @@ package mc.world.anvil;
|
||||
|
||||
import gnu.trove.list.TByteList;
|
||||
import gnu.trove.list.array.TByteArrayList;
|
||||
import gnu.trove.list.linked.TByteLinkedList;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import mc.core.utils.NibbleArray;
|
||||
|
||||
@@ -7,7 +7,6 @@ import mc.core.utils.CompactedCoords;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@@ -32,7 +31,7 @@ public class RegionManager {
|
||||
return regions.get(xz);
|
||||
} else {
|
||||
Path regionFilePath = regionFilesPath.resolve("r." + x + "." + z + ".mca");
|
||||
if (Files.exists(regionFilePath)) {
|
||||
if (regionFilePath.toFile().exists()) {
|
||||
try {
|
||||
Region region = new Region(regionFilePath.toFile());
|
||||
regions.put(xz, region);
|
||||
|
||||
24
build.gradle
24
build.gradle
@@ -25,6 +25,7 @@ plugins {
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
maven { url 'https://oss.sonatype.org/content/groups/public/' }
|
||||
}
|
||||
@@ -32,6 +33,7 @@ allprojects {
|
||||
|
||||
subprojects {
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'jacoco'
|
||||
|
||||
compileJava {
|
||||
sourceCompatibility = 1.8
|
||||
@@ -64,24 +66,28 @@ subprojects {
|
||||
compile (group: 'org.springframework', name: 'spring-context', version: spring_version)
|
||||
|
||||
/* Lombok */
|
||||
annotationProcessor (group: 'org.projectlombok', name: 'lombok', version: lombok_version)
|
||||
compile (group: 'org.projectlombok', name: 'lombok', version: lombok_version)
|
||||
annotationProcessor (group: 'org.projectlombok', name: 'lombok', version: lombok_version)
|
||||
compile (group: 'org.projectlombok', name: 'lombok', version: lombok_version)
|
||||
testAnnotationProcessor (group: 'org.projectlombok', name: 'lombok', version: lombok_version)
|
||||
testCompile (group: 'org.projectlombok', name: 'lombok', version: lombok_version)
|
||||
testCompile (group: 'org.projectlombok', name: 'lombok', version: lombok_version)
|
||||
|
||||
/* Testing */
|
||||
testImplementation (group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junit_version)
|
||||
testRuntimeOnly(group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junit_version)
|
||||
testImplementation(group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junit_version)
|
||||
testCompile (group: 'org.slf4j', name: 'slf4j-simple', version: slf4j_version)
|
||||
testCompile (group: 'org.mockito', name: 'mockito-core', version: '1.10.19')
|
||||
testCompile (group: 'org.springframework', name: 'spring-test', version: spring_version)
|
||||
testImplementation (group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junit_version)
|
||||
testRuntimeOnly (group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junit_version)
|
||||
testImplementation (group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junit_version)
|
||||
testCompile (group: 'org.slf4j', name: 'slf4j-simple', version: slf4j_version)
|
||||
testCompile (group: 'org.mockito', name: 'mockito-core', version: '1.10.19')
|
||||
testCompile (group: 'org.springframework', name: 'spring-test', version: spring_version)
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
jacoco {
|
||||
toolVersion = '0.8.3'
|
||||
}
|
||||
|
||||
task copyDep(type: Copy) {
|
||||
into 'libs'
|
||||
from configurations.compile + configurations.runtime - configurations.compile_excludeCopy
|
||||
|
||||
@@ -19,6 +19,40 @@ public class CoreEventListener {
|
||||
EventBus.getInstance().registerSubscribes(this);
|
||||
}
|
||||
|
||||
private void processLoadChunks(CS_PlayerMoveEvent event, int cMinX, int cMaxX, int cMinZ, int cMaxZ) {
|
||||
SC_ChunkLoadEvent eventChunkLoad = new SC_ChunkLoadEvent(event.getPlayer());
|
||||
for (int cZ = cMinZ; cZ <= cMaxZ; cZ++) {
|
||||
for (int cX = cMinX; cX <= cMaxX; cX++) {
|
||||
int compressXZ = CompactedCoords.compressXZ(cX, cZ);
|
||||
if (!event.getPlayer().getLoadedChunks().contains(compressXZ)) {
|
||||
eventChunkLoad.getNeedLoadChunks().add(compressXZ);
|
||||
event.getPlayer().getLoadedChunks().add(compressXZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!eventChunkLoad.getNeedLoadChunks().isEmpty()) {
|
||||
EventBus.getInstance().post(eventChunkLoad);
|
||||
}
|
||||
}
|
||||
|
||||
private void processUnloadChunks(CS_PlayerMoveEvent event, int cMinX, int cMaxX, int cMinZ, int cMaxZ) {
|
||||
SC_ChunkUnloadEvent eventChunkUnload = new SC_ChunkUnloadEvent(event.getPlayer());
|
||||
Iterator<Integer> itr = event.getPlayer().getLoadedChunks().iterator();
|
||||
while(itr.hasNext()) {
|
||||
int compressXZ = itr.next();
|
||||
int[] xz = CompactedCoords.uncompressXZ(compressXZ);
|
||||
if (xz[0] > cMaxX || xz[0] < cMinX || xz[1] > cMaxZ || xz[1] < cMinZ) {
|
||||
eventChunkUnload.getNeedUnloadChunks().add(compressXZ);
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (!eventChunkUnload.getNeedUnloadChunks().isEmpty()) {
|
||||
EventBus.getInstance().post(eventChunkUnload);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscriber
|
||||
public void handlerPlayerMoveEvent(CS_PlayerMoveEvent event) {
|
||||
Chunk chunk;
|
||||
@@ -33,42 +67,14 @@ public class CoreEventListener {
|
||||
|
||||
if (event.isRecalcChunk() || (ncX != ccX || ncZ != ccZ)) {
|
||||
final int viewDistance = event.getPlayer().getSettings().getViewDistance() + 1;
|
||||
int cMinX = chunk.getX() - viewDistance;
|
||||
int cMaxX = chunk.getX() + viewDistance;
|
||||
int cMinZ = chunk.getZ() - viewDistance;
|
||||
int cMaxZ = chunk.getZ() + viewDistance;
|
||||
final int cMinX = chunk.getX() - viewDistance;
|
||||
final int cMaxX = chunk.getX() + viewDistance;
|
||||
final int cMinZ = chunk.getZ() - viewDistance;
|
||||
final int cMaxZ = chunk.getZ() + viewDistance;
|
||||
|
||||
SC_ChunkLoadEvent eventChunkLoad = new SC_ChunkLoadEvent(event.getPlayer());
|
||||
for (int cZ = cMinZ; cZ <= cMaxZ; cZ++) {
|
||||
for (int cX = cMinX; cX <= cMaxX; cX++) {
|
||||
int compressXZ = CompactedCoords.compressXZ(cX, cZ);
|
||||
if (!event.getPlayer().getLoadedChunks().contains(compressXZ)) {
|
||||
if (!event.getPlayer().getLoadedChunks().contains(compressXZ)) {
|
||||
eventChunkLoad.getNeedLoadChunks().add(compressXZ);
|
||||
event.getPlayer().getLoadedChunks().add(compressXZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
processLoadChunks(event, cMinX, cMaxX, cMinZ, cMaxZ);
|
||||
processUnloadChunks(event, cMinX, cMaxX, cMinZ, cMaxZ);
|
||||
|
||||
if (!eventChunkLoad.getNeedLoadChunks().isEmpty()) {
|
||||
EventBus.getInstance().post(eventChunkLoad);
|
||||
}
|
||||
|
||||
SC_ChunkUnloadEvent eventChunkUnload = new SC_ChunkUnloadEvent(event.getPlayer());
|
||||
Iterator<Integer> itr = event.getPlayer().getLoadedChunks().iterator();
|
||||
while(itr.hasNext()) {
|
||||
int compressXZ = itr.next();
|
||||
int[] xz = CompactedCoords.uncompressXZ(compressXZ);
|
||||
if (xz[0] > cMaxX || xz[0] < cMinX || xz[1] > cMaxZ || xz[1] < cMinZ) {
|
||||
eventChunkUnload.getNeedUnloadChunks().add(compressXZ);
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (!eventChunkUnload.getNeedUnloadChunks().isEmpty()) {
|
||||
EventBus.getInstance().post(eventChunkUnload);
|
||||
}
|
||||
}
|
||||
|
||||
event.getPlayer().getLocation().setXYZ(
|
||||
|
||||
@@ -3,12 +3,14 @@ package mc.core;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.world.block.BlockLocation;
|
||||
|
||||
@Slf4j
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class EntityLocation implements Cloneable {
|
||||
public class EntityLocation {
|
||||
private double x, y, z;
|
||||
private float yaw, pitch;
|
||||
|
||||
@@ -48,13 +50,7 @@ public class EntityLocation implements Cloneable {
|
||||
return new BlockLocation(getBlockX(), getBlockY(), getBlockZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityLocation clone() {
|
||||
try {
|
||||
return (EntityLocation) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
return ZERO();
|
||||
}
|
||||
public EntityLocation copy() {
|
||||
return new EntityLocation(x, y, z, yaw, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,17 +7,16 @@ import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@Slf4j
|
||||
public class Main {
|
||||
private static ApplicationContext createContext() {
|
||||
final String springXml = System.getProperty("springConfig", "./spring.xml");
|
||||
|
||||
if (!Files.exists(Paths.get(springXml))) {
|
||||
if (!(new File(springXml)).exists()) {
|
||||
log.info("File \"{}\" not found. Get default config.", springXml);
|
||||
try (FileOutputStream fos = new FileOutputStream(springXml)) {
|
||||
IOUtils.copy(Main.class.getResourceAsStream("/spring.xml"), fos);
|
||||
|
||||
@@ -2,7 +2,6 @@ package mc.core.embedded;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.network.Server;
|
||||
import mc.core.network.StartServerException;
|
||||
|
||||
@Slf4j
|
||||
public class FakeServer implements Server {
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.slf4j.helpers.MessageFormatter;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.stream.Stream;
|
||||
@@ -25,9 +26,11 @@ public class EventBus {
|
||||
private Stream<Method> getMethods(Object subscriberObject) {
|
||||
return Stream.of(subscriberObject.getClass().getDeclaredMethods())
|
||||
.filter(method -> method.isAnnotationPresent(Subscriber.class))
|
||||
.filter(method -> !Modifier.isPrivate(method.getModifiers()))
|
||||
.filter(method -> method.getReturnType().equals(Void.TYPE))
|
||||
.filter(method -> method.getParameterCount() == 1)
|
||||
.filter(method -> Event.class.isAssignableFrom(method.getParameterTypes()[0]));
|
||||
.filter(method -> Event.class.isAssignableFrom(method.getParameterTypes()[0]))
|
||||
.filter(method -> method.getParameterTypes()[0] != Event.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -63,25 +66,25 @@ public class EventBus {
|
||||
}
|
||||
|
||||
public void post(Event event) {
|
||||
eventQueue.add(event);
|
||||
if (subscribes.containsKey(event.getClass())) {
|
||||
eventQueue.add(event);
|
||||
}
|
||||
}
|
||||
|
||||
public void process() {
|
||||
Event event;
|
||||
while ((event = eventQueue.poll()) != null) {
|
||||
final Class<? extends Event> type = event.getClass();
|
||||
if (subscribes.containsKey(type)) {
|
||||
final List<Pair<Object, Method>> pairs = subscribes.get(type);
|
||||
for (Pair<Object, Method> pair : pairs) {
|
||||
try {
|
||||
pair.getValue().invoke(pair.getKey(), event);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
log.error(MessageFormatter.format("Invoke method '{}#{}'",
|
||||
pair.getKey().getClass().getSimpleName(),
|
||||
pair.getValue().getName()).getMessage(),
|
||||
e
|
||||
);
|
||||
}
|
||||
final List<Pair<Object, Method>> pairs = subscribes.get(type);
|
||||
for (Pair<Object, Method> pair : pairs) {
|
||||
try {
|
||||
pair.getValue().invoke(pair.getKey(), event);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
log.error(MessageFormatter.format("Invoke method '{}#{}'",
|
||||
pair.getKey().getClass().getSimpleName(),
|
||||
pair.getValue().getName()).getMessage(),
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public abstract class NetInputStream extends InputStream {
|
||||
public abstract double readDouble();
|
||||
public abstract String readString();
|
||||
public abstract UUID readUUID();
|
||||
public abstract Tag<?> readNBT();
|
||||
public abstract Tag readNBT();
|
||||
|
||||
public abstract void skipBytes(int count);
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package mc.core.utils;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class CompactedCoords {
|
||||
public static int compressXZ(int x, int z) {
|
||||
if (x < Short.MIN_VALUE || x > Short.MAX_VALUE ||
|
||||
|
||||
@@ -2,7 +2,6 @@ package mc.core.world;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
@@ -3,11 +3,13 @@ package mc.core.world.block;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class BlockLocation implements Cloneable {
|
||||
public class BlockLocation {
|
||||
private int x, y, z;
|
||||
|
||||
public static BlockLocation ZERO() {
|
||||
@@ -20,13 +22,7 @@ public class BlockLocation implements Cloneable {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockLocation clone() {
|
||||
try {
|
||||
return (BlockLocation) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
return ZERO();
|
||||
}
|
||||
public BlockLocation copy() {
|
||||
return new BlockLocation(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public enum BlockType {
|
||||
@@ -29,6 +29,8 @@ public enum BlockType {
|
||||
PATH(208, 0),
|
||||
|
||||
DIRT(3, 0),
|
||||
COARSE(3, 1),
|
||||
PODZOL(3, 2),
|
||||
|
||||
/** Farmland, Dry, Moisture 0 */
|
||||
FARMLAND (60, 0),
|
||||
@@ -48,7 +50,7 @@ public enum BlockType {
|
||||
FARMLAND_7(60, 7),
|
||||
|
||||
COBBLESTONE(4, 0),
|
||||
BEDROCK(7, 0),
|
||||
COBBLESTONE_WALL(139, 0),
|
||||
|
||||
/** Water, flowing, Level 7 (Source) */
|
||||
WATER_FLOWING (8, 0),
|
||||
@@ -193,7 +195,7 @@ public enum BlockType {
|
||||
ORE_LAPIS (21, 0),
|
||||
ORE_DIAMOND (56, 0),
|
||||
ORE_REDSTONE (73, 0),
|
||||
ORE_GLOWING_REDSTONE(74, 0),
|
||||
ORE_REDSTONE_GLOWING(74, 0),
|
||||
ORE_EMERALD (129, 0),
|
||||
|
||||
// Upright
|
||||
@@ -220,6 +222,14 @@ public enum BlockType {
|
||||
WOOD_ACACIA_NS (162, 8),
|
||||
WOOD_OAK_DARK_NS(162, 9),
|
||||
|
||||
// Bark
|
||||
WOOD_OAK_BARK (17, 12),
|
||||
WOOD_SPRUCE_BARK (17, 13),
|
||||
WOOD_BIRCH_BARK (17, 14),
|
||||
WOOD_JUNGLE_BARK (17, 15),
|
||||
WOOD_ACACIA_BARK (162, 12),
|
||||
WOOD_OAK_DARK_BARK(162, 13),
|
||||
|
||||
PLANK_WOOD_OAK (5, 0),
|
||||
PLANK_WOOD_SPRUCE (5, 1),
|
||||
PLANK_WOOD_BIRCH (5, 2),
|
||||
@@ -227,25 +237,101 @@ public enum BlockType {
|
||||
PLANK_WOOD_ACACIA (5, 4),
|
||||
PLANK_WOOD_OAK_DARK(5, 5),
|
||||
|
||||
DOOR_LOW_OAK_EAST(64, 0),
|
||||
DOOR_LOW_OAK_SOUTH(64, 1),
|
||||
DOOR_LOW_OAK_WEST(64, 2),
|
||||
DOOR_LOW_OAK_NORTH(64, 3),
|
||||
DOOR_LOW_OAK_EAST_OPENED(64, 4),
|
||||
DOOR_LOW_OAK_SOUTH_OPENED(64, 5),
|
||||
DOOR_LOW_OAK_WEST_OPENED(64, 6),
|
||||
DOOR_LOW_OAK_NORTH_OPENED(64, 7),
|
||||
DOOR_OAK_LE (64, 0), // Lower, East
|
||||
DOOR_OAK_LS (64, 1),
|
||||
DOOR_OAK_LW (64, 2),
|
||||
DOOR_OAK_LN (64, 3),
|
||||
DOOR_OAK_LE_OPENED(64, 4),
|
||||
DOOR_OAK_LS_OPENED(64, 5),
|
||||
DOOR_OAK_LW_OPENED(64, 6),
|
||||
DOOR_OAK_LN_OPENED(64, 7),
|
||||
|
||||
DOOR_UP_OAK_LEFT(64, 8),
|
||||
DOOR_UP_OAK_RIGHT(64, 9),
|
||||
DOOR_UP_OAK_LEFT_POWERED(64, 10),
|
||||
DOOR_UP_OAK_RIGHT_POWERED(64, 11),
|
||||
DOOR_UP_OAK_12(64, 12),
|
||||
DOOR_UP_OAK_13(64, 13),
|
||||
DOOR_UP_OAK_14(64, 14),
|
||||
DOOR_UP_OAK_15(64, 15),
|
||||
DOOR_OAK_UP_LEFT (64, 8),
|
||||
DOOR_OAK_UP_RIGHT (64, 9),
|
||||
DOOR_OAK_UP_LEFT_POWERED (64, 10),
|
||||
DOOR_OAK_UP_RIGHT_POWERED(64, 11),
|
||||
DOOR_OAK_UP_12 (64, 12),
|
||||
DOOR_OAK_UP_13 (64, 13),
|
||||
DOOR_OAK_UP_14 (64, 14),
|
||||
DOOR_OAK_UP_15 (64, 15),
|
||||
|
||||
FENCE_OAK(85, 0),
|
||||
DOOR_SPRUCE_LE (193, 0),
|
||||
DOOR_SPRUCE_LS (193, 1),
|
||||
DOOR_SPRUCE_LW (193, 2),
|
||||
DOOR_SPRUCE_LN (193, 3),
|
||||
DOOR_SPRUCE_LE_OPENED(193, 4),
|
||||
DOOR_SPRUCE_LS_OPENED(193, 5),
|
||||
DOOR_SPRUCE_LW_OPENED(193, 6),
|
||||
DOOR_SPRUCE_LN_OPENED(193, 7),
|
||||
|
||||
DOOR_SPRUCE_UP_LEFT (193, 8),
|
||||
DOOR_SPRUCE_UP_RIGHT (193, 9),
|
||||
DOOR_SPRUCE_UP_LEFT_POWERED (193, 10),
|
||||
DOOR_SPRUCE_UP_RIGHT_POWERED(193, 11),
|
||||
DOOR_SPRUCE_UP_12 (193, 12),
|
||||
DOOR_SPRUCE_UP_13 (193, 13),
|
||||
DOOR_SPRUCE_UP_14 (193, 14),
|
||||
DOOR_SPRUCE_UP_15 (193, 15),
|
||||
|
||||
FENCE_OAK (85, 0),
|
||||
FENCE_SPRUCE (188, 0),
|
||||
FENCE_BIRCH (189, 0),
|
||||
FENCE_JUNGLE (190, 0),
|
||||
FENCE_OAK_DARK(191, 0),
|
||||
|
||||
SLAB_WOOD_OAK_BOTTOM (126, 0),
|
||||
SLAB_WOOD_SPRUCE_BOTTOM (126, 1),
|
||||
SLAB_WOOD_BIRCH_BOTTOM (126, 2),
|
||||
SLAB_WOOD_JUNGLE_BOTTOM (126, 3),
|
||||
SLAB_WOOD_ACACIA_BOTTOM (126, 4),
|
||||
SLAB_WOOD_OAK_DARK_BOTTOM(126, 5),
|
||||
|
||||
SLAB_WOOD_OAK_TOP (126, 8),
|
||||
SLAB_WOOD_SPRUCE_TOP (126, 9),
|
||||
SLAB_WOOD_BIRCH_TOP (126, 10),
|
||||
SLAB_WOOD_JUNGLE_TOP (126, 11),
|
||||
SLAB_WOOD_ACACIA_TOP (126, 12),
|
||||
SLAB_WOOD_OAK_DARK_TOP(126, 13),
|
||||
|
||||
SLAB_STONE_DOUBLE (43, 0),
|
||||
SLAB_SANDSTONE_DOUBLE (43, 1),
|
||||
SLAB_WOOD_DOUBLE (43, 2),
|
||||
SLAB_COBBLESTONE_DOUBLE(43, 3),
|
||||
SLAB_BRICK_DOUBLE (43, 4),
|
||||
SLAB_STONEBRICK_DOUBLE (43, 5),
|
||||
SLAB_NETHER_DOUBLE (43, 6),
|
||||
SLAB_QUARTZ_DOUBLE (43, 7),
|
||||
|
||||
SLAB_STONE_DOUBLE_SEAMLESS (43, 8),
|
||||
SLAB_SANDSTONE_DOUBLE_SEAMLESS (43, 9),
|
||||
SLAB_WOOD_DOUBLE_SEAMLESS (43, 10),
|
||||
SLAB_COBBLESTONE_DOUBLE_SEAMLESS(43, 11),
|
||||
SLAB_BRICK_DOUBLE_SEAMLESS (43, 12),
|
||||
SLAB_STONEBRICK_DOUBLE_SEAMLESS (43, 13),
|
||||
SLAB_NETHER_DOUBLE_SEAMLESS (43, 14),
|
||||
SLAB_QUARTZ_DOUBLE_SEAMLESS (43, 15),
|
||||
|
||||
SIGN_STANDING_SOUTH(63, 0),
|
||||
SIGN_STANDING_SSW (63, 1), // SOUTH-SOUTH WEST
|
||||
SIGN_STANDING_SW (63, 2),
|
||||
SIGN_STANDING_WSW (63, 3),
|
||||
SIGN_STANDING_WEST (63, 4),
|
||||
SIGN_STANDING_WNW (63, 5),
|
||||
SIGN_STANDING_NW (63, 6),
|
||||
SIGN_STANDING_NNW (63, 7),
|
||||
SIGN_STANDING_NORTH(63, 8),
|
||||
SIGN_STANDING_NNE (63, 9),
|
||||
SIGN_STANDING_NE (63, 10),
|
||||
SIGN_STANDING_ENE (63, 11),
|
||||
SIGN_STANDING_EAST (63, 12),
|
||||
SIGN_STANDING_ESE (63, 13),
|
||||
SIGN_STANDING_SE (63, 14),
|
||||
SIGN_STANDING_SSE (63, 15),
|
||||
|
||||
SIGN_WALL_NORTH(68, 2),
|
||||
SIGN_WALL_SOUTH(68, 3),
|
||||
SIGN_WALL_WEST(68, 4),
|
||||
SIGN_WALL_EAST(68, 5),
|
||||
|
||||
// Decay after Tree Update
|
||||
LEAVES_OAK (18, 0),
|
||||
@@ -287,6 +373,7 @@ public enum BlockType {
|
||||
|
||||
COBWEB(30, 0),
|
||||
TALLGRASS(31, 1),
|
||||
FERN(31, 2),
|
||||
DANDELION(37, 0),
|
||||
|
||||
FLOWER_POPPY (38, 0),
|
||||
@@ -359,7 +446,25 @@ public enum BlockType {
|
||||
SNOW(78, 0),
|
||||
|
||||
CLAY(82, 0),
|
||||
CLAY_HARDENED(172, 0),
|
||||
|
||||
CLAY_STRAINED_WHITE (159, 0),
|
||||
CLAY_STRAINED_ORANGE (159, 1),
|
||||
CLAY_STRAINED_MAGENTA (159, 2),
|
||||
CLAY_STRAINED_LIGHTBLUE(159, 3),
|
||||
CLAY_STRAINED_YELLOW (159, 4),
|
||||
CLAY_STRAINED_LIME (159, 5),
|
||||
CLAY_STRAINED_PINK (159, 6),
|
||||
CLAY_STRAINED_GRAY (159, 7),
|
||||
CLAY_STRAINED_LIGHTGRAY(159, 8),
|
||||
CLAY_STRAINED_CYAN (159, 9),
|
||||
CLAY_STRAINED_PURPULE (159, 10),
|
||||
CLAY_STRAINED_BLUE (159, 11),
|
||||
CLAY_STRAINED_BROWN (159, 12),
|
||||
CLAY_STRAINED_GREEN (159, 13),
|
||||
CLAY_STRAINED_RED (159, 14),
|
||||
CLAY_STRAINED_BLACK (159, 15),
|
||||
|
||||
CLAY_HARDENED (172, 0),
|
||||
|
||||
/** Sugar canes (Age 0) */
|
||||
SUGAR_CANES(83, 0),
|
||||
@@ -399,9 +504,97 @@ public enum BlockType {
|
||||
PUMPKIN_NORTH(86, 2),
|
||||
PUMPKIN_EAST (86, 3),
|
||||
|
||||
TRAPDOOR_WOODEN_CLOSE_BN(96, 0),
|
||||
TRAPDOOR_WOODEN_CLOSE_BS(96, 1),
|
||||
TRAPDOOR_WOODEN_CLOSE_BW(96, 2),
|
||||
TRAPDOOR_WOODEN_CLOSE_BE(96, 3),
|
||||
|
||||
TRAPDOOR_WOODEN_OPEN_BN(96, 4),
|
||||
TRAPDOOR_WOODEN_OPEN_BS(96, 5),
|
||||
TRAPDOOR_WOODEN_OPEN_BW(96, 6),
|
||||
TRAPDOOR_WOODEN_OPEN_BE(96, 7),
|
||||
|
||||
TRAPDOOR_WOODEN_CLOSE_TN(96, 8), // Top, North
|
||||
TRAPDOOR_WOODEN_CLOSE_TS(96, 9),
|
||||
TRAPDOOR_WOODEN_CLOSE_TW(96, 10),
|
||||
TRAPDOOR_WOODEN_CLOSE_TE(96, 11),
|
||||
|
||||
TRAPDOOR_WOODEN_OPEN_TN(96, 12),
|
||||
TRAPDOOR_WOODEN_OPEN_TS(96, 13),
|
||||
TRAPDOOR_WOODEN_OPEN_TW(96, 14),
|
||||
TRAPDOOR_WOODEN_OPEN_TE(96, 15),
|
||||
|
||||
SLAB_STONE_BOTTOM (44, 0),
|
||||
SLAB_SANDSTONE_BOTTOM (44, 1),
|
||||
SLAB_WOODEN_BOTTOM (44, 2),
|
||||
SLAB_COBBLESTONE_BOTTOM(44, 3),
|
||||
SLAB_BRICK_BOTTOM (44, 4),
|
||||
SLAB_STONEBRICK_BOTTOM (44, 5),
|
||||
SLAB_NETHERBRICK_BOTTOM(44, 6),
|
||||
SLAB_QUARTZ_BOTTOM (44, 7),
|
||||
|
||||
SLAB_STONE_TOP (44, 8),
|
||||
SLAB_SANDSTONE_TOP (44, 9),
|
||||
SLAB_WOODEN_TOP (44, 10),
|
||||
SLAB_COBBLESTONE_TOP(44, 11),
|
||||
SLAB_BRICK_TOP (44, 12),
|
||||
SLAB_STONEBRICK_TOP (44, 13),
|
||||
SLAB_NETHERBRICK_TOP(44, 14),
|
||||
SLAB_QUARTZ_TOP (44, 15),
|
||||
|
||||
STONE_MONSTER_EGG(97, 0),
|
||||
|
||||
GLASS_PANE(102, 0),
|
||||
STONEBRICKS (98, 0),
|
||||
STONEBRICKS_MOSS (98, 1),
|
||||
STONEBRICKS_CRACKED (98, 2),
|
||||
STONEBRICKS_CHISELED(98, 3),
|
||||
|
||||
STAIRS_STONEBRICK_BE(109, 0),
|
||||
STAIRS_STONEBRICK_BW(109, 1),
|
||||
STAIRS_STONEBRICK_BS(109, 2),
|
||||
STAIRS_STONEBRICK_BN(109, 3),
|
||||
STAIRS_STONEBRICK_TE(109, 4),
|
||||
STAIRS_STONEBRICK_TW(109, 5),
|
||||
STAIRS_STONEBRICK_TS(109, 6),
|
||||
STAIRS_STONEBRICK_TN(109, 7),
|
||||
|
||||
STRAIRS_COBBLESTONE_BE(67, 0), // Bottom, East
|
||||
STRAIRS_COBBLESTONE_BW(67, 1),
|
||||
STRAIRS_COBBLESTONE_BS(67, 2),
|
||||
STRAIRS_COBBLESTONE_BN(67, 3),
|
||||
STRAIRS_COBBLESTONE_TE(67, 4),
|
||||
STRAIRS_COBBLESTONE_TW(67, 5),
|
||||
STRAIRS_COBBLESTONE_TS(67, 6),
|
||||
STRAIRS_COBBLESTONE_TN(67, 7),
|
||||
|
||||
STRAIRS_SANDSTONE_BE(128, 0),
|
||||
STRAIRS_SANDSTONE_BW(128, 1),
|
||||
STRAIRS_SANDSTONE_BS(128, 2),
|
||||
STRAIRS_SANDSTONE_BN(128, 3),
|
||||
STRAIRS_SANDSTONE_TE(128, 4),
|
||||
STRAIRS_SANDSTONE_TW(128, 5),
|
||||
STRAIRS_SANDSTONE_TS(128, 6),
|
||||
STRAIRS_SANDSTONE_TN(128, 7),
|
||||
|
||||
STRAIRS_WOOD_OAK_BE(53, 0),
|
||||
STRAIRS_WOOD_OAK_BW(53, 1),
|
||||
STRAIRS_WOOD_OAK_BS(53, 2),
|
||||
STRAIRS_WOOD_OAK_BN(53, 3),
|
||||
STRAIRS_WOOD_OAK_TE(53, 4),
|
||||
STRAIRS_WOOD_OAK_TW(53, 5),
|
||||
STRAIRS_WOOD_OAK_TS(53, 6),
|
||||
STRAIRS_WOOD_OAK_TN(53, 7),
|
||||
|
||||
STRAIRS_WOOD_SPRUCE_BE(134, 0),
|
||||
STRAIRS_WOOD_SPRUCE_BW(134, 1),
|
||||
STRAIRS_WOOD_SPRUCE_BS(134, 2),
|
||||
STRAIRS_WOOD_SPRUCE_BN(134, 3),
|
||||
STRAIRS_WOOD_SPRUCE_TE(134, 4),
|
||||
STRAIRS_WOOD_SPRUCE_TW(134, 5),
|
||||
STRAIRS_WOOD_SPRUCE_TS(134, 6),
|
||||
STRAIRS_WOOD_SPRUCE_TN(134, 7),
|
||||
|
||||
MELON(103, 0),
|
||||
|
||||
VINE (106, 0),
|
||||
VINE_SOUTH(106, 1),
|
||||
@@ -422,11 +615,17 @@ public enum BlockType {
|
||||
|
||||
WATERLILY(111, 0),
|
||||
|
||||
LILAC(175, 1),
|
||||
DOUBLE_TALLGRASS(175, 2),
|
||||
ROSE_BUSH(175, 4),
|
||||
PEONY(175, 5),
|
||||
ROSE_BUSH_10(175, 10),
|
||||
SUNFLOWER_LOWER (175, 0),
|
||||
LILAC_LOWER (175, 1),
|
||||
DOUBLE_TALLGRASS_LOWER(175, 2),
|
||||
LARGE_FERN_LOWER (175, 3),
|
||||
ROSE_BUSH_LOWER (175, 4),
|
||||
PEONY_LOWER (175, 5),
|
||||
|
||||
DOUBLE_PLANT_UPPER_SOUTH(175, 8),
|
||||
DOUBLE_PLANT_UPPER_WEST (175, 9),
|
||||
DOUBLE_PLANT_UPPER_NORTH(175, 10),
|
||||
DOUBLE_PLANT_UPPER_EAST (175, 11),
|
||||
|
||||
/** Wheat (Age 0) */
|
||||
WHEAT (59, 0),
|
||||
@@ -479,6 +678,44 @@ public enum BlockType {
|
||||
/** Potatoes (Age 7) */
|
||||
POTATOES_7(142, 7),
|
||||
|
||||
REDSTONE_DUST_0 (55, 0),
|
||||
REDSTONE_DUST_1 (55, 1),
|
||||
REDSTONE_DUST_2 (55, 2),
|
||||
REDSTONE_DUST_3 (55, 3),
|
||||
REDSTONE_DUST_4 (55, 4),
|
||||
REDSTONE_DUST_5 (55, 5),
|
||||
REDSTONE_DUST_6 (55, 6),
|
||||
REDSTONE_DUST_7 (55, 7),
|
||||
REDSTONE_DUST_8 (55, 8),
|
||||
REDSTONE_DUST_9 (55, 9),
|
||||
REDSTONE_DUST_10(55, 10),
|
||||
REDSTONE_DUST_11(55, 11),
|
||||
REDSTONE_DUST_12(55, 12),
|
||||
REDSTONE_DUST_13(55, 13),
|
||||
REDSTONE_DUST_14(55, 14),
|
||||
REDSTONE_DUST_15(55, 15),
|
||||
|
||||
REDSTONE_LAMP (123, 0),
|
||||
REDSTONE_LAMP_ACTIVE(124, 0),
|
||||
REDSTONE_BLOCK (152, 0),
|
||||
|
||||
CARPET_WHITE (171, 0),
|
||||
CARPET_ORANGE (171, 1),
|
||||
CARPET_MAGENTA (171, 2),
|
||||
CARPET_LIGHTBLUE(171, 3),
|
||||
CARPET_YELLOW (171, 4),
|
||||
CARPET_LIME (171, 5),
|
||||
CARPET_PINK (171, 6),
|
||||
CARPET_GRAY (171, 7),
|
||||
CARPET_LIGHTGRAY(171, 8),
|
||||
CARPET_CYAN (171, 9),
|
||||
CARPET_PURPLE (171, 10),
|
||||
CARPET_BLUE (171, 11),
|
||||
CARPET_BROWN (171, 12),
|
||||
CARPET_GREEN (171, 13),
|
||||
CARPET_RED (171, 14),
|
||||
CARPET_BLACK (171, 15),
|
||||
|
||||
/** Beetroot (Age 0) */
|
||||
BEETROOT (207, 0),
|
||||
/** Beetroot (Age 1) */
|
||||
@@ -486,7 +723,181 @@ public enum BlockType {
|
||||
/** Beetroot (Age 2) */
|
||||
BEETROOT_2(207, 2),
|
||||
/** Beetroot (Age 3) */
|
||||
BEETROOT_3(207, 3);
|
||||
BEETROOT_3(207, 3),
|
||||
|
||||
BONE_BLOCK(216, 0),
|
||||
|
||||
BED_NORTH (26, 0),
|
||||
BED_EAST (26, 1),
|
||||
BED_SOUTH (26, 2),
|
||||
BED_WEST (26, 3),
|
||||
BED_HEAD_NORTH(26, 8),
|
||||
BED_HEAD_EAST (26, 9),
|
||||
BED_HEAD_SOUTH(26, 10),
|
||||
BED_HEAD_WEST (26, 11),
|
||||
BED_HEAD_12 (26, 12),
|
||||
BED_HEAD_13 (26, 13),
|
||||
BED_HEAD_14 (26, 14),
|
||||
BED_HEAD_15 (26, 15),
|
||||
|
||||
DEAD_BUSH(32, 0),
|
||||
|
||||
WOOL_WHITE (35, 0),
|
||||
WOOL_ORANGE (35, 1),
|
||||
WOOL_MAGENTA (35, 2),
|
||||
WOOL_LIGHTBLUE(35, 3),
|
||||
WOOL_YELLOW (35, 4),
|
||||
WOOL_LIME (35, 5),
|
||||
WOOL_PINK (35, 6),
|
||||
WOOL_GRAY (35, 7),
|
||||
WOOL_LIGHTGRAY(35, 8),
|
||||
WOOL_CYAN (35, 9),
|
||||
WOOL_PURPLE (35, 10),
|
||||
WOOL_BLUE (35, 11),
|
||||
WOOL_BROWN (35, 12),
|
||||
WOOL_GREEN (35, 13),
|
||||
WOOL_RED (35, 14),
|
||||
WOOL_BLACK (35, 15),
|
||||
|
||||
BOOKSHELF(47, 0),
|
||||
CRAFTING_TABLE(58, 0),
|
||||
|
||||
LADDER_NORTH(65, 2),
|
||||
LADDER_SOUTH(65, 3),
|
||||
LADDER_WEST(65, 4),
|
||||
LADDER_EAST(65, 5),
|
||||
|
||||
PLATE_PRESSURE_WOOD (72, 0),
|
||||
PLATE_PRESSURE_WOOD_POWERED(72, 1),
|
||||
|
||||
/** Cactus (Age 0) */
|
||||
CACTUS (81, 0),
|
||||
/** Cactus (Age 1) */
|
||||
CACTUS_1(81, 1),
|
||||
/** Cactus (Age 2) */
|
||||
CACTUS_2(81, 2),
|
||||
/** Cactus (Age 3) */
|
||||
CACTUS_3(81, 3),
|
||||
/** Cactus (Age 4) */
|
||||
CACTUS_4(81, 4),
|
||||
/** Cactus (Age 5) */
|
||||
CACTUS_5(81, 5),
|
||||
/** Cactus (Age 6) */
|
||||
CACTUS_6(81, 6),
|
||||
/** Cactus (Age 7) */
|
||||
CACTUS_7(81, 7),
|
||||
/** Cactus (Age 8) */
|
||||
CACTUS_8(81, 8),
|
||||
/** Cactus (Age 9) */
|
||||
CACTUS_9(81, 9),
|
||||
/** Cactus (Age 10) */
|
||||
CACTUS_10(81, 10),
|
||||
/** Cactus (Age 11) */
|
||||
CACTUS_11(81, 11),
|
||||
/** Cactus (Age 12) */
|
||||
CACTUS_12(81, 12),
|
||||
/** Cactus (Age 13) */
|
||||
CACTUS_13(81, 13),
|
||||
/** Cactus (Age 14) */
|
||||
CACTUS_14(81, 14),
|
||||
/** Cactus (Age 15) */
|
||||
CACTUS_15(81, 15),
|
||||
|
||||
NETHERRACK(87, 0),
|
||||
|
||||
GLASS_BLOCK (20, 0),
|
||||
GLASS_BLOCK_WHITE (95, 0),
|
||||
GLASS_BLOCK_ORANGE (95, 1),
|
||||
GLASS_BLOCK_MAGENTA (95, 2),
|
||||
GLASS_BLOCK_LIGHTBLUE(95, 3),
|
||||
GLASS_BLOCK_YELLOW (95, 4),
|
||||
GLASS_BLOCK_LIME (95, 5),
|
||||
GLASS_BLOCK_PING (95, 6),
|
||||
GLASS_BLOCK_GRAY (95, 7),
|
||||
GLASS_BLOCK_LIGHTGRAY(95, 8),
|
||||
GLASS_BLOCK_CYAN (95, 9),
|
||||
GLASS_BLOCK_PURPLE (95, 10),
|
||||
GLASS_BLOCK_BLUE (95, 11),
|
||||
GLASS_BLOCK_BROWN (95, 12),
|
||||
GLASS_BLOCK_GREEN (95, 13),
|
||||
GLASS_BLOCK_RED (95, 14),
|
||||
GLASS_BLOCK_BLACK (95, 15),
|
||||
|
||||
GLASS_PANE (102, 0),
|
||||
GLASS_PANE_WHITE (160, 0),
|
||||
GLASS_PANE_ORANGE (160, 1),
|
||||
GLASS_PANE_MAGENTA (160, 2),
|
||||
GLASS_PANE_LIGHTBLUE(160, 3),
|
||||
GLASS_PANE_YELLOW (160, 4),
|
||||
GLASS_PANE_LIME (160, 5),
|
||||
GLASS_PANE_PING (160, 6),
|
||||
GLASS_PANE_GRAY (160, 7),
|
||||
GLASS_PANE_LIGHTGRAY(160, 8),
|
||||
GLASS_PANE_CYAN (160, 9),
|
||||
GLASS_PANE_PURPLE (160, 10),
|
||||
GLASS_PANE_BLUE (160, 11),
|
||||
GLASS_PANE_BROWN (160, 12),
|
||||
GLASS_PANE_GREEN (160, 13),
|
||||
GLASS_PANE_RED (160, 14),
|
||||
GLASS_PANE_BLACK (160, 15),
|
||||
|
||||
LAPIS_LAZULI(22, 0),
|
||||
|
||||
DISPENSER_OFF_DOWN (23, 0),
|
||||
DISPENSER_OFF_UP (23, 1),
|
||||
DISPENSER_OFF_NORTH(23, 2),
|
||||
DISPENSER_OFF_SOUTH(23, 3),
|
||||
DISPENSER_OFF_WEST (23, 4),
|
||||
DISPENSER_OFF_EAST (23, 5),
|
||||
|
||||
DISPENSER_ON_DOWN (23, 8),
|
||||
DISPENSER_ON_UP (23, 9),
|
||||
DISPENSER_ON_NORTH(23, 10),
|
||||
DISPENSER_ON_SOUTH(23, 11),
|
||||
DISPENSER_ON_WEST (23, 12),
|
||||
DISPENSER_ON_EAST (23, 13),
|
||||
|
||||
PISTON_STICKY_DOWN (29, 0),
|
||||
PISTON_STICKY_UP (29, 1),
|
||||
PISTON_STICKY_NORTH(29, 2),
|
||||
PISTON_STICKY_SOUTH(29, 3),
|
||||
PISTON_STICKY_WEST (29, 4),
|
||||
PISTON_STICKY_EAST (29, 5),
|
||||
|
||||
PISTON_STICKY_DOWN_EXTENDED (29, 8),
|
||||
PISTON_STICKY_UP_EXTENDED (29, 9),
|
||||
PISTON_STICKY_NORTH_EXTENDED(29, 10),
|
||||
PISTON_STICKY_SOUTH_EXTENDED(29, 11),
|
||||
PISTON_STICKY_WEST_EXTENDED (29, 12),
|
||||
PISTON_STICKY_EAST_EXTENDED (29, 13),
|
||||
|
||||
BLOCK_GOLD (41, 0),
|
||||
BLOCK_IRON (42, 0),
|
||||
BLOCK_BRICK(45, 0),
|
||||
|
||||
FIRE (51, 0),
|
||||
FIRE_1 (51, 1),
|
||||
FIRE_2 (51, 2),
|
||||
FIRE_3 (51, 3),
|
||||
FIRE_4 (51, 4),
|
||||
FIRE_5 (51, 5),
|
||||
FIRE_6 (51, 6),
|
||||
FIRE_7 (51, 7),
|
||||
FIRE_8 (51, 8),
|
||||
FIRE_9 (51, 9),
|
||||
FIRE_10(51, 10),
|
||||
FIRE_11(51, 11),
|
||||
FIRE_12(51, 12),
|
||||
FIRE_13(51, 13),
|
||||
FIRE_14(51, 14),
|
||||
FIRE_15(51, 15),
|
||||
|
||||
FURNACE_NORTH(61, 2),
|
||||
FURNACE_SOUTH(61, 3),
|
||||
FURNACE_WEST (61, 4),
|
||||
FURNACE_EAST (61, 5),
|
||||
|
||||
BEDROCK(7, 0);
|
||||
|
||||
BlockType(int id, int meta) {
|
||||
this.id = id;
|
||||
|
||||
@@ -37,9 +37,9 @@ class EntityLocationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void clone_() {
|
||||
void copy() {
|
||||
EntityLocation locOrig = new EntityLocation(x, y, z, yaw, pitch);
|
||||
EntityLocation locClone = locOrig.clone();
|
||||
EntityLocation locClone = locOrig.copy();
|
||||
assertEquals(locOrig, locClone);
|
||||
assertNotSame(locOrig, locClone);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class ImmutableEntityLocationTest {
|
||||
@Test
|
||||
void clone_() {
|
||||
EntityLocation locOrig = new ImmutableEntityLocation(1d, 2d, 3d, 4f, 5f);
|
||||
EntityLocation locClone = locOrig.clone();
|
||||
EntityLocation locClone = locOrig.copy();
|
||||
|
||||
assertEquals(locOrig, locClone);
|
||||
}
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
package mc.core;
|
||||
|
||||
import javafx.util.Pair;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import mc.core.eventbus.Event;
|
||||
import mc.core.eventbus.EventBus;
|
||||
import mc.core.eventbus.Subscriber;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.internal.util.reflection.Whitebox;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
class TestEventBus {
|
||||
private List<String> resultList = new ArrayList<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<Class<? extends Event>, List<Pair<Object, Method>>> getEventBusFieldSubscribes() {
|
||||
return (Map<Class<? extends Event>, List<Pair<Object, Method>>>)
|
||||
Whitebox.getInternalState(EventBus.getInstance(), "subscribes");
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
void before() {
|
||||
getEventBusFieldSubscribes().clear();
|
||||
((Queue<Event>) Whitebox.getInternalState(EventBus.getInstance(), "eventQueue")).clear();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testRegisterSubscribes() {
|
||||
DumbEventHandler handler = new DumbEventHandler();
|
||||
EventBus.getInstance().registerSubscribes(handler);
|
||||
|
||||
Map<Class<? extends Event>, List<Pair<Object, Method>>> subscribes = getEventBusFieldSubscribes();
|
||||
assertEquals(1, subscribes.size());
|
||||
|
||||
List<Pair<Object, Method>> pairs = subscribes.values().iterator().next();
|
||||
assertEquals(1, pairs.size());
|
||||
|
||||
Pair<Object, Method> pair = pairs.get(0);
|
||||
assertSame(handler, pair.getKey());
|
||||
assertEquals("corectSubscribe", pair.getValue().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUnregisterSubscribes() {
|
||||
DumbEventHandler handler = new DumbEventHandler();
|
||||
EventBus.getInstance().registerSubscribes(handler);
|
||||
|
||||
EventBus.getInstance().unregisterSubscribes(handler);
|
||||
|
||||
Map<Class<? extends Event>, List<Pair<Object, Method>>> subscribes = getEventBusFieldSubscribes();
|
||||
assertEquals(0, subscribes.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void testPost() {
|
||||
EventBus.getInstance().post(new DumbEvent());
|
||||
|
||||
Queue<Event> eventQueue = (Queue<Event>) Whitebox.getInternalState(EventBus.getInstance(), "eventQueue");
|
||||
assertEquals(1, eventQueue.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProcess() {
|
||||
Stream.of(new DumbEventHandler("D1 "), new DumbEventHandler("D2 "))
|
||||
.forEach(handler -> EventBus.getInstance().registerSubscribes(handler));
|
||||
|
||||
Stream.of(new DumbEvent("message 1"), new DumbEvent("message 2"))
|
||||
.forEach(event -> EventBus.getInstance().post(event));
|
||||
|
||||
EventBus.getInstance().process();
|
||||
|
||||
assertEquals(4, resultList.size());
|
||||
assertEquals("D1 message 1", resultList.get(0));
|
||||
assertEquals("D2 message 1", resultList.get(1));
|
||||
assertEquals("D1 message 2", resultList.get(2));
|
||||
assertEquals("D2 message 2", resultList.get(3));
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
private class DumbEvent implements Event {
|
||||
String message;
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DumbEventHandler {
|
||||
private String prefix = "";
|
||||
|
||||
@Subscriber
|
||||
public void corectSubscribe(DumbEvent event) {
|
||||
resultList.add(prefix + event.message);
|
||||
}
|
||||
|
||||
@Subscriber
|
||||
public Object incorectSubscribeReturnType(DumbEvent event) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Subscriber
|
||||
public void incorrectSubscriberTypeParameter(Object object) {
|
||||
}
|
||||
|
||||
@Subscriber
|
||||
public void incorrectSubscriberManyParameters(DumbEvent event, Object object) {
|
||||
}
|
||||
|
||||
public void someMethod() {
|
||||
}
|
||||
}
|
||||
}
|
||||
274
core/src/test/java/mc/core/eventbus/EventBusTest.java
Normal file
274
core/src/test/java/mc/core/eventbus/EventBusTest.java
Normal file
@@ -0,0 +1,274 @@
|
||||
package mc.core.eventbus;
|
||||
|
||||
import javafx.util.Pair;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.mockito.internal.util.reflection.Whitebox;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class EventBusTest {
|
||||
private EventBus eventBus = EventBus.getInstance();
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
getEventQueue().clear();
|
||||
getSubscribes().clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRegisterSubscribes() {
|
||||
final AbstractDumpEventHandler handler = new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
public void corectSubscribe(DumbEvent event) {
|
||||
}
|
||||
};
|
||||
|
||||
eventBus.registerSubscribes(handler);
|
||||
|
||||
assertEquals(1, getSubscribes().size());
|
||||
assertTrue(getSubscribes().containsKey(DumbEvent.class));
|
||||
assertNotNull(getSubscribes().get(DumbEvent.class));
|
||||
assertEquals(1, getSubscribes().get(DumbEvent.class).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRegisterSubscribesManyHandlers() {
|
||||
final AbstractDumpEventHandler handler1 = new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
public void corectSubscribe(DumbEvent event) {
|
||||
result += event.message;
|
||||
}
|
||||
};
|
||||
|
||||
final AbstractDumpEventHandler handler2 = new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
public void corectSubscribe(DumbEvent event) {
|
||||
result += event.message;
|
||||
}
|
||||
};
|
||||
|
||||
eventBus.registerSubscribes(handler1);
|
||||
eventBus.registerSubscribes(handler2);
|
||||
|
||||
assertEquals(1, getSubscribes().size());
|
||||
assertTrue(getSubscribes().containsKey(DumbEvent.class));
|
||||
assertNotNull(getSubscribes().get(DumbEvent.class));
|
||||
assertEquals(2, getSubscribes().get(DumbEvent.class).size());
|
||||
}
|
||||
|
||||
private static Stream<Arguments> streamIncorrectRegisterSubscribes() {
|
||||
return Stream.of(
|
||||
Arguments.of(new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
public void incorectSubscribe(DumbEvent event) {
|
||||
result += event.message;
|
||||
}
|
||||
}),
|
||||
Arguments.of(new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
private void incorectSubscribe(DumbEvent event) {
|
||||
result += event.message;
|
||||
}
|
||||
}),
|
||||
Arguments.of(new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
public Object incorectSubscribe(DumbEvent event) {
|
||||
result += event.message;
|
||||
return null;
|
||||
}
|
||||
}),
|
||||
Arguments.of(new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
public void incorectSubscribe(DumbEvent event, DumbEvent ev2) {
|
||||
result += "Any";
|
||||
}
|
||||
}),
|
||||
Arguments.of(new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
public void incorectSubscribe(Object event) {
|
||||
result += "Any";
|
||||
}
|
||||
}),
|
||||
Arguments.of(new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
public void incorectSubscribe(Event event) {
|
||||
result += "Any";
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("streamIncorrectRegisterSubscribes")
|
||||
void testIncorrectRegisterSubscribes(AbstractDumpEventHandler incorrectHandler) {
|
||||
eventBus.registerSubscribes(incorrectHandler);
|
||||
|
||||
assertEquals(0, getSubscribes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUnregisterSubscribes() {
|
||||
final AbstractDumpEventHandler handler1 = new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
public void corectSubscribe1(DumbEvent event) {
|
||||
result += event.message;
|
||||
}
|
||||
};
|
||||
|
||||
final AbstractDumpEventHandler handler2 = new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
public void corectSubscribe2(DumbEvent event) {
|
||||
result += event.message;
|
||||
}
|
||||
};
|
||||
|
||||
eventBus.registerSubscribes(handler1);
|
||||
eventBus.registerSubscribes(handler2);
|
||||
|
||||
eventBus.unregisterSubscribes(handler1);
|
||||
|
||||
assertEquals(1, getSubscribes().size());
|
||||
assertTrue(getSubscribes().containsKey(DumbEvent.class));
|
||||
assertNotNull(getSubscribes().get(DumbEvent.class));
|
||||
assertEquals(1, getSubscribes().get(DumbEvent.class).size());
|
||||
assertEquals("corectSubscribe2", getSubscribes().get(DumbEvent.class).get(0).getValue().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUnregisterSubscribesNotExistsEvent() {
|
||||
final AbstractDumpEventHandler handler1 = new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
public void corectSubscribe1(DumbEvent event) {
|
||||
result += event.message;
|
||||
}
|
||||
};
|
||||
|
||||
eventBus.registerSubscribes(handler1);
|
||||
|
||||
final AbstractDumpEventHandler handler2 = new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
public void corectSubscribe2(DumbEvent2 event) {
|
||||
result += "Any";
|
||||
}
|
||||
};
|
||||
|
||||
eventBus.unregisterSubscribes(handler2);
|
||||
|
||||
assertEquals(1, getSubscribes().size());
|
||||
assertTrue(getSubscribes().containsKey(DumbEvent.class));
|
||||
assertNotNull(getSubscribes().get(DumbEvent.class));
|
||||
assertEquals(1, getSubscribes().get(DumbEvent.class).size());
|
||||
assertEquals("corectSubscribe1", getSubscribes().get(DumbEvent.class).get(0).getValue().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUnregisterSubscribesLast() {
|
||||
final AbstractDumpEventHandler handler = new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
public void corectSubscribe(DumbEvent event) {
|
||||
result += event.message;
|
||||
}
|
||||
};
|
||||
|
||||
eventBus.registerSubscribes(handler);
|
||||
eventBus.unregisterSubscribes(handler);
|
||||
|
||||
assertEquals(0, getSubscribes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPost() {
|
||||
final AbstractDumpEventHandler handler = new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
public void corectSubscribe(DumbEvent event) {
|
||||
result += event.message;
|
||||
}
|
||||
};
|
||||
|
||||
eventBus.registerSubscribes(handler);
|
||||
final DumbEvent event = new DumbEvent("Hello?");
|
||||
eventBus.post(event);
|
||||
eventBus.post(event);
|
||||
eventBus.post(event);
|
||||
|
||||
final Queue<Event> eventQueue = getEventQueue();
|
||||
assertEquals(3, eventQueue.size());
|
||||
assertEquals(event, eventQueue.peek());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPostNoHandlerEvent() {
|
||||
final DumbEvent event = new DumbEvent("Hello?");
|
||||
eventBus.post(event);
|
||||
|
||||
final Queue<Event> eventQueue = getEventQueue();
|
||||
assertTrue(eventQueue.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProcess() {
|
||||
final AbstractDumpEventHandler handler = new AbstractDumpEventHandler() {
|
||||
@SuppressWarnings("unused")
|
||||
@Subscriber
|
||||
public void corectSubscribe(DumbEvent event) {
|
||||
result += event.message;
|
||||
}
|
||||
};
|
||||
|
||||
eventBus.registerSubscribes(handler);
|
||||
eventBus.post(new DumbEvent("Hello?"));
|
||||
eventBus.process();
|
||||
|
||||
assertTrue(getEventQueue().isEmpty());
|
||||
assertEquals("Hello?", handler.result);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<Class<? extends Event>, List<Pair<Object, Method>>> getSubscribes() {
|
||||
return (Map<Class<? extends Event>, List<Pair<Object, Method>>>)
|
||||
Whitebox.getInternalState(eventBus, "subscribes");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Queue<Event> getEventQueue() {
|
||||
return (Queue<Event>)
|
||||
Whitebox.getInternalState(eventBus, "eventQueue");
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
private class DumbEvent implements Event {
|
||||
String message;
|
||||
}
|
||||
|
||||
private class DumbEvent2 implements Event {
|
||||
}
|
||||
|
||||
private static abstract class AbstractDumpEventHandler {
|
||||
String result = "";
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,9 @@ class BlockLocationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void clone_() {
|
||||
void copy() {
|
||||
BlockLocation locOrig = new BlockLocation(x, y, z);
|
||||
BlockLocation locClone = locOrig.clone();
|
||||
BlockLocation locClone = locOrig.copy();
|
||||
assertEquals(locOrig, locClone);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import mc.core.player.PlayerManager;
|
||||
import mc.core.player.PlayerSettings;
|
||||
import mc.core.world.World;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
@@ -30,7 +29,7 @@ public class H2PlayerManager implements PlayerManager {
|
||||
H2Player h2Player = new H2Player();
|
||||
h2Player.setName(name);
|
||||
h2Player.setUuid(UUID.randomUUID());
|
||||
h2Player.setLocation(location.clone());
|
||||
h2Player.setLocation(location.copy());
|
||||
h2Player.setLoadedChunks(new ArrayList<>());
|
||||
h2Player.setWorld(world);
|
||||
h2Player.setSettings(new PlayerSettings());
|
||||
|
||||
2
lombok.config
Normal file
2
lombok.config
Normal file
@@ -0,0 +1,2 @@
|
||||
# Добавить runtime аннотацию @lombok.Generated ко всем генерируемым методам "ломбока"
|
||||
lombok.addLombokGeneratedAnnotation = true
|
||||
@@ -1,6 +1,7 @@
|
||||
package mc.core.network.proto_1_12_2;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ByteArrayOutputNetStream extends NetOutputStream_p340 {
|
||||
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
@@ -61,6 +62,11 @@ public class ByteArrayOutputNetStream extends NetOutputStream_p340 {
|
||||
writeLong(Double.doubleToLongBits(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
baos.close();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return baos.size();
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public abstract class NetInputStream_p340 extends NetInputStream {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag<?> readNBT() {
|
||||
public Tag readNBT() {
|
||||
if (nbtInputStream == null) {
|
||||
try {
|
||||
nbtInputStream = new NBTInputStream(this, false);
|
||||
|
||||
@@ -32,7 +32,7 @@ public abstract class NetOutputStream_p340 extends NetOutputStream {
|
||||
writeBytes(buf);
|
||||
} else {
|
||||
byte[] buf = value.getBytes(StandardCharsets.UTF_8);
|
||||
writeVarInt(value.length());
|
||||
writeVarInt(buf.length);
|
||||
writeBytes(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,6 @@ public enum State {
|
||||
.put(0x0E, PlayerPositionAndLookPacket.class)
|
||||
.put(0x0F, PlayerLookPacket.class)
|
||||
.put(0x13, PlayerAbilitiesPacket.class)
|
||||
.put(0x1A, HeldItemChangePacket.class)
|
||||
.build(),
|
||||
ImmutableMap.<Class<? extends SCPacket>, Integer>builder()
|
||||
.put(BossBarPacket.class, 0x0C)
|
||||
|
||||
@@ -17,8 +17,8 @@ public class TeleportManager {
|
||||
|
||||
@AllArgsConstructor
|
||||
private class TpData {
|
||||
public Player player;
|
||||
public EntityLocation newLocation;
|
||||
Player player;
|
||||
EntityLocation newLocation;
|
||||
// TODO необходимо добавить TimeStamp, что бы понимать, когда клиент отвергнул телепортацию
|
||||
// т.е. идея такова: долгое молчание клиента знак отвержения телепортации.
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class TeleportManager {
|
||||
teleportId = RAND.nextInt(9999);
|
||||
} while (teleportMap.containsKey(teleportId));
|
||||
|
||||
teleportMap.put(teleportId, new TpData(player, location.clone()));
|
||||
teleportMap.put(teleportId, new TpData(player, location.copy()));
|
||||
return teleportId;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package mc.core.network.proto_1_12_2.packets.clientside;
|
||||
|
||||
import mc.core.network.CSPacket;
|
||||
import mc.core.network.NetInputStream;
|
||||
|
||||
public class HeldItemChangePacket implements CSPacket {
|
||||
private int slot;
|
||||
|
||||
@Override
|
||||
public void readSelf(NetInputStream netStream) {
|
||||
this.slot = netStream.readShort();
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,11 @@ import mc.core.world.block.BlockType;
|
||||
import mc.core.world.chunk.Chunk;
|
||||
import mc.core.world.chunk.ChunkSection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/*
|
||||
Packet structure
|
||||
@@ -88,19 +90,13 @@ public class ChunkDataPacket implements SCPacket {
|
||||
this.sectionList = sectionList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetOutputStream netStream) {
|
||||
if (sectionList == null && chunk == null) {
|
||||
log.warn("Empty chunk data!"); //TODO для такого нужна заглушка
|
||||
return;
|
||||
}
|
||||
|
||||
netStream.writeInt(x); // Chunk X
|
||||
netStream.writeInt(z); // Chunk Y
|
||||
netStream.writeBoolean(initChunk); // Init Chunk
|
||||
|
||||
/**
|
||||
* @return max height chunk
|
||||
*/
|
||||
private int calcAndWriteBitMask(NetOutputStream netStream) {
|
||||
int maxH = 0;
|
||||
int bitMask = 0;
|
||||
|
||||
if (sectionList == null && chunk != null) {
|
||||
for (int h = 15; h >= 0; h--) {
|
||||
bitMask = bitMask << 1;
|
||||
@@ -125,74 +121,106 @@ public class ChunkDataPacket implements SCPacket {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
netStream.writeVarInt(bitMask); // Primary Bit Mask
|
||||
|
||||
final ByteArrayOutputNetStream data = new ByteArrayOutputNetStream();
|
||||
return maxH;
|
||||
}
|
||||
|
||||
final ByteArrayOutputNetStream biomes = new ByteArrayOutputNetStream();
|
||||
boolean biomeWrite = true;
|
||||
private ChunkSection getChunkSection(int h) {
|
||||
if (chunk != null) {
|
||||
return chunk.getChunkSection(h);
|
||||
} else if (sectionList != null) {
|
||||
return sectionList.remove(0);
|
||||
}
|
||||
|
||||
List<CompoundTag> nbtList = new ArrayList<>();
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int h = 0; h < maxH; h++) {
|
||||
ChunkSection chunkSection = null;
|
||||
private PalettedChunkSection createPalette(final ChunkSection chunkSection,
|
||||
final List<CompoundTag> nbtList,
|
||||
final AtomicBoolean biomeWrite,
|
||||
final ByteArrayOutputNetStream biomes) {
|
||||
|
||||
if (chunk != null) {
|
||||
chunkSection = chunk.getChunkSection(h);
|
||||
} else if (sectionList != null) {
|
||||
chunkSection = sectionList.remove(0);
|
||||
}
|
||||
final PalettedChunkSection palettedChunkSection = new PalettedChunkSection();
|
||||
|
||||
if (chunkSection == null) {
|
||||
continue;
|
||||
}
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
Block block = chunkSection.getBlock(x, y, z);
|
||||
|
||||
final PalettedChunkSection palettedChunkSection = new PalettedChunkSection();
|
||||
palettedChunkSection.addBlock(
|
||||
block,
|
||||
chunkSection.getSkyLight(x, y, z)
|
||||
);
|
||||
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
Block block = chunkSection.getBlock(x, y, z);
|
||||
CompoundTag nbt = block.getNBTData();
|
||||
if (nbt != null) {
|
||||
nbtList.add(nbt);
|
||||
}
|
||||
|
||||
palettedChunkSection.addBlock(
|
||||
block,
|
||||
chunkSection.getSkyLight(x, y, z)
|
||||
);
|
||||
|
||||
CompoundTag nbt = block.getNBTData();
|
||||
if (nbt != null) {
|
||||
nbtList.add(nbt);
|
||||
}
|
||||
|
||||
if (biomeWrite) {
|
||||
biomes.writeByte(chunk.getBiome(
|
||||
(chunk.getX() << 4) + x,
|
||||
(chunk.getZ() << 4) + z
|
||||
).getId());
|
||||
if (x == 15 && z == 15) {
|
||||
biomeWrite = false;
|
||||
}
|
||||
if (biomeWrite.get()) {
|
||||
biomes.writeByte(chunk.getBiome(
|
||||
(chunk.getX() << 4) + x,
|
||||
(chunk.getZ() << 4) + z
|
||||
).getId());
|
||||
if (x == 15 && z == 15) {
|
||||
biomeWrite.set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// <Chunk Section>
|
||||
palettedChunkSection.writeToNetStream(data);
|
||||
// </Chunk Section>
|
||||
}
|
||||
// <Biomes>
|
||||
data.writeBytes(biomes.toByteArray());
|
||||
// </Biomes>
|
||||
|
||||
netStream.writeVarInt(data.size()); // Size of Data
|
||||
netStream.writeBytes(data.toByteArray()); // Data
|
||||
netStream.writeVarInt(nbtList.size()); // Number of block entities
|
||||
// <NBT>
|
||||
for (CompoundTag compoundTag : nbtList) {
|
||||
netStream.writeNBT(compoundTag);
|
||||
return palettedChunkSection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetOutputStream netStream) {
|
||||
if (sectionList == null && chunk == null) {
|
||||
log.warn("Empty chunk data!"); //TODO для такого нужна заглушка
|
||||
return;
|
||||
}
|
||||
|
||||
netStream.writeInt(x); // Chunk X
|
||||
netStream.writeInt(z); // Chunk Y
|
||||
netStream.writeBoolean(initChunk); // Init Chunk
|
||||
|
||||
final int maxH = calcAndWriteBitMask(netStream);
|
||||
|
||||
try (ByteArrayOutputNetStream data = new ByteArrayOutputNetStream();
|
||||
ByteArrayOutputNetStream biomes = new ByteArrayOutputNetStream()) {
|
||||
|
||||
AtomicBoolean biomeWrite = new AtomicBoolean(true);
|
||||
|
||||
List<CompoundTag> nbtList = new ArrayList<>();
|
||||
|
||||
for (int h = 0; h < maxH; h++) {
|
||||
final ChunkSection chunkSection = getChunkSection(h);
|
||||
if (chunkSection == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// <Chunk Section>
|
||||
createPalette(chunkSection, nbtList, biomeWrite, biomes)
|
||||
.writeToNetStream(data);
|
||||
// </Chunk Section>
|
||||
}
|
||||
// <Biomes>
|
||||
data.writeBytes(biomes.toByteArray());
|
||||
// </Biomes>
|
||||
|
||||
netStream.writeVarInt(data.size()); // Size of Data
|
||||
netStream.writeBytes(data.toByteArray()); // Data
|
||||
netStream.writeVarInt(nbtList.size()); // Number of block entities
|
||||
// <NBT>
|
||||
for (CompoundTag compoundTag : nbtList) {
|
||||
netStream.writeNBT(compoundTag);
|
||||
}
|
||||
// </NBT>
|
||||
} catch (IOException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
// </NBT>
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -240,7 +268,7 @@ public class ChunkDataPacket implements SCPacket {
|
||||
this.skyLight.set(bx, by, bz, skyLight);
|
||||
}
|
||||
|
||||
void writeToNetStream(final NetOutputStream netOutputStream) {
|
||||
private int getBitsPerBlock() {
|
||||
int bitsPerBlock = 4;
|
||||
if (palette.size() > 15) {
|
||||
if (palette.size() <= 31)
|
||||
@@ -253,15 +281,12 @@ public class ChunkDataPacket implements SCPacket {
|
||||
bitsPerBlock = 8;
|
||||
}
|
||||
|
||||
// <Palette>
|
||||
netOutputStream.writeUnsignedByte(bitsPerBlock); // Bits Per Block
|
||||
netOutputStream.writeVarInt(palette.size()); // Size of palette
|
||||
palette.forEach(netOutputStream::writeVarInt); // Palette
|
||||
// </Palette>
|
||||
// <Data Array>
|
||||
final int dataLength = (4096/*16*16*16*/ * bitsPerBlock) / 64/*size of long in bits*/;
|
||||
netOutputStream.writeVarInt(dataLength); // Size of Data Array
|
||||
// <Array>
|
||||
return bitsPerBlock;
|
||||
}
|
||||
|
||||
private void writePalette(final int bitsPerBlock,
|
||||
final NetOutputStream netOutputStream) {
|
||||
|
||||
long value = 0;
|
||||
int lastPos = 0;
|
||||
boolean fairy = false;
|
||||
@@ -296,6 +321,21 @@ public class ChunkDataPacket implements SCPacket {
|
||||
}
|
||||
}
|
||||
netOutputStream.writeLong(value);
|
||||
}
|
||||
|
||||
void writeToNetStream(final NetOutputStream netOutputStream) {
|
||||
final int bitsPerBlock = getBitsPerBlock();
|
||||
|
||||
// <Palette>
|
||||
netOutputStream.writeUnsignedByte(bitsPerBlock); // Bits Per Block
|
||||
netOutputStream.writeVarInt(palette.size()); // Size of palette
|
||||
palette.forEach(netOutputStream::writeVarInt); // Palette
|
||||
// </Palette>
|
||||
// <Data Array>
|
||||
final int dataLength = (4096/*16*16*16*/ * bitsPerBlock) / 64/*size of long in bits*/;
|
||||
netOutputStream.writeVarInt(dataLength); // Size of Data Array
|
||||
// <Array>
|
||||
writePalette(bitsPerBlock, netOutputStream);
|
||||
// </Array>
|
||||
// </Data Array>
|
||||
// <Block Light>
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package mc.core.network.proto_1_12_2.serializers;
|
||||
|
||||
import mc.core.world.block.BlockLocation;
|
||||
|
||||
import static com.google.common.math.IntMath.isPowerOfTwo;
|
||||
|
||||
public class BlockLocationSerializer {
|
||||
private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[] {0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
|
||||
private static final int NUM_X_BITS = 1 + log2(smallestEncompassingPowerOfTwo(30000000));
|
||||
private static final int NUM_Z_BITS = NUM_X_BITS;
|
||||
private static final int NUM_Y_BITS = 64 - NUM_X_BITS - NUM_Z_BITS;
|
||||
private static final int Y_SHIFT = NUM_Z_BITS;
|
||||
private static final int X_SHIFT = Y_SHIFT + NUM_Y_BITS;
|
||||
private static final long X_MASK = (1L << NUM_X_BITS) - 1L;
|
||||
private static final long Y_MASK = (1L << NUM_Y_BITS) - 1L;
|
||||
private static final long Z_MASK = (1L << NUM_Z_BITS) - 1L;
|
||||
|
||||
/*
|
||||
* net.minecraft.util.math.MathHelper#log2(int)
|
||||
*/
|
||||
private static int log2(int value) {
|
||||
return log2DeBruijn(value) - (isPowerOfTwo(value) ? 0 : 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* net.minecraft.util.math.MathHelper#log2DeBruijn(int)
|
||||
*/
|
||||
private static int log2DeBruijn(int value) {
|
||||
value = isPowerOfTwo(value) ? value : smallestEncompassingPowerOfTwo(value);
|
||||
return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int)((long)value * 125613361L >> 27) & 31];
|
||||
}
|
||||
|
||||
/*
|
||||
* net.minecraft.util.math.MathHelper#smallestEncompassingPowerOfTwo(int)
|
||||
*/
|
||||
private static int smallestEncompassingPowerOfTwo(int value) {
|
||||
int i = value - 1;
|
||||
i = i | i >> 1;
|
||||
i = i | i >> 2;
|
||||
i = i | i >> 4;
|
||||
i = i | i >> 8;
|
||||
i = i | i >> 16;
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
public static long toLong(BlockLocation location) {
|
||||
return ((long)location.getX() & X_MASK) << X_SHIFT |
|
||||
((long)location.getY() & Y_MASK) << Y_SHIFT |
|
||||
((long)location.getZ() & Z_MASK);
|
||||
}
|
||||
|
||||
public static BlockLocation fromLong(long value) {
|
||||
BlockLocation location = BlockLocation.ZERO();
|
||||
fromLong(value, location);
|
||||
return location;
|
||||
}
|
||||
|
||||
public static void fromLong(long value, BlockLocation location) {
|
||||
location.setX((int)(value << 64 - X_SHIFT - NUM_X_BITS >> 64 - NUM_X_BITS));
|
||||
location.setY((int)(value << 64 - Y_SHIFT - NUM_Y_BITS >> 64 - NUM_Y_BITS));
|
||||
location.setZ((int)(value << 64 - NUM_Z_BITS >> 64 - NUM_Z_BITS));
|
||||
}
|
||||
}
|
||||
@@ -81,4 +81,9 @@ public class ByteArrayInputNetStream extends NetInputStream_p340 {
|
||||
public void skipBytes(int count) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
bais.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ class ByteArrayOutputNetStreamTest {
|
||||
|
||||
final byte[] strBytes = string.getBytes(StandardCharsets.UTF_8);
|
||||
final byte[] bytes = new byte[strBytes.length + 1];
|
||||
bytes[0] = (byte) string.length(); // здесь считается, что размер поместится в один байт
|
||||
bytes[0] = (byte) strBytes.length; // здесь считается, что размер поместится в один байт
|
||||
System.arraycopy(strBytes, 0, bytes, 1, strBytes.length);
|
||||
|
||||
assertArrayEquals(bytes, byteArrayOutputNetStream.toByteArray());
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package mc.core.network.proto_1_12_2.serializers;
|
||||
|
||||
import mc.core.world.block.BlockLocation;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class BlockLocationSerializerTest {
|
||||
private static final ThreadLocalRandom rnd = ThreadLocalRandom.current();
|
||||
private static final int minI = 0, maxI = 10;
|
||||
private int x, y, z;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
x = rnd.nextInt(minI, maxI);
|
||||
y = rnd.nextInt(minI, maxI);
|
||||
z = rnd.nextInt(minI, maxI);
|
||||
}
|
||||
|
||||
@Test
|
||||
void serialize() {
|
||||
BlockLocation location = new BlockLocation(x, y, z);
|
||||
final long serializedCoords = BlockLocationSerializer.toLong(location);
|
||||
|
||||
BlockLocation deserLoc = BlockLocationSerializer.fromLong(serializedCoords);
|
||||
|
||||
assertEquals(location, deserLoc);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,9 @@ public class PacketDecoder extends ReplayingDecoder<CSPacket> {
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
State state = ctx.channel().attr(ATTR_STATE).get();
|
||||
/* FIXME: SONAR посчитал нужным здесь задействовать try-with-resources
|
||||
* однако для ByteBuf не существует понятия `close`. Необходимо проанализировать необходимость
|
||||
* использования реализации интерфейса InputStream и если её нет, то убрать. */
|
||||
NetInputStream netStream = new WrapperNetInputStream(in);
|
||||
|
||||
int packetSize = netStream.readVarInt();
|
||||
|
||||
@@ -27,6 +27,9 @@ public class PacketEncoder extends MessageToByteEncoder<SCPacket> {
|
||||
log.debug("Send {}:{}", state, packet);
|
||||
|
||||
try {
|
||||
/* FIXME: SONAR посчитал нужным здесь задействовать try-with-resources
|
||||
* однако для ByteBuf не существует понятия `close`. Необходимо проанализировать необходимость
|
||||
* использования реализации интерфейса OutputStream и если её нет, то убрать. */
|
||||
NetOutputStream netStream = new WrapperNetOutputStream(out);
|
||||
netStream.writeVarInt(id);
|
||||
packet.writeSelf(netStream);
|
||||
|
||||
@@ -32,6 +32,9 @@ public class PacketPostEncoder extends MessageToByteEncoder<ByteBuf> {
|
||||
}
|
||||
|
||||
out.ensureWritable(sizeOfPktSize + pktSize);
|
||||
/* FIXME: SONAR посчитал нужным здесь задействовать try-with-resources
|
||||
* однако для ByteBuf не существует понятия `close`. Необходимо проанализировать необходимость
|
||||
* использования реализации интерфейса OutputStream и если её нет, то убрать. */
|
||||
(new WrapperNetOutputStream(out)).writeVarInt(pktSize);
|
||||
out.writeBytes(msg);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class PlayerEventListener {
|
||||
|
||||
@Subscriber
|
||||
public void playerChunkLoadHandler(SC_ChunkLoadEvent event) {
|
||||
if (event.getNeedLoadChunks().size() == 0) return;
|
||||
if (event.getNeedLoadChunks().isEmpty()) return;
|
||||
|
||||
final NetChannel channel = event.getPlayer().getChannel();
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PlayerEventListener {
|
||||
|
||||
@Subscriber
|
||||
public void playerChunkUnloadHandler(SC_ChunkUnloadEvent event) {
|
||||
if (event.getNeedUnloadChunks().size() == 0) return;
|
||||
if (event.getNeedUnloadChunks().isEmpty()) return;
|
||||
|
||||
final NetChannel channel = event.getPlayer().getChannel();
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public class PlayHandler extends AbstractStateHandler implements PlayStateHandle
|
||||
return;
|
||||
}
|
||||
|
||||
CS_PlayerMoveEvent event = new CS_PlayerMoveEvent(player, player.getLocation().clone());
|
||||
CS_PlayerMoveEvent event = new CS_PlayerMoveEvent(player, player.getLocation().copy());
|
||||
event.setNewLocation(new EntityLocation(
|
||||
packet.getX(), packet.getY(), packet.getZ(),
|
||||
player.getLocation().getYaw(),
|
||||
|
||||
Reference in New Issue
Block a user