2020-08-08 22:41:12 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2020-08-08 22:41:12 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
package org.geysermc.geyser.level;
|
2020-08-08 22:41:12 +00:00
|
|
|
|
2020-12-28 05:29:27 +00:00
|
|
|
import com.nukkitx.nbt.NbtMap;
|
|
|
|
import com.nukkitx.nbt.NbtMapBuilder;
|
2020-08-08 22:41:12 +00:00
|
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
|
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
2021-11-22 19:52:26 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSession;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.translator.inventory.LecternInventoryTranslator;
|
2020-08-08 22:41:12 +00:00
|
|
|
|
|
|
|
public class GeyserWorldManager extends WorldManager {
|
2022-12-02 19:11:56 +00:00
|
|
|
private final Object2ObjectMap<String, String> gameruleCache = new Object2ObjectOpenHashMap<>();
|
2020-08-08 22:41:12 +00:00
|
|
|
|
|
|
|
@Override
|
2021-11-22 19:52:26 +00:00
|
|
|
public int getBlockAt(GeyserSession session, int x, int y, int z) {
|
2023-02-15 05:17:14 +00:00
|
|
|
return session.getChunkCache().getBlockAt(x, y, z);
|
2020-08-08 22:41:12 +00:00
|
|
|
}
|
|
|
|
|
2020-10-15 06:30:25 +00:00
|
|
|
@Override
|
2021-03-14 16:26:47 +00:00
|
|
|
public boolean hasOwnChunkCache() {
|
2020-10-15 06:30:25 +00:00
|
|
|
// This implementation can only fetch data from the session chunk cache
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-28 05:29:27 +00:00
|
|
|
@Override
|
2021-11-22 19:52:26 +00:00
|
|
|
public NbtMap getLecternDataAt(GeyserSession session, int x, int y, int z, boolean isChunkLoad) {
|
2020-12-28 05:29:27 +00:00
|
|
|
// Without direct server access, we can't get lectern information on-the-fly.
|
|
|
|
// I should have set this up so it's only called when there is a book in the block state. - Camotoy
|
|
|
|
NbtMapBuilder lecternTag = LecternInventoryTranslator.getBaseLecternTag(x, y, z, 1);
|
|
|
|
lecternTag.putCompound("book", NbtMap.builder()
|
|
|
|
.putByte("Count", (byte) 1)
|
|
|
|
.putShort("Damage", (short) 0)
|
|
|
|
.putString("Name", "minecraft:written_book")
|
|
|
|
.putCompound("tag", NbtMap.builder()
|
|
|
|
.putString("photoname", "")
|
|
|
|
.putString("text", "")
|
|
|
|
.build())
|
|
|
|
.build());
|
2021-02-21 23:17:31 +00:00
|
|
|
lecternTag.putInt("page", -1); // I'm surprisingly glad this exists - it forces Bedrock to stop reading immediately. Usually.
|
2020-12-28 05:29:27 +00:00
|
|
|
return lecternTag.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean shouldExpectLecternHandled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-08 22:41:12 +00:00
|
|
|
@Override
|
2021-11-22 19:52:26 +00:00
|
|
|
public void setGameRule(GeyserSession session, String name, Object value) {
|
2022-12-02 19:11:56 +00:00
|
|
|
super.setGameRule(session, name, value);
|
2020-08-08 22:41:12 +00:00
|
|
|
gameruleCache.put(name, String.valueOf(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-12-02 19:11:56 +00:00
|
|
|
public boolean getGameRuleBool(GeyserSession session, GameRule gameRule) {
|
2020-08-08 22:41:12 +00:00
|
|
|
String value = gameruleCache.get(gameRule.getJavaID());
|
|
|
|
if (value != null) {
|
|
|
|
return Boolean.parseBoolean(value);
|
|
|
|
}
|
|
|
|
|
2022-12-02 19:11:56 +00:00
|
|
|
return gameRule.getDefaultBooleanValue();
|
2020-08-08 22:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-11-22 19:52:26 +00:00
|
|
|
public int getGameRuleInt(GeyserSession session, GameRule gameRule) {
|
2020-08-08 22:41:12 +00:00
|
|
|
String value = gameruleCache.get(gameRule.getJavaID());
|
|
|
|
if (value != null) {
|
|
|
|
return Integer.parseInt(value);
|
|
|
|
}
|
|
|
|
|
2022-12-02 19:11:56 +00:00
|
|
|
return gameRule.getDefaultIntValue();
|
2020-08-08 22:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-11-22 19:52:26 +00:00
|
|
|
public boolean hasPermission(GeyserSession session, String permission) {
|
2020-08-08 22:41:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|