Optimization + fix non-solid block entity collision

This commit is contained in:
Felix Cravic 2020-04-25 20:40:08 +02:00
parent d7e9a3a23f
commit 6f5ff41c57
6 changed files with 56 additions and 42 deletions

View File

@ -102,8 +102,6 @@ public class PlayerInit {
velocity.setY(4f);
entity.setVelocity(velocity, 150);
player.sendMessage("You attacked an entity!");
//creature.jump(1);
} else if (entity instanceof Player) {
Player target = (Player) entity;
Vector velocity = player.getPosition().clone().getDirection().multiply(4);

View File

@ -1,8 +1,6 @@
package fr.themode.demo.commands;
import fr.themode.demo.entity.ChickenCreature;
import net.minestom.server.command.CommandProcessor;
import net.minestom.server.entity.EntityCreature;
import net.minestom.server.entity.Player;
public class SimpleCommand implements CommandProcessor {
@ -15,15 +13,6 @@ public class SimpleCommand implements CommandProcessor {
public boolean process(Player player, String command, String[] args) {
player.sendMessage("You tried the sample command!");
for (EntityCreature entity : player.getInstance().getCreatures()) {
if (entity instanceof ChickenCreature) {
ChickenCreature chickenCreature = (ChickenCreature) entity;
chickenCreature.moveTo(player.getPosition().clone());
player.sendMessage("CHICKEN GO");
}
}
return true;
}
}

View File

@ -28,7 +28,6 @@ public class ItemEntity extends ObjectEntity {
@Override
public void spawn() {
this.spawnTime = System.currentTimeMillis();
// setVelocity(new Vector(0, 1, 0), 5000);
}
@Override

View File

@ -1335,6 +1335,20 @@ public enum Block {
}
}
public boolean isSign() {
switch (this) {
case OAK_SIGN:
case SPRUCE_SIGN:
case BIRCH_SIGN:
case ACACIA_SIGN:
case JUNGLE_SIGN:
case DARK_OAK_SIGN:
return true;
default:
return false;
}
}
public List<BlockAlternative> getBlockAlternatives() {
return Collections.unmodifiableList(blockAlternatives);
}

View File

@ -62,23 +62,28 @@ public class BlockPlacementListener {
blockPosition.add(offsetX, offsetY, offsetZ);
Chunk chunk = instance.getChunkAt(blockPosition);
boolean refreshChunk = false;
if (material.isBlock()) {
Block block = material.getBlock();
Set<Entity> entities = instance.getChunkEntities(chunk);
boolean intersect = false;
if (block.isSolid()) {
for (Entity entity : entities) {
intersect = entity.getBoundingBox().intersect(blockPosition);
if (intersect)
break;
}
}
boolean refreshChunk = false;
if (material.isBlock() && !intersect) {
if (!intersect) {
PlayerBlockPlaceEvent playerBlockPlaceEvent = new PlayerBlockPlaceEvent((short) 10, blockPosition, packet.hand);
playerBlockPlaceEvent.consumeBlock(player.getGameMode() != GameMode.CREATIVE);
// BlockPlacementRule check
Block block = material.getBlock();
BlockManager blockManager = MinecraftServer.getBlockManager();
BlockPlacementRule blockPlacementRule = blockManager.getBlockPlacementRule(block);
boolean canPlace = true;
@ -106,6 +111,9 @@ public class BlockPlacementListener {
} else {
refreshChunk = true;
}
} else {
refreshChunk = true;
}
// Refresh chunk section if needed
if (refreshChunk) {

View File

@ -56,6 +56,12 @@ public class BlockPosition {
this.z = z;
}
public int getDistance(BlockPosition blockPosition) {
return Math.abs(getX() - blockPosition.getX()) +
Math.abs(getY() - blockPosition.getY()) +
Math.abs(getZ() - blockPosition.getZ());
}
public BlockPosition clone() {
return new BlockPosition(x, y, z);
}