Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
<java.version>21</java.version>
<!-- More visible way how to change dependency versions -->
<paper.version>1.21.11-R0.1-SNAPSHOT</paper.version>
<bentobox.version>3.14.0-SNAPSHOT</bentobox.version>
<!-- 3.18.x+ artifacts are compiled for Java 25 (class file 69) and cannot be read by the
Java 21 toolchain used here and in CI. Stay on 3.17.0 until the ecosystem moves to 25. -->
<bentobox.version>3.17.0</bentobox.version>
<level.version>2.5.0</level.version>
<bank.version>1.4.0</bank.version>
<aoneblock.version>1.18.0</aoneblock.version>
Expand All @@ -50,7 +52,7 @@
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- This allows to change between versions and snapshots. -->
<build.version>2.9.0</build.version>
<build.version>2.10.0</build.version>
<build.number>-LOCAL</build.number>
<!-- Sonar Cloud -->
<sonar.projectKey>BentoBoxWorld_MagicCobblestoneGenerator</sonar.projectKey>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;

Expand Down Expand Up @@ -345,10 +346,12 @@ public void setActivateOnUnlock(boolean activateOnUnlock)
/**
* Returns the blockChanceMap of this object.
*
* @return a {@code TreeMap} where the keys are {@code Double} values representing chances,
* and the values are {@code Material} objects.
* @return a {@code SortedMap} where the keys are {@code Double} values representing chances,
* and the values are block IDs: vanilla {@code Material} names (e.g. {@code COBBLESTONE})
* or provider-prefixed custom block IDs (e.g. {@code itemsadder:namespace:id}) — see
* {@link world.bentobox.magiccobblestonegenerator.utils.CustomBlocks}.
*/
public TreeMap<Double, Material> getBlockChanceMap()
public NavigableMap<Double, String> getBlockChanceMap()
{
return blockChanceMap;
}
Expand All @@ -359,9 +362,9 @@ public TreeMap<Double, Material> getBlockChanceMap()
*
* @param blockChanceMap new value for this object.
*/
public void setBlockChanceMap(TreeMap<Double, Material> blockChanceMap)
public void setBlockChanceMap(NavigableMap<Double, String> blockChanceMap)
{
this.blockChanceMap = blockChanceMap;
this.blockChanceMap = new TreeMap<>(blockChanceMap);
}


Expand Down Expand Up @@ -813,10 +816,11 @@ public boolean includes(GeneratorType type)
// Rewards section

/**
* Map that stores different blocks and their chance for generating.
* Map that stores different blocks and their chance for generating. Values are vanilla material
* names or provider-prefixed custom block IDs.
*/
@Expose
private TreeMap<Double, Material> blockChanceMap = new TreeMap<>();
private TreeMap<Double, String> blockChanceMap = new TreeMap<>();

/**
* Map that stores different extra treasures and their change for being dropped.
Expand Down Expand Up @@ -856,10 +860,10 @@ public boolean includes(GeneratorType type)
private int maxHeight = 320;

/**
* Map that stores min and max heights for each material in the generator.
* Map that stores min and max heights for each block ID in the generator.
*/
@Expose
private TreeMap<Material, int[]> materialHeightMap = new TreeMap<>();
private TreeMap<String, int[]> materialHeightMap = new TreeMap<>();

/**
* Maximum number of blocks this generator tier is allowed to generate during a single exhaustion period.
Expand All @@ -872,22 +876,22 @@ public boolean includes(GeneratorType type)
* Field to store block height ranges
*/
@Expose
private Map<Material, int[]> blockHeightRanges = new HashMap<>();
private Map<String, int[]> blockHeightRanges = new HashMap<>();

/**
* Gets the height ranges for each block type
* @return Map of Material to height range array [min, max]
* @return Map of block ID to height range array [min, max]
*/
public Map<Material, int[]> getBlockHeightRanges()
public Map<String, int[]> getBlockHeightRanges()
{
return blockHeightRanges;
}

