use of org.terasology.rendering.logic.VisualComponent in project Terasology by MovingBlocks.
the class FirstPersonClientSystem method linkHeldItemLocationForLocalPlayer.
/**
* Changes held item entity.
*
* <p>Detaches old held item and removes it's components. Adds components to new held item and
* attaches it to the mount point entity.</p>
*/
private void linkHeldItemLocationForLocalPlayer(EntityRef newItem) {
if (!newItem.equals(currentHeldItem)) {
EntityRef camera = localPlayer.getCameraEntity();
FirstPersonHeldItemMountPointComponent mountPointComponent = camera.getComponent(FirstPersonHeldItemMountPointComponent.class);
if (mountPointComponent != null) {
// currentHeldItem is at this point the old item
if (currentHeldItem != EntityRef.NULL) {
currentHeldItem.destroy();
}
// use the hand if there is no new item
EntityRef newHeldItem;
if (newItem == EntityRef.NULL) {
newHeldItem = getHandEntity();
} else {
newHeldItem = newItem;
}
// create client side held item entity
currentHeldItem = entityManager.create();
// add the visually relevant components
for (Component component : newHeldItem.iterateComponents()) {
if (component instanceof VisualComponent) {
currentHeldItem.addComponent(component);
}
}
// ensure world location is set
currentHeldItem.addComponent(new LocationComponent());
currentHeldItem.addComponent(new ItemIsHeldComponent());
FirstPersonHeldItemTransformComponent heldItemTransformComponent = currentHeldItem.getComponent(FirstPersonHeldItemTransformComponent.class);
if (heldItemTransformComponent == null) {
heldItemTransformComponent = new FirstPersonHeldItemTransformComponent();
currentHeldItem.addComponent(heldItemTransformComponent);
}
Location.attachChild(mountPointComponent.mountPointEntity, currentHeldItem, heldItemTransformComponent.translate, new Quat4f(TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.y, TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.x, TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.z), heldItemTransformComponent.scale);
}
}
}
Aggregations