mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-14 22:56:31 +01:00
Added CustomBlock#getCustomBlockId, it is now defined by the developer and not increased automatically by a counter
This commit is contained in:
parent
22511ca052
commit
ce40627a36
@ -37,4 +37,9 @@ public class StoneBlock extends CustomBlock {
|
||||
public int getBreakDelay(Player player) {
|
||||
return 750;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getCustomBlockId() {
|
||||
return 2;
|
||||
}
|
||||
}
|
@ -45,4 +45,9 @@ public class UpdatableBlockDemo extends CustomBlock {
|
||||
public int getBreakDelay(Player player) {
|
||||
return 500;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getCustomBlockId() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public interface BlockModifier {
|
||||
|
||||
default void setCustomBlock(int x, int y, int z, String customBlockId, Data data) {
|
||||
CustomBlock customBlock = BLOCK_MANAGER.getCustomBlock(customBlockId);
|
||||
setCustomBlock(x, y, z, customBlock.getId(), data);
|
||||
setCustomBlock(x, y, z, customBlock.getCustomBlockId(), data);
|
||||
}
|
||||
|
||||
default void setCustomBlock(int x, int y, int z, String customBlockId) {
|
||||
|
@ -80,7 +80,7 @@ public class Chunk implements Viewable {
|
||||
|
||||
private void setCustomBlock(int x, int y, int z, CustomBlock customBlock, Data data) {
|
||||
UpdateConsumer updateConsumer = customBlock.hasUpdate() ? customBlock::update : null;
|
||||
setBlock(x, y, z, customBlock.getBlockId(), customBlock.getId(), data, updateConsumer);
|
||||
setBlock(x, y, z, customBlock.getBlockId(), customBlock.getCustomBlockId(), data, updateConsumer);
|
||||
}
|
||||
|
||||
private void setBlock(int x, int y, int z, short blockId, short customId, Data data, UpdateConsumer updateConsumer) {
|
||||
@ -183,7 +183,7 @@ public class Chunk implements Viewable {
|
||||
|
||||
protected void refreshBlockValue(int x, int y, int z, short blockId) {
|
||||
CustomBlock customBlock = getCustomBlock(x, y, z);
|
||||
short customBlockId = customBlock == null ? 0 : customBlock.getId();
|
||||
short customBlockId = customBlock == null ? 0 : customBlock.getCustomBlockId();
|
||||
refreshBlockValue(x, y, z, blockId, customBlockId);
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ public class BlockManager {
|
||||
|
||||
public void registerCustomBlock(CustomBlock customBlock) {
|
||||
String identifier = customBlock.getIdentifier();
|
||||
short id = customBlock.getId();
|
||||
short id = customBlock.getCustomBlockId();
|
||||
this.customBlocksInternalId.put(id, customBlock);
|
||||
this.customBlocksId.put(identifier, customBlock);
|
||||
}
|
||||
|
@ -6,24 +6,18 @@ import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.utils.BlockPosition;
|
||||
import net.minestom.server.utils.time.UpdateOption;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* - option to set the global as "global breaking" meaning that multiple players mining the same block will break it faster (cumulation)
|
||||
*/
|
||||
public abstract class CustomBlock {
|
||||
|
||||
private static final AtomicInteger idCounter = new AtomicInteger();
|
||||
|
||||
private short blockId;
|
||||
private String identifier;
|
||||
private short id;
|
||||
|
||||
public CustomBlock(short blockId, String identifier) {
|
||||
this.blockId = blockId;
|
||||
this.identifier = identifier;
|
||||
this.id = (short) idCounter.incrementAndGet();
|
||||
}
|
||||
|
||||
// TODO add another object parameter which will offer a lot of integrated features (like break animation, id change etc...)
|
||||
@ -39,6 +33,14 @@ public abstract class CustomBlock {
|
||||
|
||||
public abstract UpdateOption getUpdateOption();
|
||||
|
||||
/**
|
||||
* This id can be serialized in chunk file, meaning no duplicate should exist
|
||||
* Changing this value halfway should mean potentially breaking the world
|
||||
*
|
||||
* @return the custom block id
|
||||
*/
|
||||
public abstract short getCustomBlockId();
|
||||
|
||||
/*
|
||||
Time in ms
|
||||
*/
|
||||
@ -59,8 +61,4 @@ public abstract class CustomBlock {
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public short getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user