/**
* Sets the height ranges for each block type
* @param blockHeightRanges Map of Material to height range array [min, max]
* @param blockHeightRanges Map of block ID to height range array [min, max]
*/
public void setBlockHeightRanges(Map<Material, int[]> blockHeightRanges)
public void setBlockHeightRanges(Map<String, int[]> blockHeightRanges)
{
this.blockHeightRanges = blockHeightRanges;
}
Expand Down Expand Up @@ -937,48 +941,48 @@ public void setMaxHeight(int maxHeight)


/**
* Gets the map of material-specific height ranges.
* Gets the map of block-specific height ranges, keyed by block ID.
*
* @return the material height map
*/
public TreeMap<Material, int[]> getMaterialHeightMap()
public NavigableMap<String, int[]> getMaterialHeightMap()
{
return this.materialHeightMap;
}


/**
* Sets the map of material-specific height ranges.
* Sets the map of block-specific height ranges, keyed by block ID.
*
* @param materialHeightMap the material height map
*/
public void setMaterialHeightMap(TreeMap<Material, int[]> materialHeightMap)
public void setMaterialHeightMap(NavigableMap<String, int[]> materialHeightMap)
{
this.materialHeightMap = materialHeightMap;
this.materialHeightMap = new TreeMap<>(materialHeightMap);
}


/**
* Gets the height range for a specific material.
* Gets the height range for a specific block ID.
*
* @param material the material
* @param blockId the block ID
* @return an array where index 0 is minHeight and index 1 is maxHeight, or null if not set
*/
public int[] getMaterialHeightRange(Material material)
public int[] getMaterialHeightRange(String blockId)
{
return this.materialHeightMap.get(material);
return this.materialHeightMap.get(blockId);
}


