mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Update + fixed animations
This commit is contained in:
parent
68d8513e1a
commit
f596a8fa84
@ -103,7 +103,7 @@ public class PlayerInit {
|
||||
Vector velocity = player.getPosition().clone().getDirection().multiply(4);
|
||||
velocity.setY(3.5f);
|
||||
target.setVelocity(velocity, 150);
|
||||
target.damage(1);
|
||||
target.damage(5);
|
||||
player.sendMessage("ATTACK");
|
||||
}
|
||||
});
|
||||
@ -142,7 +142,7 @@ public class PlayerInit {
|
||||
});
|
||||
|
||||
player.setEventCallback(PlayerSpawnEvent.class, event -> {
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
player.teleport(new Position(0, 75, 0));
|
||||
|
||||
/*Random random = new Random();
|
||||
|
@ -433,7 +433,7 @@ public abstract class Entity implements Viewable, DataContainer {
|
||||
EntityStatusPacket statusPacket = new EntityStatusPacket();
|
||||
statusPacket.entityId = getEntityId();
|
||||
statusPacket.status = status;
|
||||
sendPacketToViewers(statusPacket);
|
||||
sendPacketToViewersAndSelf(statusPacket);
|
||||
}
|
||||
|
||||
public void setOnFire(boolean fire) {
|
||||
|
@ -96,9 +96,9 @@ public abstract class LivingEntity extends Entity {
|
||||
}
|
||||
|
||||
public void kill() {
|
||||
this.isDead = true; // So the entity isn't killed over and over again
|
||||
setHealth(0);
|
||||
refreshIsDead(true); // So the entity isn't killed over and over again
|
||||
triggerStatus((byte) 3); // Start death animation status
|
||||
setHealth(0);
|
||||
DeathEvent deathEvent = new DeathEvent();
|
||||
callEvent(DeathEvent.class, deathEvent);
|
||||
}
|
||||
|
@ -338,12 +338,6 @@ public class Player extends LivingEntity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kill() {
|
||||
super.kill();
|
||||
refreshIsDead(true);
|
||||
}
|
||||
|
||||
public void sendBlockBreakAnimation(BlockPosition blockPosition, byte destroyStage) {
|
||||
BlockBreakAnimationPacket breakAnimationPacket = new BlockBreakAnimationPacket();
|
||||
breakAnimationPacket.entityId = getEntityId() + 1;
|
||||
|
@ -0,0 +1,23 @@
|
||||
package fr.themode.minestom.event;
|
||||
|
||||
public class ArmAnimationEvent extends CancellableEvent {
|
||||
|
||||
private ArmAnimationType armAnimationType;
|
||||
|
||||
public ArmAnimationEvent(ArmAnimationType armAnimationType) {
|
||||
this.armAnimationType = armAnimationType;
|
||||
}
|
||||
|
||||
public ArmAnimationType getArmAnimationType() {
|
||||
return armAnimationType;
|
||||
}
|
||||
|
||||
public enum ArmAnimationType {
|
||||
BOW,
|
||||
CROSSBOW,
|
||||
TRIDENT,
|
||||
SHIELD,
|
||||
EAT
|
||||
}
|
||||
|
||||
}
|
@ -53,6 +53,8 @@ public abstract class Instance implements BlockModifier, DataContainer {
|
||||
// Load only if auto chunk load is enabled
|
||||
public abstract void loadOptionalChunk(int chunkX, int chunkZ, Consumer<Chunk> callback);
|
||||
|
||||
public abstract void unloadChunk(int chunkX, int chunkZ);
|
||||
|
||||
public abstract Chunk getChunk(int chunkX, int chunkZ);
|
||||
|
||||
public abstract void saveChunkToFolder(Chunk chunk, Runnable callback);
|
||||
|
@ -10,6 +10,7 @@ import fr.themode.minestom.instance.block.rule.BlockPlacementRule;
|
||||
import fr.themode.minestom.net.PacketWriterUtils;
|
||||
import fr.themode.minestom.net.packet.server.play.BlockChangePacket;
|
||||
import fr.themode.minestom.net.packet.server.play.ParticlePacket;
|
||||
import fr.themode.minestom.net.packet.server.play.UnloadChunkPacket;
|
||||
import fr.themode.minestom.particle.Particle;
|
||||
import fr.themode.minestom.particle.ParticleCreator;
|
||||
import fr.themode.minestom.utils.BlockPosition;
|
||||
@ -219,6 +220,23 @@ public class InstanceContainer extends Instance {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadChunk(int chunkX, int chunkZ) {
|
||||
Chunk chunk = getChunk(chunkX, chunkZ);
|
||||
long index = ChunkUtils.getChunkIndex(chunkX, chunkZ);
|
||||
|
||||
UnloadChunkPacket unloadChunkPacket = new UnloadChunkPacket();
|
||||
unloadChunkPacket.chunkX = chunkX;
|
||||
unloadChunkPacket.chunkZ = chunkZ;
|
||||
chunk.sendPacketToViewers(unloadChunkPacket);
|
||||
|
||||
for (Player viewer : chunk.getViewers()) {
|
||||
chunk.removeViewer(viewer);
|
||||
}
|
||||
|
||||
this.chunks.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk getChunk(int chunkX, int chunkZ) {
|
||||
return chunks.get(ChunkUtils.getChunkIndex(chunkX, chunkZ));
|
||||
|
@ -43,6 +43,11 @@ public class SharedInstance extends Instance {
|
||||
instanceContainer.loadOptionalChunk(chunkX, chunkZ, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadChunk(int chunkX, int chunkZ) {
|
||||
instanceContainer.unloadChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk getChunk(int chunkX, int chunkZ) {
|
||||
return instanceContainer.getChunk(chunkX, chunkZ);
|
||||
|
@ -936,7 +936,48 @@ public enum Material {
|
||||
}
|
||||
|
||||
public boolean isFood() {
|
||||
return false; // TODO
|
||||
switch (this) {
|
||||
case APPLE:
|
||||
case MUSHROOM_STEW:
|
||||
case BREAD:
|
||||
case PORKCHOP:
|
||||
case COOKED_PORKCHOP:
|
||||
case GOLDEN_APPLE:
|
||||
case ENCHANTED_GOLDEN_APPLE:
|
||||
case COD:
|
||||
case SALMON:
|
||||
case TROPICAL_FISH:
|
||||
case PUFFERFISH:
|
||||
case COOKED_COD:
|
||||
case COOKED_SALMON:
|
||||
case CAKE:
|
||||
case COOKIE:
|
||||
case MELON_SLICE:
|
||||
case DRIED_KELP:
|
||||
case BEEF:
|
||||
case COOKED_BEEF:
|
||||
case CHICKEN:
|
||||
case COOKED_CHICKEN:
|
||||
case ROTTEN_FLESH:
|
||||
case SPIDER_EYE:
|
||||
case CARROT:
|
||||
case POTATO:
|
||||
case BAKED_POTATO:
|
||||
case POISONOUS_POTATO:
|
||||
case PUMPKIN_PIE:
|
||||
case RABBIT:
|
||||
case COOKED_RABBIT:
|
||||
case RABBIT_STEW:
|
||||
case MUTTON:
|
||||
case COOKED_MUTTON:
|
||||
case BEETROOT:
|
||||
case BEETROOT_SOUP:
|
||||
case SWEET_BERRIES:
|
||||
case HONEY_BOTTLE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public short getId() {
|
||||
|
@ -75,12 +75,12 @@ public class PlayerDiggingListener {
|
||||
ItemStack handItem = player.getInventory().getItemInMainHand();
|
||||
handItem.setAmount((byte) (handItem.getAmount() - 1));
|
||||
handItem = handItem.getAmount() <= 0 ? ItemStack.AIR_ITEM : handItem;
|
||||
|
||||
dropItem(player, droppedItemStack2, handItem);
|
||||
break;
|
||||
case UPDATE_ITEM_STATE:
|
||||
// TODO check if is updatable item
|
||||
//player.refreshActiveHand(false, false, false);
|
||||
//player.sendPacketToViewers(player.getMetadataPacket());
|
||||
player.refreshActiveHand(false, false, false);
|
||||
player.sendPacketToViewers(player.getMetadataPacket());
|
||||
break;
|
||||
case SWAP_ITEM_HAND:
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package fr.themode.minestom.listener;
|
||||
|
||||
import fr.themode.minestom.entity.Player;
|
||||
import fr.themode.minestom.event.ArmAnimationEvent;
|
||||
import fr.themode.minestom.event.ArmorEquipEvent;
|
||||
import fr.themode.minestom.event.PlayerUseItemEvent;
|
||||
import fr.themode.minestom.inventory.PlayerInventory;
|
||||
@ -64,8 +65,27 @@ public class UseItemListener {
|
||||
|
||||
// TODO check if item in main or off hand is food or item with animation (bow/crossbow/riptide)
|
||||
// TODO in material enum?
|
||||
//player.refreshActiveHand(true, false, false);
|
||||
//player.sendPacketToViewers(player.getMetadataPacket());
|
||||
ArmAnimationEvent armAnimationEvent = null;
|
||||
boolean offhand = hand == Player.Hand.OFF;
|
||||
boolean riptideSpinAttack = false;
|
||||
|
||||
if (material == Material.BOW) {
|
||||
armAnimationEvent = new ArmAnimationEvent(ArmAnimationEvent.ArmAnimationType.BOW);
|
||||
} else if (material == Material.CROSSBOW) {
|
||||
armAnimationEvent = new ArmAnimationEvent(ArmAnimationEvent.ArmAnimationType.CROSSBOW);
|
||||
} else if (material == Material.SHIELD) {
|
||||
armAnimationEvent = new ArmAnimationEvent(ArmAnimationEvent.ArmAnimationType.SHIELD);
|
||||
} else if (material == Material.TRIDENT) {
|
||||
armAnimationEvent = new ArmAnimationEvent(ArmAnimationEvent.ArmAnimationType.TRIDENT);
|
||||
} else if (material.isFood()) {
|
||||
armAnimationEvent = new ArmAnimationEvent(ArmAnimationEvent.ArmAnimationType.EAT);
|
||||
}
|
||||
|
||||
if (armAnimationEvent != null)
|
||||
player.callCancellableEvent(ArmAnimationEvent.class, armAnimationEvent, () -> {
|
||||
player.refreshActiveHand(true, offhand, riptideSpinAttack);
|
||||
player.sendPacketToViewers(player.getMetadataPacket());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class PacketProcessor {
|
||||
PlayerConnection playerConnection = connectionPlayerConnectionMap.computeIfAbsent(channel, c -> new PlayerConnection(channel));
|
||||
ConnectionState connectionState = playerConnection.getConnectionState();
|
||||
//if (!printBlackList.contains(id)) {
|
||||
// System.out.println("RECEIVED ID: 0x" + Integer.toHexString(id) + " State: " + connectionState);
|
||||
//System.out.println("RECEIVED ID: 0x" + Integer.toHexString(id) + " State: " + connectionState);
|
||||
//}
|
||||
|
||||
PacketReader packetReader = new PacketReader(buffer, length);
|
||||
|
Loading…
Reference in New Issue
Block a user