mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-29 15:07:36 +02:00
Allow negative break delay to skip stages
This commit is contained in:
parent
6b778f425a
commit
f2222cfaf2
@ -42,7 +42,7 @@ public class StoneBlock extends CustomBlock {
|
||||
|
||||
@Override
|
||||
public int getBreakDelay(Player player, BlockPosition position, byte stage, Set<Player> breakers) {
|
||||
return 5;
|
||||
return -2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -306,12 +306,16 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
// Target block stage
|
||||
if (targetCustomBlock != null) {
|
||||
this.targetBlockBreakCount++;
|
||||
final boolean processStage = targetBlockBreakCount >= targetBreakDelay;
|
||||
|
||||
final boolean processStage = targetBreakDelay < 0 || targetBlockBreakCount >= targetBreakDelay;
|
||||
|
||||
// Negative value should skip abs(value) stage
|
||||
final byte stageIncrease = (byte) (targetBreakDelay > 0 ? 1 : Math.abs(targetBreakDelay));
|
||||
if (processStage) {
|
||||
// Should increment the target block stage
|
||||
if (targetCustomBlock.enableMultiPlayerBreaking()) {
|
||||
// Let the custom block object manages the breaking
|
||||
final boolean canContinue = this.targetCustomBlock.processStage(instance, targetBlockPosition, this);
|
||||
final boolean canContinue = this.targetCustomBlock.processStage(instance, targetBlockPosition, this, stageIncrease);
|
||||
if (canContinue) {
|
||||
final Set<Player> breakers = targetCustomBlock.getBreakers(instance, targetBlockPosition);
|
||||
refreshBreakDelay(breakers);
|
||||
@ -321,7 +325,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
} else {
|
||||
// Let the player object manages the breaking
|
||||
// The custom block doesn't support multi player breaking
|
||||
if (targetStage + 1 >= CustomBlock.MAX_STAGE) {
|
||||
if (targetStage + stageIncrease >= CustomBlock.MAX_STAGE) {
|
||||
// Break the block
|
||||
instance.breakBlock(this, targetBlockPosition);
|
||||
resetTargetBlock();
|
||||
@ -334,7 +338,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
chunk.sendPacketToViewers(blockBreakAnimationPacket);
|
||||
|
||||
refreshBreakDelay(targetBreakers);
|
||||
this.targetStage++;
|
||||
this.targetStage += stageIncrease;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,6 +132,7 @@ public abstract class CustomBlock {
|
||||
* @param stage the current break stage of the block (0-10)
|
||||
* @param breakers the list containing all the players currently digging this block
|
||||
* @return the time in tick to pass to the next state, 0 to instant break it.
|
||||
* negative value allow to skip stages (-2 will skip 2 stages per tick)
|
||||
* @see #enableCustomBreakDelay() to enable/disable it
|
||||
*/
|
||||
public int getBreakDelay(Player player, BlockPosition position, byte stage, Set<Player> breakers) {
|
||||
@ -373,10 +374,11 @@ public abstract class CustomBlock {
|
||||
* @param instance the instance of the block
|
||||
* @param blockPosition the position of the block
|
||||
* @param player the player who processed one stage on the block
|
||||
* @param stageIncrease the number of stage increase
|
||||
* @return true if the block can continue being digged
|
||||
* @throws IllegalStateException if {@link #enableMultiPlayerBreaking()} is disabled
|
||||
*/
|
||||
public synchronized boolean processStage(Instance instance, BlockPosition blockPosition, Player player) {
|
||||
public synchronized boolean processStage(Instance instance, BlockPosition blockPosition, Player player, byte stageIncrease) {
|
||||
Check.stateCondition(!enableMultiPlayerBreaking(),
|
||||
"CustomBlock#processState requires having the multi player breaking feature enabled");
|
||||
|
||||
@ -384,7 +386,7 @@ public abstract class CustomBlock {
|
||||
InstanceBreakData instanceBreakData = instanceBreakDataMap.get(instance);
|
||||
Object2ByteMap<BlockPosition> breakStageMap = instanceBreakData.breakStageMap;
|
||||
byte stage = breakStageMap.getByte(blockPosition);
|
||||
if (stage + 1 >= MAX_STAGE) {
|
||||
if (stage + stageIncrease >= MAX_STAGE) {
|
||||
instance.breakBlock(player, blockPosition);
|
||||
return false;
|
||||
} else {
|
||||
@ -397,7 +399,8 @@ public abstract class CustomBlock {
|
||||
chunk.sendPacketToViewers(new BlockBreakAnimationPacket(entityId, blockPosition, stage));
|
||||
|
||||
// Refresh the stage
|
||||
breakStageMap.put(blockPosition, ++stage);
|
||||
stage += stageIncrease;
|
||||
breakStageMap.put(blockPosition, stage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ public final class PacketWriterUtils {
|
||||
|
||||
/**
|
||||
* Write the packet in the writer thread pool
|
||||
* <p>
|
||||
* WARNING: should not be used if the packet receive order is important
|
||||
*
|
||||
* @param serverPacket the packet to write
|
||||
* @param consumer the consumer called once the packet has been written
|
||||
@ -35,6 +37,8 @@ public final class PacketWriterUtils {
|
||||
|
||||
/**
|
||||
* Write a packet in the writer thread pool and send it to every players in {@code players}
|
||||
* <p>
|
||||
* WARNING: should not be used if the packet receive order is important
|
||||
*
|
||||
* @param players the players list to send the packet to
|
||||
* @param serverPacket the packet to write and send
|
||||
@ -59,6 +63,8 @@ public final class PacketWriterUtils {
|
||||
|
||||
/**
|
||||
* Write a packet and send it to a player connection
|
||||
* <p>
|
||||
* WARNING: should not be used if the packet receive order is important
|
||||
*
|
||||
* @param playerConnection the connection to send the packet to
|
||||
* @param serverPacket the packet to write and send
|
||||
@ -71,6 +77,8 @@ public final class PacketWriterUtils {
|
||||
|
||||
/**
|
||||
* Write a packet and send it to a player
|
||||
* <p>
|
||||
* WARNING: should not be used if the packet receive order is important
|
||||
*
|
||||
* @param player the player to send the packet to
|
||||
* @param serverPacket the packet to write and send
|
||||
|
Loading…
Reference in New Issue
Block a user