mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 02:36:59 +00:00
Attempt at faster block data
This commit is contained in:
parent
13bf6a89cb
commit
93529cda60
75
src/main/java/com/volmit/iris/util/FastBlockData.java
Normal file
75
src/main/java/com/volmit/iris/util/FastBlockData.java
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package com.volmit.iris.util;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
|
public class FastBlockData
|
||||||
|
{
|
||||||
|
private static final KMap<Material, BlockData> defaultBlockData = new KMap<>();
|
||||||
|
private BlockData blockData;
|
||||||
|
private Material type;
|
||||||
|
|
||||||
|
private FastBlockData(BlockData d)
|
||||||
|
{
|
||||||
|
this.blockData = d;
|
||||||
|
this.type = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private FastBlockData(Material m)
|
||||||
|
{
|
||||||
|
this.type = m;
|
||||||
|
this.blockData = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FastBlockData of(Material type)
|
||||||
|
{
|
||||||
|
return new FastBlockData(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FastBlockData of(BlockData type)
|
||||||
|
{
|
||||||
|
return new FastBlockData(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getType()
|
||||||
|
{
|
||||||
|
return type != null ? type : blockData.getMaterial();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FastBlockData optimize()
|
||||||
|
{
|
||||||
|
if(hasBlockData())
|
||||||
|
{
|
||||||
|
BlockData f = getDefaultBlockData(type);
|
||||||
|
|
||||||
|
if(f.hashCode() == getBlockData().hashCode())
|
||||||
|
{
|
||||||
|
type = getBlockData().getMaterial();
|
||||||
|
blockData = null;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BlockData getDefaultBlockData(Material type)
|
||||||
|
{
|
||||||
|
return defaultBlockData.compute(type, (k, v) -> v != null ? v : type.createBlockData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasBlockData()
|
||||||
|
{
|
||||||
|
return blockData != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockData getBlockData()
|
||||||
|
{
|
||||||
|
if(blockData != null)
|
||||||
|
{
|
||||||
|
return blockData;
|
||||||
|
}
|
||||||
|
|
||||||
|
return type.createBlockData();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user