mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-25 18:47:40 +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);
|
||||
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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -62,43 +62,51 @@ public class BlockPlacementListener {
|
||||
|
||||
blockPosition.add(offsetX, offsetY, offsetZ);
|
||||
|
||||
Chunk chunk = instance.getChunkAt(blockPosition);
|
||||
Set<Entity> entities = instance.getChunkEntities(chunk);
|
||||
boolean intersect = false;
|
||||
for (Entity entity : entities) {
|
||||
intersect = entity.getBoundingBox().intersect(blockPosition);
|
||||
if (intersect)
|
||||
break;
|
||||
}
|
||||
|
||||
Chunk chunk = instance.getChunkAt(blockPosition);
|
||||
boolean refreshChunk = false;
|
||||
|
||||
if (material.isBlock() && !intersect) {
|
||||
PlayerBlockPlaceEvent playerBlockPlaceEvent = new PlayerBlockPlaceEvent((short) 10, blockPosition, packet.hand);
|
||||
playerBlockPlaceEvent.consumeBlock(player.getGameMode() != GameMode.CREATIVE);
|
||||
|
||||
// BlockPlacementRule check
|
||||
if (material.isBlock()) {
|
||||
Block block = material.getBlock();
|
||||
BlockManager blockManager = MinecraftServer.getBlockManager();
|
||||
BlockPlacementRule blockPlacementRule = blockManager.getBlockPlacementRule(block);
|
||||
boolean canPlace = true;
|
||||
if (blockPlacementRule != null) {
|
||||
canPlace = blockPlacementRule.canPlace(instance, blockPosition);
|
||||
|
||||
Set<Entity> entities = instance.getChunkEntities(chunk);
|
||||
boolean intersect = false;
|
||||
if (block.isSolid()) {
|
||||
for (Entity entity : entities) {
|
||||
intersect = entity.getBoundingBox().intersect(blockPosition);
|
||||
if (intersect)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
player.callEvent(PlayerBlockPlaceEvent.class, playerBlockPlaceEvent);
|
||||
if (!playerBlockPlaceEvent.isCancelled() && canPlace) {
|
||||
instance.setBlock(blockPosition, material.getBlock());
|
||||
if (playerBlockPlaceEvent.doesConsumeBlock()) {
|
||||
if (!intersect) {
|
||||
PlayerBlockPlaceEvent playerBlockPlaceEvent = new PlayerBlockPlaceEvent((short) 10, blockPosition, packet.hand);
|
||||
playerBlockPlaceEvent.consumeBlock(player.getGameMode() != GameMode.CREATIVE);
|
||||
|
||||
StackingRule stackingRule = usedItem.getStackingRule();
|
||||
ItemStack newUsedItem = stackingRule.apply(usedItem, stackingRule.getAmount(usedItem) - 1);
|
||||
// BlockPlacementRule check
|
||||
BlockManager blockManager = MinecraftServer.getBlockManager();
|
||||
BlockPlacementRule blockPlacementRule = blockManager.getBlockPlacementRule(block);
|
||||
boolean canPlace = true;
|
||||
if (blockPlacementRule != null) {
|
||||
canPlace = blockPlacementRule.canPlace(instance, blockPosition);
|
||||
}
|
||||
|
||||
if (hand == Player.Hand.OFF) {
|
||||
playerInventory.setItemInOffHand(newUsedItem);
|
||||
} else { // Main
|
||||
playerInventory.setItemInMainHand(newUsedItem);
|
||||
player.callEvent(PlayerBlockPlaceEvent.class, playerBlockPlaceEvent);
|
||||
if (!playerBlockPlaceEvent.isCancelled() && canPlace) {
|
||||
instance.setBlock(blockPosition, material.getBlock());
|
||||
if (playerBlockPlaceEvent.doesConsumeBlock()) {
|
||||
|
||||
StackingRule stackingRule = usedItem.getStackingRule();
|
||||
ItemStack newUsedItem = stackingRule.apply(usedItem, stackingRule.getAmount(usedItem) - 1);
|
||||
|
||||
if (hand == Player.Hand.OFF) {
|
||||
playerInventory.setItemInOffHand(newUsedItem);
|
||||
} else { // Main
|
||||
playerInventory.setItemInMainHand(newUsedItem);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
refreshChunk = true;
|
||||
}
|
||||
} else {
|
||||
refreshChunk = true;
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user