Compare commits
5 Commits
ff5886f549
...
7da6871d5c
Author | SHA1 | Date |
---|---|---|
Gerber Lóránt Viktor | 7da6871d5c | |
Gerber Lóránt Viktor | 4e502a8fed | |
Gerber Lóránt Viktor | 1d98922bb2 | |
Gerber Lóránt Viktor | fca5da42f4 | |
Gerber Lóránt Viktor | 574bc6f9e8 |
|
@ -1,3 +1,27 @@
|
|||
/*
|
||||
* This file is part of BlueMap, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package de.bluecolored.bluemap.core.world.block.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -7,7 +31,7 @@ import java.util.Map;
|
|||
public class BannerBlockEntity extends BlockEntity {
|
||||
private final List<Pattern> patterns = new ArrayList<>();
|
||||
|
||||
private BannerBlockEntity(Map<String, Object> data) {
|
||||
protected BannerBlockEntity(Map<String, Object> data) {
|
||||
super(data);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -1,3 +1,27 @@
|
|||
/*
|
||||
* This file is part of BlueMap, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package de.bluecolored.bluemap.core.world.block.entity;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
@ -13,15 +37,23 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@NBTDeserializer(BlockEntity.BlockEntityDeserializer.class)
|
||||
public class BlockEntity {
|
||||
private static final BlueNBT BLUENBT = new BlueNBT();
|
||||
private static final Map<String, Class<? extends BlockEntity>> ID_MAPPING = Map.of(
|
||||
"minecraft:sign", SignBlockEntity.class,
|
||||
"minecraft:skull", SkullBlockEntity.class,
|
||||
"minecraft:banner", BannerBlockEntity.class
|
||||
|
||||
@FunctionalInterface
|
||||
private interface BlockEntityInitializer {
|
||||
BlockEntity create(Map<String, Object> data);
|
||||
}
|
||||
|
||||
@SuppressWarnings("StaticInitializerReferencesSubClass")
|
||||
private static final Map<String, BlockEntityInitializer> ID_MAPPING = Map.of(
|
||||
"minecraft:sign", SignBlockEntity::new,
|
||||
"minecraft:skull", SkullBlockEntity::new,
|
||||
"minecraft:banner", BannerBlockEntity::new
|
||||
);
|
||||
|
||||
protected final String id;
|
||||
|
@ -91,16 +123,10 @@ public class BlockEntity {
|
|||
return null;
|
||||
}
|
||||
|
||||
Class<? extends BlockEntity> dataClass = ID_MAPPING.getOrDefault(id, BlockEntity.class);
|
||||
BlockEntityInitializer instance = ID_MAPPING.getOrDefault(id, BlockEntity::new);
|
||||
|
||||
try {
|
||||
Constructor<? extends BlockEntity> constructor = dataClass.getDeclaredConstructor(Map.class);
|
||||
if (constructor.trySetAccessible()) {
|
||||
return constructor.newInstance(data);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
Logger.global.logError(
|
||||
String.format("No constructor in %s that takes a Map!", dataClass.getCanonicalName()), e);
|
||||
return instance.create(data);
|
||||
} catch (Exception e) {
|
||||
Logger.global.logError("Failed to instantiate BlockEntity instance!", e);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,27 @@
|
|||
/*
|
||||
* This file is part of BlueMap, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package de.bluecolored.bluemap.core.world.block.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -8,7 +32,7 @@ public class SignBlockEntity extends BlockEntity {
|
|||
private final TextData backText;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private SignBlockEntity(Map<String, Object> data) {
|
||||
protected SignBlockEntity(Map<String, Object> data) {
|
||||
super(data);
|
||||
|
||||
// Versions before 1.20 used a different format
|
||||
|
|
|
@ -1,3 +1,27 @@
|
|||
/*
|
||||
* This file is part of BlueMap, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package de.bluecolored.bluemap.core.world.block.entity;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -12,7 +36,7 @@ public class SkullBlockEntity extends BlockEntity {
|
|||
private final @Nullable String extraType;
|
||||
private final @Nullable SkullOwner skullOwner;
|
||||
|
||||
private SkullBlockEntity(Map<String, Object> data) {
|
||||
protected SkullBlockEntity(Map<String, Object> data) {
|
||||
super(data);
|
||||
|
||||
this.noteBlockSound = (String) data.get("note_block_sound");
|
||||
|
|
|
@ -121,7 +121,7 @@ public class Chunk_1_13 extends MCAChunk {
|
|||
}
|
||||
|
||||
this.blockEntities = level.blockEntities.stream().collect(Collectors.toMap(
|
||||
it -> (long) it.getY() << 40 | (it.getX() & 0xF) << 4 | it.getZ() & 0xF, it -> it
|
||||
it -> (long) it.getY() << 8 | (it.getX() & 0xF) << 4 | it.getZ() & 0xF, it -> it
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ public class Chunk_1_13 extends MCAChunk {
|
|||
|
||||
@Override
|
||||
public @Nullable BlockEntity getBlockEntity(int x, int y, int z) {
|
||||
return blockEntities.get((long) y << 40 | (x & 0xF) << 4 | z & 0xF);
|
||||
return blockEntities.get((long) y << 8 | (x & 0xF) << 4 | z & 0xF);
|
||||
}
|
||||
|
||||
private @Nullable Section getSection(int y) {
|
||||
|
|
|
@ -120,7 +120,7 @@ public class Chunk_1_16 extends MCAChunk {
|
|||
}
|
||||
|
||||
this.blockEntities = level.blockEntities.stream().collect(Collectors.toMap(
|
||||
it -> (long) it.getY() << 40 | (it.getX() & 0xF) << 4 | it.getZ() & 0xF, it -> it
|
||||
it -> (long) it.getY() << 8 | (it.getX() & 0xF) << 4 | it.getZ() & 0xF, it -> it
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,7 @@ public class Chunk_1_16 extends MCAChunk {
|
|||
|
||||
@Override
|
||||
public @Nullable BlockEntity getBlockEntity(int x, int y, int z) {
|
||||
return blockEntities.get((long) y << 40 | (x & 0xF) << 4 | z & 0xF);
|
||||
return blockEntities.get((long) y << 8 | (x & 0xF) << 4 | z & 0xF);
|
||||
}
|
||||
|
||||
private @Nullable Section getSection(int y) {
|
||||
|
|
|
@ -117,7 +117,7 @@ public class Chunk_1_18 extends MCAChunk {
|
|||
}
|
||||
|
||||
this.blockEntities = data.blockEntities.stream().collect(Collectors.toMap(
|
||||
it -> (long) it.getY() << 40 | (it.getX() & 0xF) << 4 | it.getZ() & 0xF, it -> it
|
||||
it -> (long) it.getY() << 8 | (it.getX() & 0xF) << 4 | it.getZ() & 0xF, it -> it
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ public class Chunk_1_18 extends MCAChunk {
|
|||
|
||||
@Override
|
||||
public @Nullable BlockEntity getBlockEntity(int x, int y, int z) {
|
||||
return blockEntities.get((long) y << 40 | (x & 0xF) << 4 | z & 0xF);
|
||||
return blockEntities.get((long) y << 8 | (x & 0xF) << 4 | z & 0xF);
|
||||
}
|
||||
|
||||
private @Nullable Section getSection(int y) {
|
||||
|
|
Loading…
Reference in New Issue