Fixed blockstates resetting when normal blocks were regenerated using custom mining

This commit is contained in:
ASangarin 2020-12-27 22:19:57 +01:00
parent 0662f460f2
commit 240fad3f34
4 changed files with 20 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import net.Indyuce.mmocore.api.block.BlockInfo.RegeneratingBlock;
public interface BlockType {
void place(Location loc, RegeneratingBlock regenerating);
void regen(Location loc, RegeneratingBlock regenerating);
/**
* Generates a key used to store the BlockInfo instance in the manager map,

View File

@ -1,13 +1,12 @@
package net.Indyuce.mmocore.api.block;
import org.bukkit.Location;
import org.bukkit.block.Block;
import net.Indyuce.mmocore.api.block.BlockInfo.RegeneratingBlock;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.MMOLineConfig;
import net.mmogroup.mmolib.version.VersionMaterial;
import org.bukkit.Location;
import org.bukkit.block.Block;
public class SkullBlockType implements BlockType {
private final String value;
@ -37,6 +36,15 @@ public class SkullBlockType implements BlockType {
MMOLib.plugin.getVersion().getWrapper().setSkullValue(loc.getBlock(), value);
}
@Override
public void regen(Location loc, RegeneratingBlock block) {
// This makes sure that if a skull loses it's original rotation
// it can revert back to it when the base block is regenerated
loc.getBlock().setBlockData(block.getBlockData());
MMOLib.plugin.getVersion().getWrapper().setSkullValue(loc.getBlock(), value);
}
@Override
public String generateKey() {
return "vanilla-skull-" + value;

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.api.block;
import net.mmogroup.mmolib.MMOLib;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.Material;
@ -48,6 +49,12 @@ public class VanillaBlockType implements BlockType {
}
}
@Override
public void regen(Location loc, RegeneratingBlock block) {
// Sets the original blocks old data (only when regenerating)
loc.getBlock().setBlockData(block.getBlockData());
}
@Override
public String generateKey() {
return "vanilla-block-" + type.name();

View File

@ -124,6 +124,7 @@ public class CustomBlockManager extends MMOManager {
// Get the chunk and load it async if needed.
PaperLib.getChunkAtAsync(infoLocation).whenComplete((chunk, ex) -> {
info.getRegeneratingBlock().getBlock().place(infoLocation, info);
info.getRegeneratingBlock().getBlock().regen(infoLocation, info);
info.getLocation().getBlock().getState().update();
if (!shutdown)
active.remove(info);