mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-01 05:58:00 +01:00
Explosion and loot table callbacks in CustomBlock + custom blocks can write block entities
This commit is contained in:
parent
fe3025fce5
commit
18a9f2485d
@ -213,7 +213,7 @@ public class Chunk implements Viewable {
|
||||
refreshBlockValue(x, y, z, blockId, customBlockId);
|
||||
}
|
||||
|
||||
public Data getData(byte x, byte y, byte z) {
|
||||
public Data getData(int x, byte y, int z) {
|
||||
int index = SerializerUtils.coordToChunkIndex(x, y, z);
|
||||
return getData(index);
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
|
||||
public Data getBlockData(int x, int y, int z) {
|
||||
Chunk chunk = getChunkAt(x, z);
|
||||
return chunk.getData((byte) x, (byte) y, (byte) z);
|
||||
return chunk.getData(x, (byte) y, z);
|
||||
}
|
||||
|
||||
public Data getBlockData(BlockPosition blockPosition) {
|
||||
|
@ -3,6 +3,8 @@ package net.minestom.server.instance.block;
|
||||
import net.minestom.server.data.Data;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.gamedata.loottables.LootTable;
|
||||
import net.minestom.server.gamedata.loottables.LootTableManager;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.utils.BlockPosition;
|
||||
import net.minestom.server.utils.time.UpdateOption;
|
||||
@ -134,10 +136,29 @@ public abstract class CustomBlock {
|
||||
/**
|
||||
* Allows custom block to write block entity data to a given NBT compound
|
||||
*
|
||||
* @param instance instance of which the block lives
|
||||
* @param position position of the block
|
||||
* @param blockData equivalent to <pre>instance.getBlockData(position)</pre>
|
||||
*/
|
||||
public void writeBlockEntity(Instance instance, BlockPosition position, Data blockData, CompoundTag nbt) {
|
||||
public void writeBlockEntity(BlockPosition position, Data blockData, CompoundTag nbt) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an explosion wants to destroy this block.
|
||||
* @param instance
|
||||
* @param lootTableArguments arguments used in the loot table loot generation
|
||||
* @return 'true' if the explosion should happen on this block, 'false' to cancel the destruction.
|
||||
* Returning true does NOT block the explosion rays, ie it does not change the block explosion resistance
|
||||
*/
|
||||
public boolean onExplode(Instance instance, BlockPosition position, Data lootTableArguments) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the loot table associated to this block. Return null to use vanilla behavior
|
||||
* @param tableManager
|
||||
* @return
|
||||
*/
|
||||
public LootTable getLootTable(LootTableManager tableManager) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.data.Data;
|
||||
import net.minestom.server.instance.Biome;
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.instance.block.CustomBlock;
|
||||
import net.minestom.server.network.packet.PacketWriter;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
@ -99,6 +101,11 @@ public class ChunkDataPacket implements ServerPacket {
|
||||
blockEntity.put("x", new DoubleTag(blockPosition.getX() + 16 * chunk.getChunkX()));
|
||||
blockEntity.put("y", new DoubleTag(blockPosition.getY()));
|
||||
blockEntity.put("z", new DoubleTag(blockPosition.getZ() + 16 * chunk.getChunkZ()));
|
||||
CustomBlock customBlock = chunk.getCustomBlock(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
|
||||
if (customBlock != null) {
|
||||
Data data = chunk.getData(blockPosition.getX(), (byte)blockPosition.getY(), blockPosition.getZ());
|
||||
customBlock.writeBlockEntity(blockPosition, data, blockEntity);
|
||||
}
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
try {
|
||||
blockEntity.serialize(new DataOutputStream(os), 100);
|
||||
|
Loading…
Reference in New Issue
Block a user