forked from Nan1t/NanoLimbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimized packet snapshot. Readers closing. Restructured schematic cl…
…asses
- Loading branch information
Showing
12 changed files
with
227 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (C) 2020 Nan1t | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package ru.nanit.limbo.world; | ||
|
||
import ru.nanit.limbo.protocol.registry.Version; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public final class BlockMappings { | ||
|
||
private final Map<String, String> idToState = new HashMap<>(); | ||
private final Map<String, String> stateToId = new HashMap<>(); | ||
|
||
public BlockData convert(int id, byte data, Version version) { | ||
if (version.less(Version.V1_13)) | ||
return new BlockData(id, data); | ||
|
||
String state = idToState.get(toId(id, data)); | ||
|
||
return state != null ? new BlockData(state) : null; | ||
} | ||
|
||
public BlockData convert(String state, Version version) { | ||
if (state == null) return null; | ||
|
||
if (version.moreOrEqual(Version.V1_13)) { | ||
return new BlockData(state); | ||
} | ||
|
||
String id = stateToId.get(state); | ||
|
||
if (id != null) { | ||
String[] arr = id.split(":"); | ||
int blockId = Integer.parseInt(arr[0]); | ||
byte data = Byte.parseByte(arr[1]); | ||
|
||
return new BlockData(blockId, data); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public void register(int id, byte data, String state) { | ||
String strId = toId(id, data); | ||
idToState.put(strId, state); | ||
stateToId.put(state, strId); | ||
} | ||
|
||
private String toId(int id, byte data) { | ||
return id + ":" + data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/java/ru/nanit/limbo/world/schematic/AbstractSchematic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (C) 2020 Nan1t | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package ru.nanit.limbo.world.schematic; | ||
|
||
import ru.nanit.limbo.world.BlockEntity; | ||
import ru.nanit.limbo.world.BlockMappings; | ||
|
||
import java.util.List; | ||
|
||
public abstract class AbstractSchematic implements Schematic { | ||
|
||
protected final BlockMappings mappings; | ||
|
||
private int width; | ||
private int height; | ||
private int length; | ||
private List<BlockEntity> blockEntities; | ||
|
||
public AbstractSchematic(BlockMappings mappings) { | ||
this.mappings = mappings; | ||
} | ||
|
||
@Override | ||
public int getWidth() { | ||
return width; | ||
} | ||
|
||
@Override | ||
public int getHeight() { | ||
return height; | ||
} | ||
|
||
@Override | ||
public int getLength() { | ||
return length; | ||
} | ||
|
||
@Override | ||
public List<BlockEntity> getBlockEntities() { | ||
return blockEntities; | ||
} | ||
|
||
public void setWidth(int width) { | ||
this.width = width; | ||
} | ||
|
||
public void setHeight(int height) { | ||
this.height = height; | ||
} | ||
|
||
public void setLength(int length) { | ||
this.length = length; | ||
} | ||
|
||
public void setBlockEntities(List<BlockEntity> blockEntities) { | ||
this.blockEntities = blockEntities; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.