mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-13 11:41:52 +01:00
Updated the custom stone block in demo
This commit is contained in:
parent
22cd7a28a7
commit
1742aa6f8a
@ -1,7 +1,7 @@
|
||||
package demo;
|
||||
|
||||
import demo.blocks.BurningTorchBlock;
|
||||
import demo.blocks.StoneBlock;
|
||||
import demo.blocks.CustomBlockSample;
|
||||
import demo.blocks.UpdatableBlockDemo;
|
||||
import demo.commands.*;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
@ -23,7 +23,7 @@ public class Main {
|
||||
// MinecraftServer.setShouldProcessNettyErrors(true);
|
||||
|
||||
BlockManager blockManager = MinecraftServer.getBlockManager();
|
||||
blockManager.registerCustomBlock(new StoneBlock());
|
||||
blockManager.registerCustomBlock(new CustomBlockSample());
|
||||
blockManager.registerCustomBlock(new UpdatableBlockDemo());
|
||||
blockManager.registerCustomBlock(new BurningTorchBlock());
|
||||
|
||||
|
@ -5,8 +5,6 @@ import demo.generator.NoiseTestGenerator;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.benchmark.BenchmarkManager;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.data.Data;
|
||||
import net.minestom.server.data.DataImpl;
|
||||
import net.minestom.server.entity.*;
|
||||
import net.minestom.server.entity.damage.DamageType;
|
||||
import net.minestom.server.entity.type.monster.EntityZombie;
|
||||
@ -26,6 +24,7 @@ import net.minestom.server.inventory.InventoryType;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.packet.server.play.EffectPacket;
|
||||
import net.minestom.server.network.packet.server.play.PlayerListHeaderAndFooterPacket;
|
||||
import net.minestom.server.ping.ResponseDataConsumer;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
@ -34,6 +33,7 @@ import net.minestom.server.utils.Vector;
|
||||
import net.minestom.server.utils.time.TimeUnit;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@ -74,6 +74,12 @@ public class PlayerInit {
|
||||
BenchmarkManager benchmarkManager = MinecraftServer.getBenchmarkManager();
|
||||
|
||||
MinecraftServer.getSchedulerManager().buildTask(() -> {
|
||||
|
||||
Collection<Player> players = connectionManager.getOnlinePlayers();
|
||||
|
||||
if (players.isEmpty())
|
||||
return;
|
||||
|
||||
long ramUsage = benchmarkManager.getUsedMemory();
|
||||
ramUsage /= 1e6; // bytes to MB
|
||||
|
||||
@ -85,7 +91,7 @@ public class PlayerInit {
|
||||
playerListHeaderAndFooterPacket.header = header;
|
||||
playerListHeaderAndFooterPacket.footer = footer;
|
||||
|
||||
PacketUtils.sendGroupedPacket(connectionManager.getOnlinePlayers(), playerListHeaderAndFooterPacket);
|
||||
PacketUtils.sendGroupedPacket(players, playerListHeaderAndFooterPacket);
|
||||
}
|
||||
|
||||
}).repeat(10, TimeUnit.TICK).schedule();
|
||||
@ -205,10 +211,7 @@ public class PlayerInit {
|
||||
final Player player = event.getPlayer();
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
|
||||
ItemStack itemStack = new ItemStack(Material.BARRIER, (byte) 64);
|
||||
Data data = new DataImpl();
|
||||
data.set("testc", 2);
|
||||
itemStack.setData(data);
|
||||
ItemStack itemStack = new ItemStack(Material.STONE, (byte) 64);
|
||||
player.getInventory().addItemStack(itemStack);
|
||||
|
||||
//player.getInventory().addItemStack(new ItemStack(Material.STONE, (byte) 32));
|
||||
|
@ -6,13 +6,18 @@ import net.minestom.server.instance.Instance;
|
||||
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.util.Set;
|
||||
|
||||
public class StoneBlock extends CustomBlock {
|
||||
public class CustomBlockSample extends CustomBlock {
|
||||
|
||||
public StoneBlock() {
|
||||
private static final UpdateOption UPDATE_OPTION = new UpdateOption(3, TimeUnit.TICK);
|
||||
|
||||
public CustomBlockSample() {
|
||||
super(Block.GOLD_BLOCK, "custom_block");
|
||||
}
|
||||
|
||||
@ -23,7 +28,7 @@ public class StoneBlock extends CustomBlock {
|
||||
|
||||
@Override
|
||||
public void onDestroy(@NotNull Instance instance, @NotNull BlockPosition blockPosition, Data data) {
|
||||
BlockPosition above = blockPosition.copy().add(0, 1, 0);
|
||||
BlockPosition above = blockPosition.clone().add(0, 1, 0);
|
||||
CustomBlock blockAbove = instance.getCustomBlock(above);
|
||||
if (blockAbove == this) {
|
||||
instance.setBlock(above, Block.AIR);
|
||||
@ -31,6 +36,18 @@ public class StoneBlock extends CustomBlock {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull Instance instance, @NotNull BlockPosition blockPosition, @Nullable Data data) {
|
||||
final short blockId = instance.getBlockStateId(blockPosition);
|
||||
instance.refreshBlockStateId(blockPosition, (short) (blockId+1));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public UpdateOption getUpdateOption() {
|
||||
return UPDATE_OPTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFromNeighbor(@NotNull Instance instance, @NotNull BlockPosition thisPosition, @NotNull BlockPosition neighborPosition, boolean directNeighbor) {
|
||||
|
Loading…
Reference in New Issue
Block a user