Make bstats opt-out, WIP spawning packet provider
This commit is contained in:
parent
1c1c6a479e
commit
b68c86d190
3 changed files with 63 additions and 1 deletions
|
@ -13,6 +13,7 @@ import me.tofaa.entitylib.meta.types.ObjectData;
|
||||||
import me.tofaa.entitylib.tick.Tickable;
|
import me.tofaa.entitylib.tick.Tickable;
|
||||||
import me.tofaa.entitylib.ve.ViewerRule;
|
import me.tofaa.entitylib.ve.ViewerRule;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.UnmodifiableView;
|
import org.jetbrains.annotations.UnmodifiableView;
|
||||||
|
@ -94,13 +95,15 @@ public class WrapperEntity implements Tickable {
|
||||||
return spawn(location, EntityLib.getApi().getDefaultContainer());
|
return spawn(location, EntityLib.getApi().getDefaultContainer());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getObjectData() {
|
@ApiStatus.Internal
|
||||||
|
public int getObjectData() {
|
||||||
if (entityMeta instanceof ObjectData) {
|
if (entityMeta instanceof ObjectData) {
|
||||||
return ((ObjectData) entityMeta).getObjectData();
|
return ((ObjectData) entityMeta).getObjectData();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
public Optional<Vector3d> createVeloPacket() {
|
public Optional<Vector3d> createVeloPacket() {
|
||||||
Optional<Vector3d> velocity;
|
Optional<Vector3d> velocity;
|
||||||
double veloX = 0, veloY = 0, veloZ = 0;
|
double veloX = 0, veloY = 0, veloZ = 0;
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package me.tofaa.entitylib.wrapper.spawning;
|
||||||
|
|
||||||
|
import com.github.retrooper.packetevents.protocol.player.User;
|
||||||
|
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||||
|
import me.tofaa.entitylib.wrapper.WrapperEntity;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface SpawnPacketProvider<T extends PacketWrapper<T>> extends SpawnPacketProviders {
|
||||||
|
|
||||||
|
T provide(User user, WrapperEntity entity);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package me.tofaa.entitylib.wrapper.spawning;
|
||||||
|
|
||||||
|
import com.github.retrooper.packetevents.protocol.world.Location;
|
||||||
|
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnEntity;
|
||||||
|
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnLivingEntity;
|
||||||
|
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnWeatherEntity;
|
||||||
|
import me.tofaa.entitylib.utils.Check;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
interface SpawnPacketProviders {
|
||||||
|
|
||||||
|
@NotNull SpawnPacketProvider<WrapperPlayServerSpawnEntity> GENERAL = (user, entity) -> {
|
||||||
|
Location location = entity.getLocation();
|
||||||
|
return new WrapperPlayServerSpawnEntity(
|
||||||
|
entity.getEntityId(),
|
||||||
|
Optional.of(entity.getUuid()),
|
||||||
|
entity.getEntityType(),
|
||||||
|
location.getPosition(),
|
||||||
|
location.getPitch(),
|
||||||
|
location.getYaw(),
|
||||||
|
location.getYaw(),
|
||||||
|
entity.getObjectData(),
|
||||||
|
entity.createVeloPacket()
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
@NotNull SpawnPacketProvider<WrapperPlayServerSpawnWeatherEntity> WEATHER_ENTITY = (user, entity) -> {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
};
|
||||||
|
|
||||||
|
@NotNull SpawnPacketProvider<WrapperPlayServerSpawnLivingEntity> PRE_1_19_LIVING = (user, entity) -> {
|
||||||
|
Location location = entity.getLocation();
|
||||||
|
return new WrapperPlayServerSpawnLivingEntity(
|
||||||
|
entity.getEntityId(),
|
||||||
|
entity.getUuid(),
|
||||||
|
entity.getEntityType(),
|
||||||
|
location,
|
||||||
|
location.getPitch(),
|
||||||
|
entity.getVelocity(),
|
||||||
|
entity.getEntityMeta()
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue