mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-26 19:18:12 +01:00
Optimization + fix non-solid block entity collision
This commit is contained in:
parent
d7e9a3a23f
commit
6f5ff41c57
@ -102,8 +102,6 @@ public class PlayerInit {
|
|||||||
velocity.setY(4f);
|
velocity.setY(4f);
|
||||||
entity.setVelocity(velocity, 150);
|
entity.setVelocity(velocity, 150);
|
||||||
player.sendMessage("You attacked an entity!");
|
player.sendMessage("You attacked an entity!");
|
||||||
|
|
||||||
//creature.jump(1);
|
|
||||||
} else if (entity instanceof Player) {
|
} else if (entity instanceof Player) {
|
||||||
Player target = (Player) entity;
|
Player target = (Player) entity;
|
||||||
Vector velocity = player.getPosition().clone().getDirection().multiply(4);
|
Vector velocity = player.getPosition().clone().getDirection().multiply(4);
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package fr.themode.demo.commands;
|
package fr.themode.demo.commands;
|
||||||
|
|
||||||
import fr.themode.demo.entity.ChickenCreature;
|
|
||||||
import net.minestom.server.command.CommandProcessor;
|
import net.minestom.server.command.CommandProcessor;
|
||||||
import net.minestom.server.entity.EntityCreature;
|
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
|
||||||
public class SimpleCommand implements CommandProcessor {
|
public class SimpleCommand implements CommandProcessor {
|
||||||
@ -15,15 +13,6 @@ public class SimpleCommand implements CommandProcessor {
|
|||||||
public boolean process(Player player, String command, String[] args) {
|
public boolean process(Player player, String command, String[] args) {
|
||||||
player.sendMessage("You tried the sample command!");
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ public class ItemEntity extends ObjectEntity {
|
|||||||
@Override
|
@Override
|
||||||
public void spawn() {
|
public void spawn() {
|
||||||
this.spawnTime = System.currentTimeMillis();
|
this.spawnTime = System.currentTimeMillis();
|
||||||
// setVelocity(new Vector(0, 1, 0), 5000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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() {
|
public List<BlockAlternative> getBlockAlternatives() {
|
||||||
return Collections.unmodifiableList(blockAlternatives);
|
return Collections.unmodifiableList(blockAlternatives);
|
||||||
}
|
}
|
||||||
|
@ -62,23 +62,28 @@ public class BlockPlacementListener {
|
|||||||
|
|
||||||
blockPosition.add(offsetX, offsetY, offsetZ);
|
blockPosition.add(offsetX, offsetY, offsetZ);
|
||||||
|
|
||||||
|
|
||||||
Chunk chunk = instance.getChunkAt(blockPosition);
|
Chunk chunk = instance.getChunkAt(blockPosition);
|
||||||
|
boolean refreshChunk = false;
|
||||||
|
|
||||||
|
if (material.isBlock()) {
|
||||||
|
Block block = material.getBlock();
|
||||||
|
|
||||||
Set<Entity> entities = instance.getChunkEntities(chunk);
|
Set<Entity> entities = instance.getChunkEntities(chunk);
|
||||||
boolean intersect = false;
|
boolean intersect = false;
|
||||||
|
if (block.isSolid()) {
|
||||||
for (Entity entity : entities) {
|
for (Entity entity : entities) {
|
||||||
intersect = entity.getBoundingBox().intersect(blockPosition);
|
intersect = entity.getBoundingBox().intersect(blockPosition);
|
||||||
if (intersect)
|
if (intersect)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boolean refreshChunk = false;
|
if (!intersect) {
|
||||||
|
|
||||||
if (material.isBlock() && !intersect) {
|
|
||||||
PlayerBlockPlaceEvent playerBlockPlaceEvent = new PlayerBlockPlaceEvent((short) 10, blockPosition, packet.hand);
|
PlayerBlockPlaceEvent playerBlockPlaceEvent = new PlayerBlockPlaceEvent((short) 10, blockPosition, packet.hand);
|
||||||
playerBlockPlaceEvent.consumeBlock(player.getGameMode() != GameMode.CREATIVE);
|
playerBlockPlaceEvent.consumeBlock(player.getGameMode() != GameMode.CREATIVE);
|
||||||
|
|
||||||
// BlockPlacementRule check
|
// BlockPlacementRule check
|
||||||
Block block = material.getBlock();
|
|
||||||
BlockManager blockManager = MinecraftServer.getBlockManager();
|
BlockManager blockManager = MinecraftServer.getBlockManager();
|
||||||
BlockPlacementRule blockPlacementRule = blockManager.getBlockPlacementRule(block);
|
BlockPlacementRule blockPlacementRule = blockManager.getBlockPlacementRule(block);
|
||||||
boolean canPlace = true;
|
boolean canPlace = true;
|
||||||
@ -106,6 +111,9 @@ public class BlockPlacementListener {
|
|||||||
} else {
|
} else {
|
||||||
refreshChunk = true;
|
refreshChunk = true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
refreshChunk = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Refresh chunk section if needed
|
// Refresh chunk section if needed
|
||||||
if (refreshChunk) {
|
if (refreshChunk) {
|
||||||
|
@ -56,6 +56,12 @@ public class BlockPosition {
|
|||||||
this.z = z;
|
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() {
|
public BlockPosition clone() {
|
||||||
return new BlockPosition(x, y, z);
|
return new BlockPosition(x, y, z);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user