/**
* Sets the height range for a specific material.
* Sets the height range for a specific block ID.
*
* @param material the material
* @param blockId the block ID
* @param minHeight the minimum height
* @param maxHeight the maximum height
*/
public void setMaterialHeightRange(Material material, int minHeight, int maxHeight)
public void setMaterialHeightRange(String blockId, int minHeight, int maxHeight)
{
this.materialHeightMap.put(material, new int[]{minHeight, maxHeight});
this.materialHeightMap.put(blockId, new int[]{minHeight, maxHeight});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import world.bentobox.magiccobblestonegenerator.StoneGeneratorAddon;
import world.bentobox.magiccobblestonegenerator.database.objects.GeneratorDataObject;
import world.bentobox.magiccobblestonegenerator.database.objects.GeneratorTierObject;
import world.bentobox.magiccobblestonegenerator.utils.CustomBlocks;
import world.bentobox.magiccobblestonegenerator.utils.Why;


/**
Expand Down Expand Up @@ -151,13 +153,67 @@ protected void playEffects(Block block)


/**
* This method returns material of new block if generator manages to replace cobblestone to a new magic block.
* This method applies a block ID picked by the generator to the given block. Vanilla IDs are set
* immediately; custom (hook-provided) IDs first set a vanilla placeholder and are replaced by the
* hook placement one tick later, because hook APIs set blocks directly rather than through a state.
*
* @param blockId Block ID picked by the generator (vanilla material name or provider-prefixed custom ID).
* @param block Block that must be replaced.
* @param placeholder Vanilla material to leave in place while a custom placement is pending.
* @return {@code true} if a replacement was applied or scheduled.
*/
protected boolean applyBlockId(String blockId, Block block, Material placeholder)
{
Material material = CustomBlocks.matchVanilla(blockId);

if (material != null)
{
if (!material.isBlock())
{
return false;
}

block.setType(material);
return true;
}

if (CustomBlocks.isCustom(blockId))
{
block.setType(placeholder);
this.scheduleCustomBlockPlacement(blockId, block.getLocation());
return true;
}

return false;
}


/**
* This method schedules placement of a custom block via its BentoBox hook on the next tick.
*
* @param blockId Provider-prefixed custom block ID.
* @param location Location where the block must be placed.
*/
protected void scheduleCustomBlockPlacement(String blockId, Location location)
{
Bukkit.getScheduler().runTask(this.addon.getPlugin(), () ->
{
if (!CustomBlocks.place(this.addon, blockId, location))
{
Why.report(location, "Custom block " + blockId + " could not be placed.");
}
});
}


/**
* This method returns block ID of new block if generator manages to replace cobblestone to a new magic block.
*
* @param island Island on which block is processed.
* @param location Block location that need to be replaced.
* @return Material of replaced block or null, if block was not replaced.
* @return Block ID of replaced block or null, if block was not replaced.
*/
protected @Nullable Material generateCobblestoneReplacement(@Nullable Island island, Location location)
protected @Nullable String generateCobblestoneReplacement(@Nullable Island island, Location location)
{
GeneratorTierObject generatorTier = this.addon.getAddonManager().getGeneratorTier(
island,
Expand All @@ -175,13 +231,13 @@ protected void playEffects(Block block)


/**
* This method returns material of new block if generator manages to replace stone to a new magic block.
* This method returns block ID of new block if generator manages to replace stone to a new magic block.
*
* @param island Island on which block is processed.
* @param location Block that need to be replaced.
* @return Material of replaced block or null, if block was not replaced.
* @return Block ID of replaced block or null, if block was not replaced.
*/
protected @Nullable Material generateStoneReplacement(@Nullable Island island, Location location)
protected @Nullable String generateStoneReplacement(@Nullable Island island, Location location)
{
GeneratorTierObject generatorTier = this.addon.getAddonManager().getGeneratorTier(
island,
Expand All @@ -199,13 +255,13 @@ protected void playEffects(Block block)


/**
* This method returns material of new block if generator manages to replace basalt to a new magic block.
* This method returns block ID of new block if generator manages to replace basalt to a new magic block.
*
* @param island Island on which block is processed.
* @param location Block that need to be replaced.
* @return Material of replaced block or null, if block was not replaced.
* @return Block ID of replaced block or null, if block was not replaced.
*/
protected @Nullable Material generateBasaltReplacement(@Nullable Island island, Location location)
protected @Nullable String generateBasaltReplacement(@Nullable Island island, Location location)
{
GeneratorTierObject generatorTier = this.addon.getAddonManager().getGeneratorTier(
island,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,10 @@ public void onBlockFromToEvent(BlockFromToEvent event)
{
// Return from here at any case. Even if could not manage to replace stone.

Material material = this.generateStoneReplacement(island, eventToBlock.getLocation());
String blockId = this.generateStoneReplacement(island, eventToBlock.getLocation());

if (material != null)
if (blockId != null && this.applyBlockId(blockId, eventToBlock, Material.STONE))
{
eventToBlock.setType(material);
// sound when lava transforms to cobble
this.playEffects(eventToBlock);
event.setCancelled(true);
Expand All @@ -146,12 +145,11 @@ public void onBlockFromToEvent(BlockFromToEvent event)

if (liquid.equals(Material.LAVA) && this.canLavaGenerateCobblestone(eventToBlock, event.getFace()))
{
Material material = this.generateCobblestoneReplacement(island, eventToBlock.getLocation());
String blockId = this.generateCobblestoneReplacement(island, eventToBlock.getLocation());

// Lava is generating cobblestone into eventToBlock place
if (material != null)
if (blockId != null && this.applyBlockId(blockId, eventToBlock, Material.COBBLESTONE))
{
eventToBlock.setType(material);
// sound when lava transforms to cobble
this.playEffects(eventToBlock);
event.setCancelled(true);
Expand All @@ -168,11 +166,10 @@ else if (liquid.equals(Material.WATER))

if (replacedBlock != null)
{
Material material = this.generateStoneReplacement(island, replacedBlock.getLocation());
String blockId = this.generateStoneReplacement(island, replacedBlock.getLocation());

if (material != null)
if (blockId != null && this.applyBlockId(blockId, replacedBlock, Material.STONE))
{
replacedBlock.setType(material);
// sound when lava transforms to cobble
this.playEffects(eventToBlock);
}
Expand Down
Loading
Loading