mirror of https://github.com/Minestom/Minestom.git
Fixed EntityCreature walking collision
This commit is contained in:
parent
26276af29e
commit
0a30554a5a
|
@ -1,5 +1,6 @@
|
|||
package fr.themode.demo;
|
||||
|
||||
import fr.themode.demo.entity.ChickenCreature;
|
||||
import fr.themode.demo.generator.ChunkGeneratorDemo;
|
||||
import fr.themode.demo.generator.NoiseTestGenerator;
|
||||
import fr.themode.minestom.MinecraftServer;
|
||||
|
@ -121,8 +122,8 @@ public class PlayerInit {
|
|||
p.teleport(player.getPosition());
|
||||
}*/
|
||||
|
||||
//ChickenCreature chickenCreature = new ChickenCreature(player.getPosition());
|
||||
//chickenCreature.setInstance(player.getInstance());
|
||||
ChickenCreature chickenCreature = new ChickenCreature(player.getPosition());
|
||||
chickenCreature.setInstance(player.getInstance());
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package fr.themode.demo.entity;
|
||||
|
||||
import fr.themode.minestom.MinecraftServer;
|
||||
import fr.themode.minestom.entity.Entity;
|
||||
import fr.themode.minestom.entity.EntityCreature;
|
||||
import fr.themode.minestom.entity.EntityType;
|
||||
|
@ -84,10 +83,10 @@ public class ChickenCreature extends EntityCreature {
|
|||
move(x, 0, z, updateView);
|
||||
}
|
||||
} else {
|
||||
//move(randomX * speed, 0, randomZ * speed, true);
|
||||
//move(0.5f * speed, 0, 0.5f * speed, true);
|
||||
}
|
||||
|
||||
Player player = MinecraftServer.getConnectionManager().getPlayer("TheMode911");
|
||||
moveTo(player.getPosition().clone());
|
||||
//Player player = MinecraftServer.getConnectionManager().getPlayer("TheMode911");
|
||||
//moveTo(player.getPosition().clone());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package fr.themode.minestom.collision;
|
||||
|
||||
import fr.themode.minestom.instance.Instance;
|
||||
import fr.themode.minestom.item.Material;
|
||||
import fr.themode.minestom.utils.BlockPosition;
|
||||
import fr.themode.minestom.utils.Position;
|
||||
|
||||
public class CollisionUtils {
|
||||
|
||||
public static Position entity(Instance instance, BoundingBox boundingBox, Position currentPosition, Position targetPosition) {
|
||||
|
||||
float currentX = currentPosition.getX();
|
||||
float currentY = currentPosition.getY();
|
||||
float currentZ = currentPosition.getZ();
|
||||
|
||||
float targetX = targetPosition.getX();
|
||||
float targetY = targetPosition.getY();
|
||||
float targetZ = targetPosition.getZ();
|
||||
|
||||
|
||||
BlockPosition xBlock = new BlockPosition(targetX, currentY, currentZ);
|
||||
BlockPosition yBlock = new BlockPosition(currentX, targetY, currentZ);
|
||||
BlockPosition zBlock = new BlockPosition(currentX, currentY, targetZ);
|
||||
|
||||
boolean xAir = instance.getBlockId(xBlock) == Material.AIR.getId();
|
||||
boolean yAir = instance.getBlockId(yBlock) == Material.AIR.getId();
|
||||
boolean zAir = instance.getBlockId(zBlock) == Material.AIR.getId();
|
||||
|
||||
boolean xIntersect = boundingBox.intersect(xBlock);
|
||||
boolean yIntersect = boundingBox.intersect(yBlock);
|
||||
boolean zIntersect = boundingBox.intersect(zBlock);
|
||||
|
||||
float newX = xAir ? targetX : xIntersect ? currentX : targetX;
|
||||
float newY = yAir ? targetY : yIntersect ? currentY : targetY;
|
||||
float newZ = zAir ? targetZ : zIntersect ? currentZ : targetZ;
|
||||
|
||||
return new Position(newX, newY, newZ);
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,7 @@ package fr.themode.minestom.entity;
|
|||
import fr.themode.minestom.MinecraftServer;
|
||||
import fr.themode.minestom.Viewable;
|
||||
import fr.themode.minestom.collision.BoundingBox;
|
||||
import fr.themode.minestom.collision.CollisionUtils;
|
||||
import fr.themode.minestom.data.Data;
|
||||
import fr.themode.minestom.data.DataContainer;
|
||||
import fr.themode.minestom.event.Callback;
|
||||
|
@ -10,7 +11,6 @@ import fr.themode.minestom.event.CancellableEvent;
|
|||
import fr.themode.minestom.event.Event;
|
||||
import fr.themode.minestom.instance.Chunk;
|
||||
import fr.themode.minestom.instance.Instance;
|
||||
import fr.themode.minestom.item.Material;
|
||||
import fr.themode.minestom.net.packet.PacketWriter;
|
||||
import fr.themode.minestom.net.packet.server.play.*;
|
||||
import fr.themode.minestom.net.player.PlayerConnection;
|
||||
|
@ -219,23 +219,11 @@ public abstract class Entity implements Viewable, DataContainer {
|
|||
float newY = position.getY() + velocity.getY() / tps;
|
||||
float newZ = position.getZ() + velocity.getZ() / tps;
|
||||
|
||||
BlockPosition xBlock = new BlockPosition(newX, position.getY(), position.getZ());
|
||||
BlockPosition yBlock = new BlockPosition(position.getX(), newY, position.getZ());
|
||||
BlockPosition zBlock = new BlockPosition(position.getX(), position.getY(), newZ);
|
||||
Position newPosition = new Position(newX, newY, newZ);
|
||||
|
||||
boolean xAir = getInstance().getBlockId(xBlock) == Material.AIR.getId();
|
||||
boolean yAir = getInstance().getBlockId(yBlock) == Material.AIR.getId();
|
||||
boolean zAir = getInstance().getBlockId(zBlock) == Material.AIR.getId();
|
||||
newPosition = CollisionUtils.entity(getInstance(), getBoundingBox(), getPosition(), newPosition);
|
||||
|
||||
boolean xIntersect = boundingBox.intersect(xBlock);
|
||||
boolean yIntersect = boundingBox.intersect(yBlock);
|
||||
boolean zIntersect = boundingBox.intersect(zBlock);
|
||||
|
||||
newX = xAir ? newX : xIntersect ? position.getX() : newX;
|
||||
newY = yAir ? newY : yIntersect ? position.getY() : newY;
|
||||
newZ = zAir ? newZ : zIntersect ? position.getZ() : newZ;
|
||||
|
||||
refreshPosition(newX, newY, newZ);
|
||||
refreshPosition(newPosition);
|
||||
if (this instanceof ObjectEntity) {
|
||||
// FIXME velocity/gravity
|
||||
//sendPacketToViewers(getVelocityPacket());
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package fr.themode.minestom.entity;
|
||||
|
||||
import fr.themode.minestom.collision.CollisionUtils;
|
||||
import fr.themode.minestom.entity.pathfinding.EntityPathFinder;
|
||||
import fr.themode.minestom.entity.property.Attribute;
|
||||
import fr.themode.minestom.net.packet.server.play.*;
|
||||
|
@ -46,6 +47,13 @@ public abstract class EntityCreature extends LivingEntity {
|
|||
float newX = position.getX() + x;
|
||||
float newY = position.getY() + y;
|
||||
float newZ = position.getZ() + z;
|
||||
Position newPosition = new Position(newX, newY, newZ);
|
||||
// Calculate collisions boxes
|
||||
newPosition = CollisionUtils.entity(getInstance(), getBoundingBox(), position, newPosition);
|
||||
// Refresh target position
|
||||
newX = newPosition.getX();
|
||||
newY = newPosition.getY();
|
||||
newZ = newPosition.getZ();
|
||||
|
||||
// Creatures cannot move in unload chunk
|
||||
if (ChunkUtils.isChunkUnloaded(getInstance(), newX, newZ))
|
||||
|
|
|
@ -28,7 +28,7 @@ public abstract class LivingEntity extends Entity {
|
|||
private float[] attributeValues = new float[Attribute.values().length];
|
||||
|
||||
private boolean isHandActive;
|
||||
private boolean activeHand;
|
||||
private boolean offHand;
|
||||
private boolean riptideSpinAttack;
|
||||
|
||||
public LivingEntity(int entityType, Position spawnPosition) {
|
||||
|
@ -84,7 +84,7 @@ public abstract class LivingEntity extends Entity {
|
|||
byte activeHandValue = 0;
|
||||
if (isHandActive) {
|
||||
activeHandValue += 1;
|
||||
if (activeHand)
|
||||
if (offHand)
|
||||
activeHandValue += 2;
|
||||
if (riptideSpinAttack)
|
||||
activeHandValue += 4;
|
||||
|
@ -160,7 +160,7 @@ public abstract class LivingEntity extends Entity {
|
|||
|
||||
public void refreshActiveHand(boolean isHandActive, boolean offHand, boolean riptideSpinAttack) {
|
||||
this.isHandActive = isHandActive;
|
||||
this.activeHand = offHand;
|
||||
this.offHand = offHand;
|
||||
this.riptideSpinAttack = riptideSpinAttack;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class PacketListenerManager {
|
|||
if (packetConsumer != null) {
|
||||
boolean cancel = packetConsumer.accept(player, packet);
|
||||
if (cancel)
|
||||
return;
|
||||
return; // Listening cancelled
|
||||
}
|
||||
|
||||
BiConsumer<T, Player> biConsumer = (BiConsumer<T, Player>) listeners.get(packet.getClass());
|
||||
|
|
Loading…
Reference in New Issue