Updated multiple files

This commit is contained in:
Németh Noel 2021-06-30 01:54:11 +02:00
parent 25183973dc
commit aaa3b91424
4 changed files with 20 additions and 21 deletions

View File

@ -20,13 +20,13 @@ import net.minestom.server.utils.callback.OptionalCallback;
import net.minestom.server.utils.chunk.ChunkCallback;
import net.minestom.server.utils.chunk.ChunkUtils;
import net.minestom.server.utils.time.Cooldown;
import net.minestom.server.utils.time.UpdateOption;
import net.minestom.server.utils.validate.Check;
import net.minestom.server.world.biomes.Biome;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.lang.ref.SoftReference;
import java.time.Duration;
import java.util.Set;
/**
@ -143,10 +143,10 @@ public class DynamicChunk extends Chunk {
final CustomBlock customBlock = getCustomBlock(index);
// Update cooldown
final UpdateOption updateOption = customBlock.getUpdateOption();
if (updateOption != null) {
final Duration updateFrequency = customBlock.getUpdateFrequency();
if (updateFrequency != null) {
final long lastUpdate = updatableBlocksLastUpdate.get(index);
final boolean hasCooldown = Cooldown.hasCooldown(time, lastUpdate, updateOption);
final boolean hasCooldown = Cooldown.hasCooldown(time, lastUpdate, updateFrequency);
if (hasCooldown)
continue;

View File

@ -14,12 +14,12 @@ import net.minestom.server.instance.Chunk;
import net.minestom.server.instance.Instance;
import net.minestom.server.network.packet.server.play.BlockBreakAnimationPacket;
import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.time.UpdateOption;
import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.time.Duration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -67,12 +67,12 @@ public abstract class CustomBlock {
}
/**
* Calling delay depends on {@link #getUpdateOption()} which should be overridden.
* Calling delay depends on {@link #getUpdateFrequency()} which should be overridden.
*
* @param instance the instance of the block
* @param blockPosition the position of the block
* @param data the data associated with the block
* @throws UnsupportedOperationException if {@link #getUpdateOption()}
* @throws UnsupportedOperationException if {@link #getUpdateFrequency()}
* is not null but the update method is not overridden
*/
public void update(@NotNull Instance instance, @NotNull BlockPosition blockPosition, @Nullable Data data) {
@ -89,7 +89,7 @@ public abstract class CustomBlock {
* @return the update option of the block, null if not any
*/
@Nullable
public UpdateOption getUpdateOption() {
public Duration getUpdateFrequency() {
return null;
}
@ -172,14 +172,14 @@ public abstract class CustomBlock {
/**
* Gets if this {@link CustomBlock} requires any tick update.
*
* @return true if {@link #getUpdateOption()} is not null and the value is positive
* @return true if {@link #getUpdateFrequency()} is not null and the value is positive
*/
public boolean hasUpdate() {
final UpdateOption updateOption = getUpdateOption();
if (updateOption == null)
final Duration updateFrequency = getUpdateFrequency();
if (updateFrequency == null)
return false;
return updateOption.getValue() > 0;
return !updateFrequency.isZero();
}

View File

@ -7,15 +7,15 @@ import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.CustomBlock;
import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.time.UpdateOption;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.Duration;
import java.util.Set;
public class CustomBlockSample extends CustomBlock {
private static final UpdateOption UPDATE_OPTION = new UpdateOption(3, TimeUnit.TICK);
private static final Duration DURATION = Duration.of(3, TimeUnit.SERVER_TICK);
public CustomBlockSample() {
super(Block.GOLD_BLOCK, "custom_block");
@ -45,10 +45,9 @@ public class CustomBlockSample extends CustomBlock {
//instance.refreshBlockStateId(blockPosition, (short) (blockId+1));
}
@Nullable
@Override
public UpdateOption getUpdateOption() {
return UPDATE_OPTION;
public Duration getUpdateFrequency() {
return DURATION;
}
@Override

View File

@ -7,14 +7,14 @@ import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.CustomBlock;
import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.time.UpdateOption;
import org.jetbrains.annotations.NotNull;
import java.time.Duration;
import java.util.Set;
public class UpdatableBlockDemo extends CustomBlock {
private static final UpdateOption UPDATE_OPTION = new UpdateOption(20, TimeUnit.TICK);
private static final Duration DURATION = Duration.of(20, TimeUnit.SERVER_TICK);
public UpdatableBlockDemo() {
super(Block.DIRT, "updatable");
@ -41,8 +41,8 @@ public class UpdatableBlockDemo extends CustomBlock {
}
@Override
public UpdateOption getUpdateOption() {
return UPDATE_OPTION;
public Duration getUpdateFrequency() {
return DURATION;
}
@Override